def list_songs(self, artists=None, albums=None, query=None, output='json'): result = {} if albums and not artists: albums = albums.split(',') for album in albums: for artist in self.relationships: if album in self.relationships[artist]: for song in self.relationships[artist][album]: result[song] = self.songs[song] if artists and not albums: artists = artists.split(',') for artist in artists: for album in self.relationships[artist]: for song in self.relationships[artist][album]: result[song] = self.songs[song] if (artists != None) and (albums != None): artists = artists.split(',') albums = albums.split(',') for album in albums: for artist in artists: try: for song in self.relationships[artist][album]: result[song] = self.songs[song] except: pass if query: filter_result = {} if not result: result = self.songs for song in result: if query.lower() in result[song]['artist'].lower() and song not in filter_result: filter_result[song] = result[song] elif query.lower() in result[song]['album'].lower() and song not in filter_result: filter_result[song] = result[song] elif query.lower() in result[song]['title'].lower() and song not in filter_result: filter_result[song] = result[song] result = filter_result if output =='json': return str(result) template = Template(file=os.path.join(self._path, 'templates/list_songs.tmpl')) template.songs = result return template.respond()
def list_songs(self, artists=None ,albums=None, start=None, length=None, query=None, list_all=False, archive=False, output='json'): logger.debug("%s (%s)\tlist_songs(artists=%s, albums=%s, start=%s, length=%s, query=%s, list_all=%s, archive=%s, output=%s)\tHeaders: %s" % (utils.find_originating_host(cherrypy.request.headers), cherrypy.request.login, artists, albums, start, length, query, list_all, archive, output, cherrypy.request.headers)) if not list_all and not artists and not albums and not query and not archive: songs = [] else: if artists: artists = artists.split(',') if albums: albums = albums.split(',') songs = self.library.songs(artists, albums, query) #log_message = "%s (%s) is " % (cherrypy.request.login, utils.find_originating_host(cherrypy.request.headers)) #if query: # log_message += 'searching for "%s".' % query #elif artists or albums: # log_message += "browsing " # if artists and not albums: # log_message += "albums by %s." % ', '.join(self.library.artists(artists, query)) # elif albums: # log_message += "%s by %s." % (', '.join(self.library.albums(artists, query)), ', '.join(self.library.artists(artists, albums, query))) #if not archive and not list_all: # logger.info(log_message) if start and length: start = int(start) end = int(length) + start if len(songs) - 1 < end: end = -1 songs = songs[start:end] songs.sort(key=itemgetter('albumartist', 'album', 'date', 'discnumber', 'tracknumber')) if output == 'json': cherrypy.response.headers['Content-Type'] = 'application/json' return json.dumps({'songs': songs}) elif output == 'html': template = Template(file=os.path.join(cfg['THEME_DIR'], 'list_songs.tmpl')) template.songs = songs return template.respond() else: raise cherrypy.HTTPError(501,'Not Implemented')
def index(self): songs = db.selectSongs() t = Template(file=tempdir + 'songs.tmpl') t.songs = songs return _tostr(t)
def index(self): template = Template(file=os.path.join(self._path, 'templates/index.tmpl')) template.songs = self.songs return template.respond()