def list_albums(self, artists=None, query=None, output='json'): result = {} if artists: artists = artists.split(',') for artist in artists: for album in self.relationships[artist]: result[album] = self.albums[album] if query: filter_result = {} if not result: result = self.albums for song in self.songs: if query.lower() in self.songs[song]['artist'].lower() and self.songs[song]['album_hash'] in result and self.songs[song]['album_hash'] not in filter_result: filter_result[self.songs[song]['album_hash']] = self.songs[song]['album'] elif query.lower() in self.songs[song]['album'].lower() and self.songs[song]['album_hash'] in result and self.songs[song]['album_hash'] not in filter_result: filter_result[self.songs[song]['album_hash']] = self.songs[song]['album'] elif query.lower() in self.songs[song]['title'].lower() and self.songs[song]['album_hash'] in result and self.songs[song]['album_hash'] not in filter_result: filter_result[self.songs[song]['album_hash']] = self.songs[song]['album'] result = filter_result if output == 'json': if result: return str(result) return str(self.albums) template = Template(file=os.path.join(self._path, 'templates/list_albums.tmpl')) if result: template.albums = result else: template.albums = self.albums return template.respond()
def list_albums(self, artists=None, query=None, output='json'): logger.debug("%s (%s)\tlist_albums(artists=%s, query=%s, output=%s)\tHeaders: %s" % (utils.find_originating_host(cherrypy.request.headers), cherrypy.request.login, artists, query, output, cherrypy.request.headers)) if artists: artists = artists.split(',') albums = self.library.albums(artists, query) if output == 'json': cherrypy.response.headers['Content-Type'] = 'application/json' return json.dumps({'albums': albums}) elif output == 'html': template = Template(file=os.path.join(cfg['THEME_DIR'], 'list_albums.tmpl')) template.albums = albums return template.respond() else: raise cherrypy.HTTPError(501,'Not Implemented')