mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-21 08:24:00 +01:00
Added index fetching, separated findAlbum and findArtist, updated apireference
This commit is contained in:
+4
-5
@@ -2,10 +2,9 @@
|
|||||||
General structure:
|
General structure:
|
||||||
http://localhost:8181 + HTTP_ROOT + /api?apikey=$apikey&cmd=$command
|
http://localhost:8181 + HTTP_ROOT + /api?apikey=$apikey&cmd=$command
|
||||||
|
|
||||||
Optional parameters:
|
Data returned in json format
|
||||||
format : json, xml
|
|
||||||
|
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
&getIndex
|
||||||
findArtist?name=$artistname&type={album,artist}[&limit=$limit]
|
&findArtist?name=$artistname[&limit=$limit]
|
||||||
|
&findAlbum?name=$albumname[&limit=$limit]
|
||||||
+51
-31
@@ -3,8 +3,10 @@ import headphones
|
|||||||
from headphones import db, mb, logger
|
from headphones import db, mb, logger
|
||||||
|
|
||||||
import lib.simplejson as simplejson
|
import lib.simplejson as simplejson
|
||||||
|
from xml.dom.minidom import Document
|
||||||
|
import copy
|
||||||
|
|
||||||
cmd_list = [ 'findArtist']
|
cmd_list = [ 'getIndex', 'findArtist']
|
||||||
|
|
||||||
class Api(object):
|
class Api(object):
|
||||||
|
|
||||||
@@ -12,12 +14,10 @@ class Api(object):
|
|||||||
|
|
||||||
self.apikey = None
|
self.apikey = None
|
||||||
self.cmd = None
|
self.cmd = None
|
||||||
self.format = 'json'
|
|
||||||
self.id = None
|
self.id = None
|
||||||
|
|
||||||
self.kwargs = None
|
self.kwargs = None
|
||||||
|
|
||||||
self.rawdata = None
|
|
||||||
self.data = None
|
self.data = None
|
||||||
|
|
||||||
def checkParams(self,*args,**kwargs):
|
def checkParams(self,*args,**kwargs):
|
||||||
@@ -52,49 +52,69 @@ class Api(object):
|
|||||||
else:
|
else:
|
||||||
self.cmd = kwargs.pop('cmd')
|
self.cmd = kwargs.pop('cmd')
|
||||||
|
|
||||||
if 'format' not in kwargs:
|
#if 'format' not in kwargs:
|
||||||
self.format = 'json'
|
# self.format = 'json'
|
||||||
else:
|
#else:
|
||||||
if kwargs['format'] not in ['json', 'xml']:
|
# if kwargs['format'] not in ['json', 'xml']:
|
||||||
self.data = 'Unknown format: %s' % kwargs['format']
|
# self.data = 'Unknown format: %s' % kwargs['format']
|
||||||
return
|
# return
|
||||||
else:
|
# else:
|
||||||
self.format = kwargs.pop('format')
|
# self.format = kwargs.pop('format')
|
||||||
|
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
self.data = 'OK'
|
self.data = 'OK'
|
||||||
|
|
||||||
def formatData(self):
|
|
||||||
|
|
||||||
self.data = '%s' % self.data
|
|
||||||
|
|
||||||
def fetchData(self):
|
def fetchData(self):
|
||||||
|
|
||||||
|
if self.cmd == 'getIndex':
|
||||||
|
self._getIndex()
|
||||||
|
|
||||||
if self.cmd == 'findArtist':
|
if self.cmd == 'findArtist':
|
||||||
self.findArtist(**self.kwargs)
|
self._findArtist(**self.kwargs)
|
||||||
|
|
||||||
return simplejson.dumps(self.data)
|
return simplejson.dumps(self.data)
|
||||||
|
|
||||||
def findArtist(self, **kwargs):
|
def _getIndex(self):
|
||||||
if 'type' not in kwargs:
|
myDB = db.DBConnection()
|
||||||
self.data = 'Missing parameter: type'
|
artists = myDB.select('SELECT * from artists order by ArtistSortName COLLATE NOCASE')
|
||||||
return
|
|
||||||
|
artists_as_dic = []
|
||||||
|
for artist in artists:
|
||||||
|
artist_as_dic = {
|
||||||
|
'ArtistID' : artist['ArtistID'],
|
||||||
|
'ArtistName' : artist['ArtistName'],
|
||||||
|
'ArtistSortName' : artist['ArtistSortName'],
|
||||||
|
'DateAdded' : artist['DateAdded'],
|
||||||
|
'Status' : artist['Status'],
|
||||||
|
'IncludeExtras' : artist['IncludeExtras'],
|
||||||
|
'LatestAlbum' : artist['LatestAlbum'],
|
||||||
|
'ReleaseDate' : artist['ReleaseDate'],
|
||||||
|
'AlbumID' : artist['AlbumID'],
|
||||||
|
'HaveTracks' : artist['HaveTracks'],
|
||||||
|
'TotalTracks' : artist['TotalTracks']}
|
||||||
|
artists_as_dic.append(artist_as_dic)
|
||||||
|
|
||||||
|
self.data = artists_as_dic
|
||||||
|
|
||||||
|
def _findArtist(self, **kwargs):
|
||||||
if 'name' not in kwargs:
|
if 'name' not in kwargs:
|
||||||
self.data = 'Missing parameter: name'
|
self.data = 'Missing parameter: name'
|
||||||
return
|
return
|
||||||
if kwargs['type'] not in ['artist','album']:
|
|
||||||
self.data = 'Incorrect type: %s' % kwargs['type']
|
|
||||||
return
|
|
||||||
if 'limit' in kwargs:
|
if 'limit' in kwargs:
|
||||||
limit = kwargs['limit']
|
limit = kwargs['limit']
|
||||||
else:
|
else:
|
||||||
limit=50
|
limit=50
|
||||||
if kwargs['type'] == 'artist':
|
|
||||||
self.data = mb.findArtist(kwargs['name'], limit)
|
self.data = mb.findArtist(kwargs['name'], limit)
|
||||||
|
|
||||||
|
def _findAlbum(self, **kwargs):
|
||||||
|
if 'name' not in kwargs:
|
||||||
|
self.data = 'Missing parameter: name'
|
||||||
|
return
|
||||||
|
if 'limit' in kwargs:
|
||||||
|
limit = kwargs['limit']
|
||||||
else:
|
else:
|
||||||
self.data = mb.findRelease(kwargs['name'], limit)
|
limit=50
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.data = mb.findRelease(kwargs['name'], limit)
|
||||||
|
|
||||||
Reference in New Issue
Block a user