From 86daa0111c4e4de514b1bb9a63ef5c30c607dfd7 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sat, 11 Nov 2023 21:02:52 -0500 Subject: [PATCH 01/15] Update spotify.py --- beetsplug/spotify.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 987b18aaf..5c292c0de 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -242,6 +242,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): album_data = self._handle_response( requests.get, self.album_url + spotify_id ) + self._log.debug("album_data: {}", album_data) if album_data["name"] == "": self._log.debug("Album removed from Spotify: {}", album_id) return None @@ -359,6 +360,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): track_data = self._handle_response( requests.get, self.track_url + spotify_id ) + self._log.debug("track_data: {}", track_data) track = self._get_track(track_data) # Get album's tracks to set `track.index` (position on the entire From d561ba77931071511f3959dfac0d7a2fb064afc7 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sat, 11 Nov 2023 21:23:50 -0500 Subject: [PATCH 02/15] Add isrc --- beetsplug/spotify.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 5c292c0de..5fc35fe9d 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -242,7 +242,6 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): album_data = self._handle_response( requests.get, self.album_url + spotify_id ) - self._log.debug("album_data: {}", album_data) if album_data["name"] == "": self._log.debug("Album removed from Spotify: {}", album_id) return None @@ -306,6 +305,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): mediums=max(medium_totals.keys()), data_source=self.data_source, data_url=album_data["external_urls"]["spotify"], + isrc=album_data["external_ids"].get("isrc"), ) def _get_track(self, track_data): @@ -360,7 +360,6 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): track_data = self._handle_response( requests.get, self.track_url + spotify_id ) - self._log.debug("track_data: {}", track_data) track = self._get_track(track_data) # Get album's tracks to set `track.index` (position on the entire From e9bfeee9e726b7e8ae57d334b8ea373fd360a71e Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sat, 11 Nov 2023 21:28:27 -0500 Subject: [PATCH 03/15] Update changelog.rst --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 728605d81..51b885a4b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,6 +17,8 @@ Major new features: New features: +* :doc:`plugins/spotify`: Update ISRC field from Spotify plugin. + :bug:`4992` * :doc:`plugins/discogs`: supply a value for the `cover_art_url` attribute, for use by `fetchart`. :bug:`429` * :ref:`update-cmd`: added ```-e``` flag for excluding fields from being updated. From 263796d194e7ab4f4832a1b966ab7959b9699a75 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sat, 11 Nov 2023 21:33:18 -0500 Subject: [PATCH 04/15] Update changelog.rst --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 51b885a4b..72578f918 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,7 +17,7 @@ Major new features: New features: -* :doc:`plugins/spotify`: Update ISRC field from Spotify plugin. +* :doc:`plugins/spotify`: We now fetch ISRC identifiers from Spotify. :bug:`4992` * :doc:`plugins/discogs`: supply a value for the `cover_art_url` attribute, for use by `fetchart`. :bug:`429` From 7952f0a71d4089f3953bbdbd7ed32807fb07b7e4 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sat, 11 Nov 2023 21:35:14 -0500 Subject: [PATCH 05/15] Also obtain track ISRC --- beetsplug/spotify.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 5fc35fe9d..6b4be1dbd 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -338,6 +338,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): medium_index=track_data["track_number"], data_source=self.data_source, data_url=track_data["external_urls"]["spotify"], + isrc=track_data["external_ids"].get("isrc"), ) def track_for_id(self, track_id=None, track_data=None): From e7d86f2fc93c97ede66fd35642db8c01f649e2c1 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 12 Nov 2023 09:40:25 -0500 Subject: [PATCH 06/15] Update spotify.py --- beetsplug/spotify.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 6b4be1dbd..85c39f5df 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -305,7 +305,6 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): mediums=max(medium_totals.keys()), data_source=self.data_source, data_url=album_data["external_urls"]["spotify"], - isrc=album_data["external_ids"].get("isrc"), ) def _get_track(self, track_data): @@ -338,7 +337,6 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): medium_index=track_data["track_number"], data_source=self.data_source, data_url=track_data["external_urls"]["spotify"], - isrc=track_data["external_ids"].get("isrc"), ) def track_for_id(self, track_id=None, track_data=None): @@ -660,8 +658,9 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): self._log.debug("No track_id present for: {}", item) continue - popularity = self.track_popularity(spotify_track_id) - item["spotify_track_popularity"] = popularity + info = self.track_info(spotify_track_id) + item["spotify_track_popularity"] = info[0] + item["isrc"] = info[1] audio_features = self.track_audio_features(spotify_track_id) if audio_features is None: self._log.info("No audio features found for: {}", item) @@ -676,13 +675,16 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): if write: item.try_write() - def track_popularity(self, track_id=None): - """Fetch a track popularity by its Spotify ID.""" + def track_info(self, track_id=None): + """Fetch a track popularity and ISRC by its Spotify ID.""" track_data = self._handle_response( requests.get, self.track_url + track_id ) - self._log.debug("track_data: {}", track_data.get("popularity")) - return track_data.get("popularity") + self._log.debug("track_popularity: {} and track_isrc: {}", + track_data.get("popularity"), + track_data.get("external_ids").get("isrc")) + return [track_data.get("popularity"), + track_data.get("external_ids").get("isrc")] def track_audio_features(self, track_id=None): """Fetch track audio features by its Spotify ID.""" From 9e1c530c9d6457b9fa2542411273480e39926f84 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 12 Nov 2023 09:43:59 -0500 Subject: [PATCH 07/15] also include EAN and UPC --- beetsplug/spotify.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 85c39f5df..ad29bb3ad 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -661,6 +661,8 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): info = self.track_info(spotify_track_id) item["spotify_track_popularity"] = info[0] item["isrc"] = info[1] + item["ean"] = info[2] + item["upc"] = info[3] audio_features = self.track_audio_features(spotify_track_id) if audio_features is None: self._log.info("No audio features found for: {}", item) @@ -676,7 +678,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): item.try_write() def track_info(self, track_id=None): - """Fetch a track popularity and ISRC by its Spotify ID.""" + """Fetch a track popularity and other external_ids by its Spotify ID.""" track_data = self._handle_response( requests.get, self.track_url + track_id ) @@ -684,7 +686,9 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): track_data.get("popularity"), track_data.get("external_ids").get("isrc")) return [track_data.get("popularity"), - track_data.get("external_ids").get("isrc")] + track_data.get("external_ids").get("isrc"), + track_data.get("external_ids").get("ean"), + track_data.get("external_ids").get("upc")] def track_audio_features(self, track_id=None): """Fetch track audio features by its Spotify ID.""" From 33944d457be70ab3e1043304853b799febbbaed3 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 12 Nov 2023 09:45:29 -0500 Subject: [PATCH 08/15] formatting --- beetsplug/spotify.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index ad29bb3ad..729769d17 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -682,13 +682,17 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): track_data = self._handle_response( requests.get, self.track_url + track_id ) - self._log.debug("track_popularity: {} and track_isrc: {}", - track_data.get("popularity"), - track_data.get("external_ids").get("isrc")) - return [track_data.get("popularity"), - track_data.get("external_ids").get("isrc"), - track_data.get("external_ids").get("ean"), - track_data.get("external_ids").get("upc")] + self._log.debug( + "track_popularity: {} and track_isrc: {}", + track_data.get("popularity"), + track_data.get("external_ids").get("isrc"), + ) + return [ + track_data.get("popularity"), + track_data.get("external_ids").get("isrc"), + track_data.get("external_ids").get("ean"), + track_data.get("external_ids").get("upc"), + ] def track_audio_features(self, track_id=None): """Fetch track audio features by its Spotify ID.""" From c21e736811beb715f823c07c07ade43424650946 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Sun, 12 Nov 2023 09:46:48 -0500 Subject: [PATCH 09/15] Update changelog.rst --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 72578f918..8126ef133 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,7 +17,7 @@ Major new features: New features: -* :doc:`plugins/spotify`: We now fetch ISRC identifiers from Spotify. +* :doc:`plugins/spotify`: We now fetch ISRC, EAN, and UPC identifiers from Spotify. :bug:`4992` * :doc:`plugins/discogs`: supply a value for the `cover_art_url` attribute, for use by `fetchart`. :bug:`429` From f636167bd0ce3dceddae224c4524dedaa965d669 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Wed, 15 Nov 2023 10:13:56 -0500 Subject: [PATCH 10/15] Update docs/changelog.rst Co-authored-by: J0J0 Todos <2733783+JOJ0@users.noreply.github.com> --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8126ef133..1ff5b59c8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,7 +17,7 @@ Major new features: New features: -* :doc:`plugins/spotify`: We now fetch ISRC, EAN, and UPC identifiers from Spotify. +* :doc:`plugins/spotify`: We now fetch track's ISRC, EAN, and UPC identifiers from Spotify when using the ``spotifysync`` command. :bug:`4992` * :doc:`plugins/discogs`: supply a value for the `cover_art_url` attribute, for use by `fetchart`. :bug:`429` From c64df0d27ad0ef2cd67b1f77c91e2fb45e85332a Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Wed, 15 Nov 2023 10:21:42 -0500 Subject: [PATCH 11/15] Update beetsplug/spotify.py Co-authored-by: J0J0 Todos <2733783+JOJ0@users.noreply.github.com> --- beetsplug/spotify.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 729769d17..77e6b41c4 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -658,11 +658,11 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): self._log.debug("No track_id present for: {}", item) continue - info = self.track_info(spotify_track_id) - item["spotify_track_popularity"] = info[0] - item["isrc"] = info[1] - item["ean"] = info[2] - item["upc"] = info[3] + popularity, iscr, ean, upc = self.track_info(spotify_track_id) + item["spotify_track_popularity"] = popularity + item["isrc"] = isrc + item["ean"] = ean + item["upc"] = upc audio_features = self.track_audio_features(spotify_track_id) if audio_features is None: self._log.info("No audio features found for: {}", item) From 3b8cb98e6d89a93d09b96d0b05a563e79c303cb5 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Wed, 15 Nov 2023 10:21:53 -0500 Subject: [PATCH 12/15] Update beetsplug/spotify.py Co-authored-by: J0J0 Todos <2733783+JOJ0@users.noreply.github.com> --- beetsplug/spotify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 77e6b41c4..e4b269575 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -687,12 +687,12 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): track_data.get("popularity"), track_data.get("external_ids").get("isrc"), ) - return [ + return ( track_data.get("popularity"), track_data.get("external_ids").get("isrc"), track_data.get("external_ids").get("ean"), track_data.get("external_ids").get("upc"), - ] + ) def track_audio_features(self, track_id=None): """Fetch track audio features by its Spotify ID.""" From e2f83cdf77c3681baf271bd719a092cfe35cef15 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Wed, 15 Nov 2023 10:24:34 -0500 Subject: [PATCH 13/15] Fix typo --- beetsplug/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index e4b269575..4bb7832b5 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -658,7 +658,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): self._log.debug("No track_id present for: {}", item) continue - popularity, iscr, ean, upc = self.track_info(spotify_track_id) + popularity, isrc, ean, upc = self.track_info(spotify_track_id) item["spotify_track_popularity"] = popularity item["isrc"] = isrc item["ean"] = ean From 3b707b9276283bab821389504dcd75cbad0f0edf Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Wed, 15 Nov 2023 10:31:20 -0500 Subject: [PATCH 14/15] 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 4bb7832b5..b8279e631 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -678,7 +678,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): item.try_write() def track_info(self, track_id=None): - """Fetch a track popularity and other external_ids by its Spotify ID.""" + """Fetch track popularity and other external_ids using its Spotify ID.""" track_data = self._handle_response( requests.get, self.track_url + track_id ) From 138216a6bb5828d8baea9cd6bd64bc4452ad4557 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Thu, 16 Nov 2023 12:23:42 -0500 Subject: [PATCH 15/15] Update docstring --- beetsplug/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index b8279e631..705209de5 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -678,7 +678,7 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): item.try_write() def track_info(self, track_id=None): - """Fetch track popularity and other external_ids using its Spotify ID.""" + """Fetch a track's popularity and external IDs using its Spotify ID.""" track_data = self._handle_response( requests.get, self.track_url + track_id )