From 128ba8173f986de7a57f9e3497e30fbd9505d757 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 8 Mar 2020 12:43:10 +0100 Subject: [PATCH] Fix all flake8 warnings --- mopidy_subidy/library.py | 18 +---------------- mopidy_subidy/playlists.py | 3 --- mopidy_subidy/subsonic_api.py | 38 ++++++++++++++++++----------------- tests/test_extension.py | 2 +- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index 3c597e8..6da42e0 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -1,6 +1,6 @@ import logging -from mopidy import backend, models +from mopidy import backend from mopidy.models import Ref, SearchResult from mopidy_subidy import uri @@ -130,22 +130,6 @@ class SubidyLibraryProvider(backend.LibraryProvider): def refresh(self, uri): pass - def search_uri(self, query): - type = uri.get_type(lookup_uri) - if type == uri.ARTIST: - artist = self.lookup_artist(uri.get_artist_id(lookup_uri)) - if artist is not None: - return SearchResult(artists=[artist]) - elif type == uri.ALBUM: - album = self.lookup_album(uri.get_album_id(lookup_uri)) - if album is not None: - return SearchResult(albums=[album]) - elif type == uri.SONG: - song = self.lookup_song(uri.get_song_id(lookup_uri)) - if song is not None: - return SearchResult(tracks=[song]) - return None - def search_by_artist_album_and_track( self, artist_name, album_name, track_name ): diff --git a/mopidy_subidy/playlists.py b/mopidy_subidy/playlists.py index cb0d19f..c048643 100644 --- a/mopidy_subidy/playlists.py +++ b/mopidy_subidy/playlists.py @@ -1,7 +1,6 @@ import logging from mopidy import backend -from mopidy.models import Playlist from mopidy_subidy import uri logger = logging.getLogger(__name__) @@ -35,13 +34,11 @@ class SubidyPlaylistsProvider(backend.PlaylistsProvider): self.subsonic_api.delete_playlist_raw(playlist_id) def get_items(self, items_uri): - # logger.info('ITEMS %s: %s' % (lookup_uri, self.subsonic_api.get_playlist_songs_as_refs(uri.get_playlist_id(items_uri)))) return self.subsonic_api.get_playlist_as_songs_as_refs( uri.get_playlist_id(items_uri) ) def lookup(self, lookup_uri): - # logger.info('LOOKUP PLAYLIST %s: %s' % (lookup_uri, self.subsonic_api.get_playlist_as_playlist(uri.get_playlist_id(lookup_uri)))) return self.subsonic_api.get_playlist_as_playlist( uri.get_playlist_id(lookup_uri) ) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index e40b765..e8b4ad2 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -1,4 +1,3 @@ -import itertools import logging import re from urllib.parse import urlencode, urlparse @@ -16,7 +15,9 @@ UNKNOWN_ARTIST = "Unknown Artist" MAX_SEARCH_RESULTS = 100 MAX_LIST_RESULTS = 500 -ref_sort_key = lambda ref: ref.name + +def ref_sort_key(ref): + return ref.name def string_nums_nocase_sort_key(s): @@ -66,7 +67,8 @@ class SubsonicApi: self.username = username self.password = password logger.info( - f"Connecting to subsonic server on url {url} as user {username}, API version {api_version}" + f"Connecting to subsonic server on url {url} as user {username}, " + f"API version {api_version}" ) try: self.connection.ping() @@ -108,7 +110,7 @@ class SubsonicApi: MAX_SEARCH_RESULTS if not exclude_songs else 0, 0, ) - except Exception as e: + except Exception: logger.warning("Connecting to subsonic failed when searching.") return None if response.get("status") != RESPONSE_OK: @@ -148,7 +150,7 @@ class SubsonicApi: def create_playlist_raw(self, name): try: response = self.connection.createPlaylist(name=name) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when creating playlist." ) @@ -164,7 +166,7 @@ class SubsonicApi: def delete_playlist_raw(self, playlist_id): try: response = self.connection.deletePlaylist(playlist_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when deleting playlist." ) @@ -182,7 +184,7 @@ class SubsonicApi: response = self.connection.createPlaylist( playlist_id, songIds=song_ids ) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when creating playlist." ) @@ -198,7 +200,7 @@ class SubsonicApi: def get_raw_artists(self): try: response = self.connection.getArtists() - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading list of artists." ) @@ -225,7 +227,7 @@ class SubsonicApi: def get_raw_rootdirs(self): try: response = self.connection.getIndexes() - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading list of rootdirs." ) @@ -252,7 +254,7 @@ class SubsonicApi: def get_song_by_id(self, song_id): try: response = self.connection.getSong(song_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading song by id." ) @@ -272,7 +274,7 @@ class SubsonicApi: def get_album_by_id(self, album_id): try: response = self.connection.getAlbum(album_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading album by id." ) @@ -292,7 +294,7 @@ class SubsonicApi: def get_artist_by_id(self, artist_id): try: response = self.connection.getArtist(artist_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading artist by id." ) @@ -312,7 +314,7 @@ class SubsonicApi: def get_raw_playlists(self): try: response = self.connection.getPlaylists() - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading list of playlists." ) @@ -334,7 +336,7 @@ class SubsonicApi: def get_raw_playlist(self, playlist_id): try: response = self.connection.getPlaylist(playlist_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading playlist." ) @@ -350,7 +352,7 @@ class SubsonicApi: def get_raw_dir(self, parent_id): try: response = self.connection.getMusicDirectory(parent_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when listing content of music directory." ) @@ -370,7 +372,7 @@ class SubsonicApi: def get_raw_albums(self, artist_id): try: response = self.connection.getArtist(artist_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading list of albums." ) @@ -392,7 +394,7 @@ class SubsonicApi: def get_raw_songs(self, album_id): try: response = self.connection.getAlbum(album_id) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading list of songs in album." ) @@ -411,7 +413,7 @@ class SubsonicApi: def get_raw_album_list(self, ltype, size=MAX_LIST_RESULTS): try: response = self.connection.getAlbumList2(ltype=ltype, size=size) - except Exception as e: + except Exception: logger.warning( "Connecting to subsonic failed when loading album list." ) diff --git a/tests/test_extension.py b/tests/test_extension.py index b2fa67f..70ea844 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -16,7 +16,7 @@ def test_get_config_schema(): schema = ext.get_config_schema() # TODO Test the content of your config schema - # assert "username" in schema + assert "url" in schema # assert "password" in schema