From c9c1123756ed233b01dd6619e6d548b036c9e1b4 Mon Sep 17 00:00:00 2001 From: J0J0 T Date: Tue, 1 Mar 2022 07:44:39 +0100 Subject: [PATCH 1/5] discogs: Fix discogs_albumid extraction Use extract_release_id_regex instead of extract_release_id to get the release ID out ouf the Discogs release URL. --- beetsplug/discogs.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 875842f83..820a0acbd 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -326,7 +326,7 @@ class DiscogsPlugin(BeetsPlugin): else: genre = base_genre - discogs_albumid = self.extract_release_id(result.data.get('uri')) + discogs_albumid = self.extract_release_id_regex(result.data.get('uri')) # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. @@ -378,12 +378,6 @@ class DiscogsPlugin(BeetsPlugin): else: return None - def extract_release_id(self, uri): - if uri: - return uri.split("/")[-1] - else: - return None - def get_tracks(self, tracklist): """Returns a list of TrackInfo objects for a discogs tracklist. """ From 76e81199b5c550f1270f3e8dd569e6d7fdc90df8 Mon Sep 17 00:00:00 2001 From: J0J0 T Date: Tue, 1 Mar 2022 08:43:03 +0100 Subject: [PATCH 2/5] discogs: Changelog entry for #4303 Fix discogs_albumid.. --- docs/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 633ddda24..f1833aad4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -16,6 +16,10 @@ New features: Bug fixes: +* The Discogs release ID is now populated correctly to the discogs_albumid + field again (it was no longer working after Discogs changed their release URL + format). + :bug:`4225` * The autotagger no longer considers all matches without a MusicBrainz ID as duplicates of each other. :bug:`4299` From b609047d6463cac69345d50d693be945ba87b27e Mon Sep 17 00:00:00 2001 From: J0J0 T Date: Wed, 2 Mar 2022 16:29:07 +0100 Subject: [PATCH 3/5] discogs: Add extract_release_id_regex sanity check Check whether any input worth pattern checking was passed. --- beetsplug/discogs.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 820a0acbd..30aa6d28d 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -194,16 +194,17 @@ class DiscogsPlugin(BeetsPlugin): # patterns. # Regex has been tested here https://regex101.com/r/wyLdB4/2 - for pattern in [ - r'^\[?r?(?P\d+)\]?$', - r'discogs\.com/release/(?P\d+)-', - r'discogs\.com/[^/]+/release/(?P\d+)', - ]: - match = re.search(pattern, album_id) - if match: - return int(match.group('id')) - - return None + if album_id: + for pattern in [ + r'^\[?r?(?P\d+)\]?$', + r'discogs\.com/release/(?P\d+)-', + r'discogs\.com/[^/]+/release/(?P\d+)', + ]: + match = re.search(pattern, album_id) + if match: + return int(match.group('id')) + else: + return None def album_for_id(self, album_id): """Fetches an album by its Discogs ID and returns an AlbumInfo object From c85f903caed5bfd74b45f94d48d6336d63c11f58 Mon Sep 17 00:00:00 2001 From: J0J0 T Date: Fri, 4 Mar 2022 08:02:29 +0100 Subject: [PATCH 4/5] Revert "discogs: Add extract_release_id_regex sanity check" This reverts commit c3cc055fdd3830bbe1c5470fe540684278a6ecc7. We assume the Discogs API never returns a release response without an URI. --- beetsplug/discogs.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 30aa6d28d..820a0acbd 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -194,17 +194,16 @@ class DiscogsPlugin(BeetsPlugin): # patterns. # Regex has been tested here https://regex101.com/r/wyLdB4/2 - if album_id: - for pattern in [ - r'^\[?r?(?P\d+)\]?$', - r'discogs\.com/release/(?P\d+)-', - r'discogs\.com/[^/]+/release/(?P\d+)', - ]: - match = re.search(pattern, album_id) - if match: - return int(match.group('id')) - else: - return None + for pattern in [ + r'^\[?r?(?P\d+)\]?$', + r'discogs\.com/release/(?P\d+)-', + r'discogs\.com/[^/]+/release/(?P\d+)', + ]: + match = re.search(pattern, album_id) + if match: + return int(match.group('id')) + + return None def album_for_id(self, album_id): """Fetches an album by its Discogs ID and returns an AlbumInfo object From b2f4834b76de7aa694319c2f4a10d0fa5062cd2c Mon Sep 17 00:00:00 2001 From: J0J0 T Date: Fri, 4 Mar 2022 07:46:15 +0100 Subject: [PATCH 5/5] discogs: Add URI to test_parse_minimal_release data --- test/test_discogs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_discogs.py b/test/test_discogs.py index d6825c978..c2aa7682c 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -337,6 +337,7 @@ class DGAlbumInfoTest(_common.TestCase): def test_parse_minimal_release(self): """Test parsing of a release with the minimal amount of information.""" data = {'id': 123, + 'uri': 'https://www.discogs.com/release/123456-something', 'tracklist': [self._make_track('A', '1', '01:01')], 'artists': [{'name': 'ARTIST NAME', 'id': 321, 'join': ''}], 'title': 'TITLE'}