From b64cefb0d0f3994f73f9fe354135e08b0daaa202 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 10 Jul 2022 13:11:27 -0400 Subject: [PATCH 01/20] Add params to debug --- beetsplug/spotify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index ef7407b36f..0138f0b9fe 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -194,8 +194,8 @@ def _handle_response(self, request_type, url, params=None): time.sleep(int(seconds) + 1) return self._handle_response(request_type, url, params=params) elif response.status_code == 404: - raise SpotifyAPIError("API Error {0.status_code} for {1}" - .format(response, url)) + raise SpotifyAPIError("API Error {0.status_code} for {1} and \ + params = {2}".format(response, url, params=params)) else: raise ui.UserError( '{} API error:\n{}\nURL:\n{}\nparams:\n{}'.format( From a28f8835cb888a6601f3d0b205962e3dda8ffa59 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 10 Jul 2022 13:12:38 -0400 Subject: [PATCH 02/20] Update spotify.py --- beetsplug/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 0138f0b9fe..8abf3154cd 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -195,7 +195,7 @@ def _handle_response(self, request_type, url, params=None): return self._handle_response(request_type, url, params=params) elif response.status_code == 404: raise SpotifyAPIError("API Error {0.status_code} for {1} and \ - params = {2}".format(response, url, params=params)) + params = {2}".format(response, url, params)) else: raise ui.UserError( '{} API error:\n{}\nURL:\n{}\nparams:\n{}'.format( From 2bd61a7c48eb3750397387c8a2e1782c7d417e20 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 10 Jul 2022 13:15:25 -0400 Subject: [PATCH 03/20] Update spotify.py --- beetsplug/spotify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 8abf3154cd..7071e1c0c4 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -194,8 +194,8 @@ def _handle_response(self, request_type, url, params=None): time.sleep(int(seconds) + 1) return self._handle_response(request_type, url, params=params) elif response.status_code == 404: - raise SpotifyAPIError("API Error {0.status_code} for {1} and \ - params = {2}".format(response, url, params)) + raise SpotifyAPIError("API Error {} for {} and params = {}". + format(response.status_code, url, params)) else: raise ui.UserError( '{} API error:\n{}\nURL:\n{}\nparams:\n{}'.format( From c2ad2b3d4c446e0cc4b14922104fea86da03294b Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 10 Jul 2022 13:23:10 -0400 Subject: [PATCH 04/20] Update spotify.py --- beetsplug/spotify.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 7071e1c0c4..b95546dd22 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -194,8 +194,9 @@ def _handle_response(self, request_type, url, params=None): time.sleep(int(seconds) + 1) return self._handle_response(request_type, url, params=params) elif response.status_code == 404: - raise SpotifyAPIError("API Error {} for {} and params = {}". - format(response.status_code, url, params)) + raise SpotifyAPIError("API Error: {}\nURL: {}\nparams: {}". + format(response.status_code, url, + params)) else: raise ui.UserError( '{} API error:\n{}\nURL:\n{}\nparams:\n{}'.format( From 7b94bbd76499b059e945a52dfc90b2c7fc3d64e5 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Mon, 11 Jul 2022 11:36:08 -0400 Subject: [PATCH 05/20] Update spotify.py --- beetsplug/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index b95546dd22..5ecb8e81a3 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -36,7 +36,7 @@ class SpotifyAPIError(Exception): - pass + continue class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): From 525e5eafd5a875a052294eac3307a1f886e7bf9a Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Mon, 11 Jul 2022 11:36:52 -0400 Subject: [PATCH 06/20] revert --- beetsplug/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 5ecb8e81a3..b95546dd22 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -36,7 +36,7 @@ class SpotifyAPIError(Exception): - continue + pass class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): From d82362df3e2774ab3fc929b0276df3d39cfc54fa Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Mon, 11 Jul 2022 11:40:32 -0400 Subject: [PATCH 07/20] Update spotify.py --- beetsplug/spotify.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index b95546dd22..2d3b7c975a 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -658,8 +658,9 @@ def track_popularity(self, track_id=None): def track_audio_features(self, track_id=None): """Fetch track audio features by its Spotify ID.""" try: - return self._handle_response( + track_features = self._handle_response( requests.get, self.audio_features_url + track_id) except SpotifyAPIError as e: self._log.debug('Spotify API error: {}', e) - return None + track_features = None + return track_features From e1153f7772f931fe74a49b912b4a98492097e107 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Mon, 11 Jul 2022 11:42:24 -0400 Subject: [PATCH 08/20] revert --- beetsplug/spotify.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 2d3b7c975a..b95546dd22 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -658,9 +658,8 @@ def track_popularity(self, track_id=None): def track_audio_features(self, track_id=None): """Fetch track audio features by its Spotify ID.""" try: - track_features = self._handle_response( + return self._handle_response( requests.get, self.audio_features_url + track_id) except SpotifyAPIError as e: self._log.debug('Spotify API error: {}', e) - track_features = None - return track_features + return None From 4e63c8893b58f7d513a1ae7546dfa5084a9e5308 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 09:28:23 -0400 Subject: [PATCH 09/20] refactor handle_reponse --- beetsplug/spotify.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index b95546dd22..b7df9dcf8b 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -396,15 +396,18 @@ def _search_api(self, query_type, filters=None, keywords=''): self._log.debug( f"Searching {self.data_source} for '{query}'" ) - response_data = ( - self._handle_response( + try: + response = self._handle_response( requests.get, self.search_url, params={'q': query, 'type': query_type}, ) - .get(query_type + 's', {}) - .get('items', []) - ) + except SpotifyAPIError as e: + self._log.debug('Spotify API error: {}', e) + response_data = (response + .get(query_type + 's', {}) + .get('items', []) + ) self._log.debug( "Found {} result(s) from {} for '{}'", len(response_data), From 85e58d48a26463f0f370f5f051f65bb9451431af Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 09:30:07 -0400 Subject: [PATCH 10/20] Update spotify.py --- beetsplug/spotify.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index b7df9dcf8b..d3910523c7 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -404,6 +404,7 @@ def _search_api(self, query_type, filters=None, keywords=''): ) except SpotifyAPIError as e: self._log.debug('Spotify API error: {}', e) + return None response_data = (response .get(query_type + 's', {}) .get('items', []) From 500ff5135c34a2bd13d8ca35b8ac6d80c3ef73db Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 09:37:14 -0400 Subject: [PATCH 11/20] Update plugins.py --- beets/plugins.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index ed1f82d8f3..6a68a3d34f 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -749,7 +749,10 @@ def item_candidates(self, item, artist, title): tracks = self._search_api( query_type='track', keywords=title, filters={'artist': artist} ) - return [self.track_for_id(track_data=track) for track in tracks] + if tracks is not None: + return [self.track_for_id(track_data=track) for track in tracks] + else: + return None def album_distance(self, items, album_info, mapping): return get_distance( From 16f8b47be3010e6d8826ed102d4889bf6829fc43 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 09:49:49 -0400 Subject: [PATCH 12/20] Update plugins.py --- beets/plugins.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index 6a68a3d34f..2f5ba397b2 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -389,7 +389,8 @@ def item_candidates(item, artist, title): """Gets MusicBrainz candidates for an item from the plugins. """ for plugin in find_plugins(): - yield from plugin.item_candidates(item, artist, title) + if plugin.item_candidates(item, artist, title) is not None: + yield from plugin.item_candidates(item, artist, title) def album_for_id(album_id): From 28614d94dc8a78d5012d97a56406fe360aa67c67 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 10:32:55 -0400 Subject: [PATCH 13/20] lint --- beetsplug/spotify.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index d3910523c7..be9a8509e6 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -405,10 +405,8 @@ def _search_api(self, query_type, filters=None, keywords=''): except SpotifyAPIError as e: self._log.debug('Spotify API error: {}', e) return None - response_data = (response - .get(query_type + 's', {}) - .get('items', []) - ) + response_data = (response.get(query_type + 's', {}) + .get('items', [])) self._log.debug( "Found {} result(s) from {} for '{}'", len(response_data), From 3896e5cd9c6510b3e8e54728d89c4d2a07294b74 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 16:14:22 -0400 Subject: [PATCH 14/20] Update plugins.py --- beets/plugins.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index 2f5ba397b2..bbf29e4be1 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -731,7 +731,8 @@ def candidates(self, items, artist, album, va_likely, extra_tags=None): if not va_likely: query_filters['artist'] = artist results = self._search_api(query_type='album', filters=query_filters) - albums = [self.album_for_id(album_id=r['id']) for r in results] + if results is not None: + albums = [self.album_for_id(album_id=r['id']) for r in results] return [a for a in albums if a is not None] def item_candidates(self, item, artist, title): From 32afd79eed7f5d89dd5e34d653ec890d571cae63 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 16:15:59 -0400 Subject: [PATCH 15/20] Update plugins.py --- beets/plugins.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beets/plugins.py b/beets/plugins.py index bbf29e4be1..b31c55482f 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -733,6 +733,8 @@ def candidates(self, items, artist, album, va_likely, extra_tags=None): results = self._search_api(query_type='album', filters=query_filters) if results is not None: albums = [self.album_for_id(album_id=r['id']) for r in results] + else: + albums = None return [a for a in albums if a is not None] def item_candidates(self, item, artist, title): From 5084794a94115e532982bd80f3bbab58e3187712 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 16:17:46 -0400 Subject: [PATCH 16/20] Update plugins.py --- beets/plugins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beets/plugins.py b/beets/plugins.py index b31c55482f..9b966cc197 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -733,9 +733,9 @@ def candidates(self, items, artist, album, va_likely, extra_tags=None): results = self._search_api(query_type='album', filters=query_filters) if results is not None: albums = [self.album_for_id(album_id=r['id']) for r in results] + return [a for a in albums if a is not None] else: - albums = None - return [a for a in albums if a is not None] + return None def item_candidates(self, item, artist, title): """Returns a list of TrackInfo objects for Search API results From c685f196441ad1018cedc2d0935b8c2d6fcc44cf Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 16:21:06 -0400 Subject: [PATCH 17/20] Update plugins.py --- beets/plugins.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index 9b966cc197..82c9ccb2bf 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -381,7 +381,9 @@ def candidates(items, artist, album, va_likely, extra_tags=None): """Gets MusicBrainz candidates for an album from each plugin. """ for plugin in find_plugins(): - yield from plugin.candidates(items, artist, album, va_likely, + if plugin.candidates(items, artist, album, va_likely, + extra_tags) is not None: + yield from plugin.candidates(items, artist, album, va_likely, extra_tags) From 8fcd87ef9feb3a2e253969f70d85e1d852354668 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 12 Jul 2022 16:28:23 -0400 Subject: [PATCH 18/20] Lint --- beets/plugins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/plugins.py b/beets/plugins.py index 82c9ccb2bf..13fb50cae9 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -384,7 +384,7 @@ def candidates(items, artist, album, va_likely, extra_tags=None): if plugin.candidates(items, artist, album, va_likely, extra_tags) is not None: yield from plugin.candidates(items, artist, album, va_likely, - extra_tags) + extra_tags) def item_candidates(item, artist, title): From 01fa07de06b113d534906648e8b6f2ec40d2d8d7 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Thu, 14 Jul 2022 20:56:07 -0400 Subject: [PATCH 19/20] Revert plugins.py changes --- beets/plugins.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/beets/plugins.py b/beets/plugins.py index 13fb50cae9..ed1f82d8f3 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -381,18 +381,15 @@ def candidates(items, artist, album, va_likely, extra_tags=None): """Gets MusicBrainz candidates for an album from each plugin. """ for plugin in find_plugins(): - if plugin.candidates(items, artist, album, va_likely, - extra_tags) is not None: - yield from plugin.candidates(items, artist, album, va_likely, - extra_tags) + yield from plugin.candidates(items, artist, album, va_likely, + extra_tags) def item_candidates(item, artist, title): """Gets MusicBrainz candidates for an item from the plugins. """ for plugin in find_plugins(): - if plugin.item_candidates(item, artist, title) is not None: - yield from plugin.item_candidates(item, artist, title) + yield from plugin.item_candidates(item, artist, title) def album_for_id(album_id): @@ -733,11 +730,8 @@ def candidates(self, items, artist, album, va_likely, extra_tags=None): if not va_likely: query_filters['artist'] = artist results = self._search_api(query_type='album', filters=query_filters) - if results is not None: - albums = [self.album_for_id(album_id=r['id']) for r in results] - return [a for a in albums if a is not None] - else: - return None + albums = [self.album_for_id(album_id=r['id']) for r in results] + return [a for a in albums if a is not None] def item_candidates(self, item, artist, title): """Returns a list of TrackInfo objects for Search API results @@ -755,10 +749,7 @@ def item_candidates(self, item, artist, title): tracks = self._search_api( query_type='track', keywords=title, filters={'artist': artist} ) - if tracks is not None: - return [self.track_for_id(track_data=track) for track in tracks] - else: - return None + return [self.track_for_id(track_data=track) for track in tracks] def album_distance(self, items, album_info, mapping): return get_distance( From 06825e0729abf1897db62f122b31e843e0b8074f Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Fri, 15 Jul 2022 09:22:23 -0400 Subject: [PATCH 20/20] Return an empty sequence --- beetsplug/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index be9a8509e6..30fbabc060 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -404,7 +404,7 @@ def _search_api(self, query_type, filters=None, keywords=''): ) except SpotifyAPIError as e: self._log.debug('Spotify API error: {}', e) - return None + return [] response_data = (response.get(query_type + 's', {}) .get('items', [])) self._log.debug(