Browse Source

start saving stars

podcasts
dave 5 years ago
parent
commit
c7af853358
  1. 10
      pysonic/api.py
  2. 16
      pysonic/database.py
  3. 3
      pysonic/library.py

10
pysonic/api.py

@ -310,3 +310,13 @@ class PysonicApi(object):
tag.append(folder)
yield doc.prettify()
@cherrypy.expose
def star_view(self, id, **kwargs):
self.library.set_starred(cherrypy.request.login, int(id), starred=True)
print(cherrypy.request.login)
yield self.response()[0].prettify()
@cherrypy.expose
def unstar_view(self, id, **kwargs):
self.library.set_starred(cherrypy.request.login, int(id), starred=False)
yield self.response()[0].prettify()

16
pysonic/database.py

@ -73,6 +73,15 @@ class PysonicDatabase(object):
'email' TEXT)"""
cursor.execute(users_table)
version = 1
if version < 2:
logging.warning("migrating database to v2 from %s", version)
users_table = """CREATE TABLE 'stars' (
'userid' INTEGER,
'nodeid' INTEGER,
primary key ('userid', 'nodeid'))"""
cursor.execute(users_table)
version = 2
cursor.execute("""UPDATE meta SET value=? WHERE key="db_version";""", (str(version), ))
logging.warning("db schema is version {}".format(version))
@ -154,3 +163,10 @@ class PysonicDatabase(object):
except IndexError:
raise NotFoundError("User doesn't exist")
def set_starred(self, user_id, node_id, starred=True):
with closing(self.db.cursor()) as cursor:
if starred:
query = "INSERT INTO stars (userid, nodeid) VALUES (?, ?);"
else:
query = "DELETE FROM stars WHERE userid=? and nodeid=?;"
cursor.execute(query, (user_id, node_id))

3
pysonic/library.py

@ -94,6 +94,9 @@ class PysonicLibrary(object):
"largeImageUrl": "",
"similarArtists": []}
def set_starred(self, username, node_id, starred):
self.db.set_starred(self.db.get_user(username)["id"], node_id, starred)
def get_user(self, user):
if type(user) is int:
return self.db.get_user(username)

Loading…
Cancel
Save