Removed unused old image handling

This commit is contained in:
krateng 2022-02-17 08:16:59 +01:00
parent bfed3604c5
commit f645f73f1f
1 changed files with 0 additions and 146 deletions

View File

@ -145,14 +145,6 @@ def get_artist_image(artist=None,artist_id=None,fast=False):
if result is not None: return result
return ""
### Caches
cacheage = malojaconfig["CACHE_EXPIRE_POSITIVE"] * 24 * 3600
cacheage_neg = malojaconfig["CACHE_EXPIRE_NEGATIVE"] * 24 * 3600
artist_cache = caching.Cache(name="imgcache_artists",maxage=cacheage,maxage_negative=cacheage_neg,persistent=True)
track_cache = caching.Cache(name="imgcache_tracks",maxage=cacheage,maxage_negative=cacheage_neg,persistent=True)
# removes emojis and weird shit from names
def clean(name):
@ -245,144 +237,6 @@ def local_files(artist=None,artists=None,title=None):
# these caches are there so we don't check all files every time, but return the same one
local_cache_age = malojaconfig["LOCAL_IMAGE_ROTATE"]
local_artist_cache = caching.Cache(maxage=local_cache_age)
local_track_cache = caching.Cache(maxage=local_cache_age)
def getTrackImage(artists,title,fast=False):
hashable_track = (frozenset(artists),title)
# Prio 1: Local image
if malojaconfig["USE_LOCAL_IMAGES"]:
try:
return local_track_cache.get(hashable_track)
except:
images = local_files(artists=artists,title=title)
if len(images) != 0:
res = random.choice(images)
local_track_cache.add(hashable_track,res)
return urllib.parse.quote(res)
# Prio 2: Cached remote link
try:
result = track_cache.get(hashable_track)
if result is not None: return result
# if we have cached the nonexistence of that image, we immediately return
# the redirect to the artist and let the resolver handle it
# (even if we're not in a fast lookup right now)
for a in artists:
res = getArtistImage(artist=a,fast=True)
if res != "": return res
return ""
except:
pass
# fast request will not go further than this, but now generate redirect link
if fast:
return ("/image?title=" + urllib.parse.quote(title) + "&" + "&".join(
"artist=" + urllib.parse.quote(a) for a in artists))
# Prio 3 (only non-fast lookup): actually call third parties
result = thirdparty.get_image_track_all((artists,title))
# cache results (even negative ones)
track_cache.add(hashable_track,result)
# return either result or redirect to artist
if result is not None: return result
for a in artists:
res = getArtistImage(artist=a,fast=False)
if res != "": return res
return ""
def getArtistImage(artist,fast=False):
# Prio 1: Local image
if malojaconfig["USE_LOCAL_IMAGES"]:
try:
return local_artist_cache.get(artist)
except:
images = local_files(artist=artist)
if len(images) != 0:
res = random.choice(images)
local_artist_cache.add(artist,res)
return urllib.parse.quote(res)
# Prio 2: Cached remote link
try:
result = artist_cache.get(artist)
if result is not None: return result
else: return ""
# none means non-existence is cached, return empty
except:
pass
# no cache entry, go on
# fast request will not go further than this, but now generate redirect link
if fast: return "/image?artist=" + urllib.parse.quote(artist)
# Prio 3 (only non-fast lookup): actually call third parties
result = thirdparty.get_image_artist_all(artist)
# cache results (even negative ones)
artist_cache.add(artist,result) #cache_artist(artist,result)
if result is not None: return result
else: return ""
def getTrackImages(trackobjectlist,fast=False):
threads = []
for track in trackobjectlist:
t = Thread(target=getTrackImage,args=(track["artists"],track["title"],),kwargs={"fast":fast})
t.start()
threads.append(t)
for t in threads:
t.join()
return [getTrackImage(t["artists"],t["title"]) for t in trackobjectlist]
def getArtistImages(artistlist,fast=False):
threads = []
for artist in artistlist:
t = Thread(target=getArtistImage,args=(artist,),kwargs={"fast":fast})
t.start()
threads.append(t)
for t in threads:
t.join()
# async calls only cached results, now we need to get them
return [getArtistImage(a) for a in artistlist]
# new way of serving images
# instead always generate a link locally, but redirect that on the fly
# this way the page can load faster and images will trickle in without having to resort to XHTTP requests
def resolveImage(artist=None,track=None):
if track is not None:
return getTrackImage(track["artists"],track["title"])
elif artist is not None:
return getArtistImage(artist)
def set_image(b64,**keys):
track = "title" in keys