mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented more album functions
This commit is contained in:
parent
e7b1cb469d
commit
6d55d60535
@ -220,6 +220,8 @@ def get_scrobbles(dbconn=None,**keys):
|
||||
result = sqldb.get_scrobbles_of_artist(artist=keys['artist'],since=since,to=to,dbconn=dbconn)
|
||||
elif 'track' in keys:
|
||||
result = sqldb.get_scrobbles_of_track(track=keys['track'],since=since,to=to,dbconn=dbconn)
|
||||
elif 'album' in keys:
|
||||
result = sqldb.get_scrobbles_of_album(album=keys['album'],since=since,to=to,dbconn=dbconn)
|
||||
else:
|
||||
result = sqldb.get_scrobbles(since=since,to=to,dbconn=dbconn)
|
||||
#return result[keys['page']*keys['perpage']:(keys['page']+1)*keys['perpage']]
|
||||
@ -312,6 +314,14 @@ def get_performance(dbconn=None,**keys):
|
||||
if c["artist"] == artist:
|
||||
rank = c["rank"]
|
||||
break
|
||||
elif "album" in keys:
|
||||
album = sqldb.get_album(sqldb.get_album_id(keys['album'],dbconn=dbconn),dbconn=dbconn)
|
||||
charts = get_charts_albums(timerange=rng,dbconn=dbconn)
|
||||
rank = None
|
||||
for c in charts:
|
||||
if c["album"] == album:
|
||||
rank = c["rank"]
|
||||
break
|
||||
else:
|
||||
raise exceptions.MissingEntityParameter()
|
||||
results.append({"range":rng,"rank":rank})
|
||||
|
@ -388,7 +388,7 @@ def get_track_id(trackdict,create_new=True,update_album=False,dbconn=None):
|
||||
if set(artist_ids) == set(match_artist_ids):
|
||||
#print("ID for",trackdict['title'],"was",row[0])
|
||||
if 'album' in trackdict:
|
||||
add_track_to_album(row.id,get_album_id(trackdict['album']),replace=update_album)
|
||||
add_track_to_album(row.id,get_album_id(trackdict['album']),replace=update_album,dbconn=dbconn)
|
||||
return row.id
|
||||
|
||||
if not create_new: return None
|
||||
@ -408,7 +408,7 @@ def get_track_id(trackdict,create_new=True,update_album=False,dbconn=None):
|
||||
#print("Created",trackdict['title'],track_id)
|
||||
|
||||
if 'album' in trackdict:
|
||||
add_track_to_album(track_id,get_album_id(trackdict['album']))
|
||||
add_track_to_album(track_id,get_album_id(trackdict['album']),dbconn=dbconn)
|
||||
return track_id
|
||||
|
||||
@cached_wrapper
|
||||
@ -671,6 +671,29 @@ def get_scrobbles_of_track(track,since=None,to=None,resolve_references=True,dbco
|
||||
#result = [scrobble_db_to_dict(row) for row in result]
|
||||
return result
|
||||
|
||||
@cached_wrapper
|
||||
@connection_provider
|
||||
def get_scrobbles_of_album(album,since=None,to=None,resolve_references=True,dbconn=None):
|
||||
|
||||
if since is None: since=0
|
||||
if to is None: to=now()
|
||||
|
||||
album_id = get_album_id(album,dbconn=dbconn)
|
||||
|
||||
jointable = sql.join(DB['scrobbles'],DB['tracks'],DB['scrobbles'].c.track_id == DB['tracks'].c.id)
|
||||
|
||||
op = jointable.select().where(
|
||||
DB['scrobbles'].c.timestamp<=to,
|
||||
DB['scrobbles'].c.timestamp>=since,
|
||||
DB['tracks'].c.album_id==album_id
|
||||
).order_by(sql.asc('timestamp'))
|
||||
result = dbconn.execute(op).all()
|
||||
|
||||
if resolve_references:
|
||||
result = scrobbles_db_to_dict(result)
|
||||
#result = [scrobble_db_to_dict(row) for row in result]
|
||||
return result
|
||||
|
||||
@cached_wrapper
|
||||
@connection_provider
|
||||
def get_scrobbles(since=None,to=None,resolve_references=True,dbconn=None):
|
||||
|
@ -115,6 +115,11 @@ def get_artist_image(artist=None,artist_id=None):
|
||||
|
||||
return f"/image?type=artist&id={artist_id}"
|
||||
|
||||
def get_album_image(album=None,album_id=None):
|
||||
if album_id is None:
|
||||
album_id = database.sqldb.get_album_id(album)
|
||||
|
||||
return f"/image?type=album&id={album_id}"
|
||||
|
||||
|
||||
resolve_semaphore = BoundedSemaphore(8)
|
||||
|
Loading…
Reference in New Issue
Block a user