Support recently/most played albums views
This commit is contained in:
parent
8a19422e0f
commit
8340bb3c61
|
@ -17,8 +17,11 @@ class PysonicSubsonicApi(object):
|
||||||
self.options = options
|
self.options = options
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
|
@formatresponse
|
||||||
def index(self):
|
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
|
@cherrypy.expose
|
||||||
@formatresponse
|
@formatresponse
|
||||||
|
@ -73,8 +76,10 @@ class PysonicSubsonicApi(object):
|
||||||
qargs.update(sortby="name", order="asc")
|
qargs.update(sortby="name", order="asc")
|
||||||
elif type == "newest":
|
elif type == "newest":
|
||||||
qargs.update(sortby="added", order="desc")
|
qargs.update(sortby="added", order="desc")
|
||||||
else:
|
elif type == "recent":
|
||||||
raise NotImplemented()
|
qargs.update(sortby="played", order="desc")
|
||||||
|
elif type == "frequent":
|
||||||
|
qargs.update(sortby="plays", order="desc")
|
||||||
|
|
||||||
qargs.update(limit=(offset, size))
|
qargs.update(limit=(offset, size))
|
||||||
|
|
||||||
|
@ -415,6 +420,10 @@ class PysonicSubsonicApi(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def savePlayQueue_view(self, id, current, position, **kwargs):
|
def savePlayQueue_view(self, id, current, position, **kwargs):
|
||||||
print("TODO save playqueue with items {} current {} position {}".format(id, current, position))
|
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
|
# TODO save playlist with items ['378', '386', '384', '380', '383'] current 383 position 4471
|
||||||
# id entries are strings!
|
# id entries are strings!
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@ class PysonicDatabase(object):
|
||||||
'dir' INTEGER,
|
'dir' INTEGER,
|
||||||
'name' TEXT,
|
'name' TEXT,
|
||||||
'added' INTEGER NOT NULL DEFAULT -1,
|
'added' INTEGER NOT NULL DEFAULT -1,
|
||||||
|
'played' INTEGER,
|
||||||
|
'plays' INTEGER NOT NULL DEFAULT 0,
|
||||||
UNIQUE (artistid, dir));""",
|
UNIQUE (artistid, dir));""",
|
||||||
"""CREATE TABLE 'songs' (
|
"""CREATE TABLE 'songs' (
|
||||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
@ -463,6 +465,16 @@ class PysonicDatabase(object):
|
||||||
cursor.execute("DELETE FROM playlists WHERE id=?", (playlist_id, ))
|
cursor.execute("DELETE FROM playlists WHERE id=?", (playlist_id, ))
|
||||||
cursor.execute("COMMIT")
|
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
|
# User related
|
||||||
@readcursor
|
@readcursor
|
||||||
def add_user(self, cursor, username, password, is_admin=False):
|
def add_user(self, cursor, username, password, is_admin=False):
|
||||||
|
|
Loading…
Reference in New Issue