stats endpoint

This commit is contained in:
dave 2018-04-07 15:04:41 -07:00
parent 41db860297
commit 8a19422e0f
4 changed files with 16 additions and 5 deletions

View File

@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.2"

View File

@ -10,12 +10,16 @@ import cherrypy
logging = logging.getLogger("api")
class PysonicApi(object):
class PysonicSubsonicApi(object):
def __init__(self, db, library, options):
self.db = db
self.library = library
self.options = options
@cherrypy.expose
def index(self):
return str(self.library.db.get_stats())
@cherrypy.expose
@formatresponse
def ping_view(self, **kwargs):
@ -61,7 +65,7 @@ class PysonicApi(object):
@cherrypy.expose
@formatresponse
def getAlbumList_view(self, type, size=50, offset=0, **kwargs):
def getAlbumList_view(self, type, size=250, offset=0, **kwargs):
qargs = {}
if type == "random":
qargs.update(sortby="random")

View File

@ -2,7 +2,7 @@ import os
import logging
import cherrypy
from sqlite3 import DatabaseError
from pysonic.api import PysonicApi
from pysonic.api import PysonicSubsonicApi
from pysonic.library import PysonicLibrary
from pysonic.database import PysonicDatabase, DuplicateRootException
@ -54,7 +54,7 @@ def main():
# logging.warning("Artists: {}".format([i["name"] for i in library.get_artists()]))
# logging.warning("Albums: {}".format(len(library.get_albums())))
api = PysonicApi(db, library, args)
api = PysonicSubsonicApi(db, library, args)
api_config = {}
if args.disable_auth:
logging.warning("starting up with auth disabled")

View File

@ -147,6 +147,13 @@ class PysonicDatabase(object):
# logging.warning("db schema is version {}".format(version))
pass
@readcursor
def get_stats(self, cursor):
songs = cursor.execute("SELECT COUNT(*) as cnt FROM songs").fetchone()['cnt']
artists = cursor.execute("SELECT COUNT(*) as cnt FROM artists").fetchone()['cnt']
albums = cursor.execute("SELECT COUNT(*) as cnt FROM albums").fetchone()['cnt']
return dict(songs=songs, artists=artists, albums=albums)
# Music related
@readcursor
def add_root(self, cursor, path, name="Library"):