| 1 |
from typing import NamedTuple |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from beets.util.id_extractors import extract_release_id |
| 6 |
|
| 7 |
|
| 8 |
@pytest.mark.parametrize( |
| 9 |
"source, id_string, expected", |
| 10 |
[ |
| 11 |
("spotify", "39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), |
| 12 |
("spotify", "blah blah", None), |
| 13 |
("spotify", "https://open.spotify.com/album/39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), |
| 14 |
("spotify", "spotify:album:39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), |
| 15 |
("spotify", "spotify:track:39WqpoPgZxygo6YQjehLJJ", "39WqpoPgZxygo6YQjehLJJ"), |
| 16 |
("deezer", "176356382", "176356382"), |
| 17 |
("deezer", "blah blah", None), |
| 18 |
("deezer", "https://www.deezer.com/album/176356382", "176356382"), |
| 19 |
("beatport", "3089651", "3089651"), |
| 20 |
("beatport", "blah blah", None), |
| 21 |
("beatport", "https://www.beatport.com/release/album-name/3089651", "3089651"), |
| 22 |
("discogs", "http://www.discogs.com/G%C3%BCnther-Lause-Meru-Ep/release/4354798", "4354798"), |
| 23 |
("discogs", "http://www.discogs.com/release/4354798-G%C3%BCnther-Lause-Meru-Ep", "4354798"), |
| 24 |
("discogs", "http://www.discogs.com/G%C3%BCnther-4354798Lause-Meru-Ep/release/4354798", "4354798"), |
| 25 |
("discogs", "http://www.discogs.com/release/4354798-G%C3%BCnther-4354798Lause-Meru-Ep/", "4354798"), |
| 26 |
("discogs", "[r4354798]", "4354798"), |
| 27 |
("discogs", "r4354798", "4354798"), |
| 28 |
("discogs", "4354798", "4354798"), |
| 29 |
("discogs", "yet-another-metadata-provider.org/foo/12345", None), |
| 30 |
("discogs", "005b84a0-ecd6-39f1-b2f6-6eb48756b268", None), |
| 31 |
("musicbrainz", "28e32c71-1450-463e-92bf-e0a46446fc11", "28e32c71-1450-463e-92bf-e0a46446fc11"), |
| 32 |
("musicbrainz", "blah blah", None), |
| 33 |
("musicbrainz", "https://musicbrainz.org/entity/28e32c71-1450-463e-92bf-e0a46446fc11", "28e32c71-1450-463e-92bf-e0a46446fc11"), |
| 34 |
("bandcamp", "https://nameofartist.bandcamp.com/album/nameofalbum", "https://nameofartist.bandcamp.com/album/nameofalbum"), |
| 35 |
("tidal", "https://tidal.com/browse/album/76699758", "76699758"), |
| 36 |
("tidal", "https://tidal.com/track/463928643/u", "463928643"), |
| 37 |
("tidal", "blah blah", None), |
| 38 |
], |
| 39 |
) # fmt: skip |
| 40 |
def test_extract_release_id(source, id_string, expected): |
| 41 |
assert extract_release_id(source, id_string) == expected |
| 42 |
|
| 43 |
|
| 44 |
class SourceWithURL(NamedTuple): |
| 45 |
source: str |
| 46 |
url: str |
| 47 |
|
| 48 |
|
| 49 |
source_with_urls = [ |
| 50 |
SourceWithURL("spotify", "https://open.spotify.com/album/39WqpoPgZxygo6YQjehLJJ"), |
| 51 |
SourceWithURL("deezer", "https://www.deezer.com/album/176356382"), |
| 52 |
SourceWithURL("beatport", "https://www.beatport.com/release/album-name/3089651"), |
| 53 |
SourceWithURL("discogs", "http://www.discogs.com/G%C3%BCnther-Lause-Meru-Ep/release/4354798"), |
| 54 |
SourceWithURL("musicbrainz", "https://musicbrainz.org/entity/28e32c71-1450-463e-92bf-e0a46446fc11"), |
| 55 |
SourceWithURL("tidal", "https://tidal.com/track/463928643"), |
| 56 |
] # fmt: skip |
| 57 |
|
| 58 |
|
| 59 |
@pytest.mark.parametrize("source", [s.source for s in source_with_urls]) |
| 60 |
@pytest.mark.parametrize("source_with_url", source_with_urls) |
| 61 |
def test_match_source_url(source, source_with_url): |
| 62 |
if source == source_with_url.source: |
| 63 |
assert extract_release_id(source, source_with_url.url) |
| 64 |
else: |
| 65 |
assert not extract_release_id(source, source_with_url.url), ( |
| 66 |
f"Source {source} pattern should not match {source_with_url.source} URL" |
| 67 |
) |