def lookup(config, session, uri): try: sp_link = session.get_link(uri) except ValueError as exc: logger.info('Failed to lookup "%s": %s', uri, exc) return [] try: if sp_link.type is spotify.LinkType.TRACK: return list(_lookup_track(config, sp_link)) elif sp_link.type is spotify.LinkType.ALBUM: return list(_lookup_album(config, sp_link)) elif sp_link.type is spotify.LinkType.ARTIST: with utils.time_logger('Artist lookup'): return list(_lookup_artist(config, sp_link)) elif sp_link.type is spotify.LinkType.PLAYLIST: return list(_lookup_playlist(config, sp_link)) elif sp_link.type is spotify.LinkType.STARRED: return list(reversed(list(_lookup_playlist(config, sp_link)))) else: logger.info( 'Failed to lookup "%s": Cannot handle %r', uri, sp_link.type) return [] except spotify.Error as exc: logger.info('Failed to lookup "%s": %s', uri, exc) return []
def lookup(config, session, web_client, uri): try: web_link = web.WebLink.from_uri(uri) if web_link.type != web.LinkType.PLAYLIST: sp_link = session.get_link(uri) except ValueError as exc: logger.info(f"Failed to lookup {uri!r}: {exc}") return [] try: if web_link.type == web.LinkType.PLAYLIST: return _lookup_playlist(config, session, web_client, uri) elif sp_link.type is spotify.LinkType.TRACK: return list(_lookup_track(config, sp_link)) elif sp_link.type is spotify.LinkType.ALBUM: return list(_lookup_album(config, sp_link)) elif sp_link.type is spotify.LinkType.ARTIST: with utils.time_logger("Artist lookup"): return list(_lookup_artist(config, sp_link)) else: logger.info( f"Failed to lookup {uri!r}: Cannot handle {sp_link.type!r}") return [] except spotify.Error as exc: logger.info(f"Failed to lookup {uri!r}: {exc}") return []
def lookup(config, session, uri): try: sp_link = session.get_link(uri) except ValueError as exc: logger.info('Failed to lookup "%s": %s', uri, exc) return [] try: if sp_link.type is spotify.LinkType.TRACK: return list(_lookup_track(config, sp_link)) elif sp_link.type is spotify.LinkType.ALBUM: return list(_lookup_album(config, sp_link)) elif sp_link.type is spotify.LinkType.ARTIST: with utils.time_logger('Artist lookup'): return list(_lookup_artist(config, sp_link)) elif sp_link.type is spotify.LinkType.PLAYLIST: return list(_lookup_playlist(config, sp_link)) elif sp_link.type is spotify.LinkType.STARRED: return list(reversed(list(_lookup_playlist(config, sp_link)))) else: logger.info('Failed to lookup "%s": Cannot handle %r', uri, sp_link.type) return [] except spotify.Error as exc: logger.info('Failed to lookup "%s": %s', uri, exc) return []
def lookup(config, session, uri, web_client): try: web_link = translator.parse_uri(uri) sp_link = session.get_link(uri) except ValueError as exc: logger.info('Failed to lookup "%s": %s', uri, exc) return [] try: if web_link.type == 'playlist': return list(_lookup_playlist(web_client, config, web_link)) elif web_link.type == 'starred': return list(reversed(_lookup_starred(web_client, config, web_link))) if sp_link.type is spotify.LinkType.TRACK: return list(_lookup_track(config, sp_link)) elif sp_link.type is spotify.LinkType.ALBUM: return list(_lookup_album(config, sp_link)) elif sp_link.type is spotify.LinkType.ARTIST: with utils.time_logger('Artist lookup'): return list(_lookup_artist(config, sp_link)) #elif sp_link.type is spotify.LinkType.PLAYLIST: #return list(_lookup_playlist(config, sp_link)) #elif sp_link.type is spotify.LinkType.STARRED: #return list(reversed(list(_lookup_playlist(config, sp_link)))) else: logger.info('Failed to lookup "%s": Cannot handle %r', uri, sp_link.type) return [] except spotify.Error as exc: logger.info('Failed to lookup "%s": %s', uri, exc) return []
def refresh(self): if not self._backend._web_client.logged_in: return with utils.time_logger("playlists.refresh()", logging.DEBUG): _sp_links.clear() self._backend._web_client.clear_cache() count = 0 for playlist_ref in self._get_flattened_playlist_refs(): self._get_playlist(playlist_ref.uri) count = count + 1 logger.info(f"Refreshed {count} Spotify playlists") self._loaded = True
def lookup(self, uri): with utils.time_logger('playlists.lookup(%s)' % uri): return self._get_playlist(uri)
def get_items(self, uri): with utils.time_logger('playlist.get_items(%s)' % uri): return self._get_playlist(uri, as_items=True)
def as_list(self): with utils.time_logger('playlists.as_list()'): return list(self._get_flattened_playlist_refs())
def lookup(self, uri): with utils.time_logger(f"playlists.lookup({uri!r})", logging.DEBUG): return self._get_playlist(uri)
def get_items(self, uri): with utils.time_logger(f"playlist.get_items({uri!r})", logging.DEBUG): return self._get_playlist(uri, as_items=True)
def as_list(self): with utils.time_logger("playlists.as_list()", logging.DEBUG): if not self._loaded: return [] return list(self._get_flattened_playlist_refs())
def test_time_logger(caplog): with utils.time_logger('task'): pass assert re.match('.*task took \d+ms.*', caplog.text())
def test_time_logger(caplog): with utils.time_logger("task"): pass assert re.match(r".*task took \d+ms.*", caplog.text)