mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Fixes to image handling
This commit is contained in:
parent
cf43a9221a
commit
bfed3604c5
@ -4,7 +4,7 @@
|
|||||||
# you know what f*ck it
|
# you know what f*ck it
|
||||||
# this is hardcoded for now because of that damn project / package name discrepancy
|
# this is hardcoded for now because of that damn project / package name discrepancy
|
||||||
# i'll fix it one day
|
# i'll fix it one day
|
||||||
VERSION = "3.0.0-alpha.2"
|
VERSION = "3.0.0-alpha"
|
||||||
HOMEPAGE = "https://github.com/krateng/maloja"
|
HOMEPAGE = "https://github.com/krateng/maloja"
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,15 +41,14 @@ meta.create_all(engine)
|
|||||||
def get_image_from_cache(id,table):
|
def get_image_from_cache(id,table):
|
||||||
now = int(datetime.datetime.now().timestamp())
|
now = int(datetime.datetime.now().timestamp())
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
op = DB[table].select(
|
op = DB[table].select().where(
|
||||||
DB[table].c.url
|
|
||||||
).where(
|
|
||||||
DB[table].c.id==id,
|
DB[table].c.id==id,
|
||||||
DB[table].c.expire>now
|
DB[table].c.expire>now
|
||||||
)
|
)
|
||||||
result = conn.execute(op).all()
|
result = conn.execute(op).all()
|
||||||
for row in result:
|
for row in result:
|
||||||
return row.url
|
return row.url # returns None if nonexistence cached
|
||||||
|
return False # no cache entry
|
||||||
|
|
||||||
def set_image_in_cache(id,table,url):
|
def set_image_in_cache(id,table,url):
|
||||||
now = int(datetime.datetime.now().timestamp())
|
now = int(datetime.datetime.now().timestamp())
|
||||||
@ -75,7 +74,14 @@ def get_track_image(track=None,track_id=None,fast=False):
|
|||||||
|
|
||||||
# check cache
|
# check cache
|
||||||
result = get_image_from_cache(track_id,'tracks')
|
result = get_image_from_cache(track_id,'tracks')
|
||||||
if result is not None:
|
if result is None:
|
||||||
|
# nonexistence cached, redirect to artist
|
||||||
|
for a in artists:
|
||||||
|
return get_artist_image(artist=a,fast=True)
|
||||||
|
elif result is False:
|
||||||
|
# no cache entry
|
||||||
|
pass
|
||||||
|
else:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# local image
|
# local image
|
||||||
@ -100,7 +106,7 @@ def get_track_image(track=None,track_id=None,fast=False):
|
|||||||
for a in artists:
|
for a in artists:
|
||||||
res = get_artist_image(artist=a,fast=False)
|
res = get_artist_image(artist=a,fast=False)
|
||||||
if res != "": return res
|
if res != "": return res
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def get_artist_image(artist=None,artist_id=None,fast=False):
|
def get_artist_image(artist=None,artist_id=None,fast=False):
|
||||||
@ -110,7 +116,13 @@ def get_artist_image(artist=None,artist_id=None,fast=False):
|
|||||||
|
|
||||||
# check cache
|
# check cache
|
||||||
result = get_image_from_cache(artist_id,'artists')
|
result = get_image_from_cache(artist_id,'artists')
|
||||||
if result is not None:
|
if result is None:
|
||||||
|
# nonexistence cached, whatevs
|
||||||
|
return ""
|
||||||
|
elif result is False:
|
||||||
|
# no cache entry
|
||||||
|
pass
|
||||||
|
else:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# local image
|
# local image
|
||||||
@ -130,7 +142,8 @@ def get_artist_image(artist=None,artist_id=None,fast=False):
|
|||||||
# third party
|
# third party
|
||||||
result = thirdparty.get_image_artist_all(artist)
|
result = thirdparty.get_image_artist_all(artist)
|
||||||
set_image_in_cache(artist_id,'artists',result)
|
set_image_in_cache(artist_id,'artists',result)
|
||||||
return result
|
if result is not None: return result
|
||||||
|
return ""
|
||||||
|
|
||||||
### Caches
|
### Caches
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user