diff --git a/beets/util/id_extractors.py b/beets/util/id_extractors.py index 7e3de0de4..9718447ff 100644 --- a/beets/util/id_extractors.py +++ b/beets/util/id_extractors.py @@ -10,7 +10,11 @@ log = logging.getLogger("beets") PATTERN_BY_SOURCE = { - "spotify": re.compile(r"(?:^|open\.spotify\.com/[^/]+/)([0-9A-Za-z]{22})"), + # Accepts the raw ID, open.spotify.com URLs, and native URIs. + # (ex.: "spotify:album:", "spotify:track:"). + "spotify": re.compile( + r"(?:^|open\.spotify\.com/[^/]+/|spotify:[a-z]+:)([0-9A-Za-z]{22})" + ), "deezer": re.compile(r"(?:^|deezer\.com/)(?:[a-z]*/)?(?:[^/]+/)?(\d+)"), "beatport": re.compile(r"(?:^|beatport\.com/release/.+/)(\d+)$"), "musicbrainz": re.compile(r"(\w{8}(?:-\w{4}){3}-\w{12})"), diff --git a/docs/changelog.rst b/docs/changelog.rst index a900c9015..e8bc4f653 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,9 @@ Unreleased New features ~~~~~~~~~~~~ +- :doc:`plugins/spotify`: Recognize native Spotify URIs (e.g. + ``spotify:album:`` and ``spotify:track:``) when extracting + release/track IDs, in addition to full ``open.spotify.com`` URLs and bare IDs - :doc:`/plugins/convert`: Add new configuration option ``convert.refresh`` and command-line option ``--refresh``, allowing to force ``convert`` operation when original file is newer than existing converted file. diff --git a/test/util/test_id_extractors.py b/test/util/test_id_extractors.py index 07571c1ef..128f95ce6 100644 --- a/test/util/test_id_extractors.py +++ b/test/util/test_id_extractors.py @@ -11,6 +11,8 @@ from beets.util.id_extractors import extract_release_id ("spotify", "39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), ("spotify", "blah blah", None), ("spotify", "https://open.spotify.com/album/39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), + ("spotify", "spotify:album:39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), + ("spotify", "spotify:track:39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), ("deezer", "176356382", "176356382"), ("deezer", "blah blah", None), ("deezer", "https://www.deezer.com/album/176356382", "176356382"),