stats endpoint
This commit is contained in:
parent
41db860297
commit
8a19422e0f
|
@ -1 +1 @@
|
||||||
__version__ = "0.0.1"
|
__version__ = "0.0.2"
|
||||||
|
|
|
@ -10,12 +10,16 @@ import cherrypy
|
||||||
logging = logging.getLogger("api")
|
logging = logging.getLogger("api")
|
||||||
|
|
||||||
|
|
||||||
class PysonicApi(object):
|
class PysonicSubsonicApi(object):
|
||||||
def __init__(self, db, library, options):
|
def __init__(self, db, library, options):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.library = library
|
self.library = library
|
||||||
self.options = options
|
self.options = options
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def index(self):
|
||||||
|
return str(self.library.db.get_stats())
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@formatresponse
|
@formatresponse
|
||||||
def ping_view(self, **kwargs):
|
def ping_view(self, **kwargs):
|
||||||
|
@ -61,7 +65,7 @@ class PysonicApi(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@formatresponse
|
@formatresponse
|
||||||
def getAlbumList_view(self, type, size=50, offset=0, **kwargs):
|
def getAlbumList_view(self, type, size=250, offset=0, **kwargs):
|
||||||
qargs = {}
|
qargs = {}
|
||||||
if type == "random":
|
if type == "random":
|
||||||
qargs.update(sortby="random")
|
qargs.update(sortby="random")
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import cherrypy
|
import cherrypy
|
||||||
from sqlite3 import DatabaseError
|
from sqlite3 import DatabaseError
|
||||||
from pysonic.api import PysonicApi
|
from pysonic.api import PysonicSubsonicApi
|
||||||
from pysonic.library import PysonicLibrary
|
from pysonic.library import PysonicLibrary
|
||||||
from pysonic.database import PysonicDatabase, DuplicateRootException
|
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("Artists: {}".format([i["name"] for i in library.get_artists()]))
|
||||||
# logging.warning("Albums: {}".format(len(library.get_albums())))
|
# logging.warning("Albums: {}".format(len(library.get_albums())))
|
||||||
|
|
||||||
api = PysonicApi(db, library, args)
|
api = PysonicSubsonicApi(db, library, args)
|
||||||
api_config = {}
|
api_config = {}
|
||||||
if args.disable_auth:
|
if args.disable_auth:
|
||||||
logging.warning("starting up with auth disabled")
|
logging.warning("starting up with auth disabled")
|
||||||
|
|
|
@ -147,6 +147,13 @@ class PysonicDatabase(object):
|
||||||
# logging.warning("db schema is version {}".format(version))
|
# logging.warning("db schema is version {}".format(version))
|
||||||
pass
|
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
|
# Music related
|
||||||
@readcursor
|
@readcursor
|
||||||
def add_root(self, cursor, path, name="Library"):
|
def add_root(self, cursor, path, name="Library"):
|
||||||
|
|
Loading…
Reference in New Issue