mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Cleaned up and added logging to image fetching
This commit is contained in:
parent
11eb57ed2f
commit
3382c20cb4
@ -85,7 +85,9 @@ def api_request_artist(artist):
|
|||||||
for node in step[1]:
|
for node in step[1]:
|
||||||
var = var[node]
|
var = var[node]
|
||||||
assert isinstance(var,str) and var != ""
|
assert isinstance(var,str) and var != ""
|
||||||
except:
|
except Exception as e:
|
||||||
|
log("Error while getting artist image from " + api["name"],module="external")
|
||||||
|
log(str(e),module="external")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return var
|
return var
|
||||||
|
@ -239,11 +239,6 @@ local_track_cache = caching.Cache(maxage=local_cache_age)
|
|||||||
|
|
||||||
def getTrackImage(artists,title,fast=False):
|
def getTrackImage(artists,title,fast=False):
|
||||||
|
|
||||||
# obj = (frozenset(artists),title)
|
|
||||||
# filename = "-".join([re.sub("[^a-zA-Z0-9]","",artist) for artist in sorted(artists)]) + "_" + re.sub("[^a-zA-Z0-9]","",title)
|
|
||||||
# if filename == "": filename = str(hash(obj))
|
|
||||||
# filepath = "images/tracks/" + filename
|
|
||||||
|
|
||||||
if settings.get_settings("USE_LOCAL_IMAGES"):
|
if settings.get_settings("USE_LOCAL_IMAGES"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -257,21 +252,6 @@ def getTrackImage(artists,title,fast=False):
|
|||||||
return urllib.parse.quote(res)
|
return urllib.parse.quote(res)
|
||||||
|
|
||||||
|
|
||||||
# check if custom image exists
|
|
||||||
# if os.path.exists(filepath + ".png"):
|
|
||||||
# imgurl = "/" + filepath + ".png"
|
|
||||||
# return imgurl
|
|
||||||
# elif os.path.exists(filepath + ".jpg"):
|
|
||||||
# imgurl = "/" + filepath + ".jpg"
|
|
||||||
# return imgurl
|
|
||||||
# elif os.path.exists(filepath + ".jpeg"):
|
|
||||||
# imgurl = "/" + filepath + ".jpeg"
|
|
||||||
# return imgurl
|
|
||||||
# elif os.path.exists(filepath + ".gif"):
|
|
||||||
# imgurl = "/" + filepath + ".gif"
|
|
||||||
# return imgurl
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# check our cache
|
# check our cache
|
||||||
# if we have cached the nonexistence of that image, we immediately return the redirect to the artist and let the resolver handle it
|
# if we have cached the nonexistence of that image, we immediately return the redirect to the artist and let the resolver handle it
|
||||||
@ -313,17 +293,13 @@ def getTrackImage(artists,title,fast=False):
|
|||||||
|
|
||||||
def getArtistImage(artist,fast=False):
|
def getArtistImage(artist,fast=False):
|
||||||
|
|
||||||
# obj = artist
|
|
||||||
# filename = re.sub("[^a-zA-Z0-9]","",artist)
|
|
||||||
# if filename == "": filename = str(hash(obj))
|
|
||||||
# filepath = "images/artists/" + filename
|
|
||||||
# #filepath_cache = "info/artists_cache/" + filename
|
|
||||||
|
|
||||||
if settings.get_settings("USE_LOCAL_IMAGES"):
|
if settings.get_settings("USE_LOCAL_IMAGES"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return local_artist_cache.get(artist)
|
return local_artist_cache.get(artist)
|
||||||
|
# Local cached image
|
||||||
except:
|
except:
|
||||||
|
# Get all local images, select one if present
|
||||||
images = local_files(artist=artist)
|
images = local_files(artist=artist)
|
||||||
if len(images) != 0:
|
if len(images) != 0:
|
||||||
#return random.choice(images)
|
#return random.choice(images)
|
||||||
@ -332,28 +308,16 @@ def getArtistImage(artist,fast=False):
|
|||||||
return urllib.parse.quote(res)
|
return urllib.parse.quote(res)
|
||||||
|
|
||||||
|
|
||||||
# check if custom image exists
|
# if no local images (or setting to not use them)
|
||||||
# if os.path.exists(filepath + ".png"):
|
|
||||||
# imgurl = "/" + filepath + ".png"
|
|
||||||
# return imgurl
|
|
||||||
# elif os.path.exists(filepath + ".jpg"):
|
|
||||||
# imgurl = "/" + filepath + ".jpg"
|
|
||||||
# return imgurl
|
|
||||||
# elif os.path.exists(filepath + ".jpeg"):
|
|
||||||
# imgurl = "/" + filepath + ".jpeg"
|
|
||||||
# return imgurl
|
|
||||||
# elif os.path.exists(filepath + ".gif"):
|
|
||||||
# imgurl = "/" + filepath + ".gif"
|
|
||||||
# return imgurl
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#result = cachedArtists[artist]
|
# check cache for foreign image
|
||||||
result = artist_cache.get(artist) #artist_from_cache(artist)
|
result = artist_cache.get(artist)
|
||||||
if result is not None: return result
|
if result is not None: return result
|
||||||
else: return ""
|
else: return ""
|
||||||
|
# none means non-existence is cached, return empty
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
# no cache entry, go on
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -362,7 +326,6 @@ def getArtistImage(artist,fast=False):
|
|||||||
# if apikey is None: return "" # DO NOT CACHE THAT
|
# if apikey is None: return "" # DO NOT CACHE THAT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# fast request only retuns cached and local results, generates redirect link for rest
|
# fast request only retuns cached and local results, generates redirect link for rest
|
||||||
if fast: return "/image?artist=" + urllib.parse.quote(artist)
|
if fast: return "/image?artist=" + urllib.parse.quote(artist)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user