Support recently/most played albums views

This commit is contained in:
dave 2018-04-07 15:24:02 -07:00
parent 8a19422e0f
commit 8340bb3c61
2 changed files with 24 additions and 3 deletions

View File

@ -17,8 +17,11 @@ class PysonicSubsonicApi(object):
self.options = options
@cherrypy.expose
@formatresponse
def index(self):
return str(self.library.db.get_stats())
response = ApiResponse()
response.add_child("totals", **self.library.db.get_stats())
return response
@cherrypy.expose
@formatresponse
@ -73,8 +76,10 @@ class PysonicSubsonicApi(object):
qargs.update(sortby="name", order="asc")
elif type == "newest":
qargs.update(sortby="added", order="desc")
else:
raise NotImplemented()
elif type == "recent":
qargs.update(sortby="played", order="desc")
elif type == "frequent":
qargs.update(sortby="plays", order="desc")
qargs.update(limit=(offset, size))
@ -415,6 +420,10 @@ class PysonicSubsonicApi(object):
@cherrypy.expose
def savePlayQueue_view(self, id, current, position, **kwargs):
print("TODO save playqueue with items {} current {} position {}".format(id, current, position))
song = self.library.get_song(int(current))
self.library.db.update_album_played(song['albumid'], time())
self.library.db.increment_album_plays(song['albumid'])
# TODO save playlist with items ['378', '386', '384', '380', '383'] current 383 position 4471
# id entries are strings!

View File

@ -82,6 +82,8 @@ class PysonicDatabase(object):
'dir' INTEGER,
'name' TEXT,
'added' INTEGER NOT NULL DEFAULT -1,
'played' INTEGER,
'plays' INTEGER NOT NULL DEFAULT 0,
UNIQUE (artistid, dir));""",
"""CREATE TABLE 'songs' (
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
@ -463,6 +465,16 @@ class PysonicDatabase(object):
cursor.execute("DELETE FROM playlists WHERE id=?", (playlist_id, ))
cursor.execute("COMMIT")
@readcursor
def update_album_played(self, cursor, album_id, last_played=None):
cursor.execute("UPDATE albums SET played=? WHERE id=?", (last_played, album_id, ))
cursor.execute("COMMIT")
@readcursor
def increment_album_plays(self, cursor, album_id):
cursor.execute("UPDATE albums SET plays = plays + 1 WHERE id=?", (album_id, ))
cursor.execute("COMMIT")
# User related
@readcursor
def add_user(self, cursor, username, password, is_admin=False):