mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Added leading zeros in track_number.Fixed issue #592
This commit is contained in:
@@ -20,7 +20,7 @@ def load_defaults():
|
||||
# so that we get same results even if YouTube changes the list/order of videos on their page.
|
||||
GIST_URL = "https://gist.githubusercontent.com/ritiek/e731338e9810e31c2f00f13c249a45f5/raw/c11a27f3b5d11a8d082976f1cdd237bd605ec2c2/search_results.html"
|
||||
|
||||
|
||||
def monkeypatch_youtube_search_page(*args, **kwargs):
|
||||
fake_urlopen = urllib.request.urlopen(GIST_URL)
|
||||
return fake_urlopen
|
||||
|
||||
|
||||
@@ -101,16 +101,28 @@ class TestDownload:
|
||||
|
||||
def test_m4a(self, monkeypatch, filename_fixture):
|
||||
expect_download = True
|
||||
monkeypatch.setattr("pafy.backend_shared.BaseStream.download", self.blank_audio_generator)
|
||||
monkeypatch.setattr("pafy.backend_youtube_dl.YtdlStream.download", self.blank_audio_generator)
|
||||
download = youtube_tools.download_song(filename_fixture + ".m4a", pytest.content_fixture)
|
||||
monkeypatch.setattr(
|
||||
"pafy.backend_shared.BaseStream.download", self.blank_audio_generator
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"pafy.backend_youtube_dl.YtdlStream.download", self.blank_audio_generator
|
||||
)
|
||||
download = youtube_tools.download_song(
|
||||
filename_fixture + ".m4a", pytest.content_fixture
|
||||
)
|
||||
assert download == expect_download
|
||||
|
||||
def test_webm(self, monkeypatch, filename_fixture):
|
||||
expect_download = True
|
||||
monkeypatch.setattr("pafy.backend_shared.BaseStream.download", self.blank_audio_generator)
|
||||
monkeypatch.setattr("pafy.backend_youtube_dl.YtdlStream.download", self.blank_audio_generator)
|
||||
download = youtube_tools.download_song(filename_fixture + ".webm", pytest.content_fixture)
|
||||
monkeypatch.setattr(
|
||||
"pafy.backend_shared.BaseStream.download", self.blank_audio_generator
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"pafy.backend_youtube_dl.YtdlStream.download", self.blank_audio_generator
|
||||
)
|
||||
download = youtube_tools.download_song(
|
||||
filename_fixture + ".webm", pytest.content_fixture
|
||||
)
|
||||
assert download == expect_download
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
pafy_patcher = patcher.PatchPafy()
|
||||
pafy_patcher.patch_getbestthumb()
|
||||
|
||||
|
||||
class TestPafyContentAvailable:
|
||||
pass
|
||||
|
||||
@@ -30,7 +31,6 @@ class TestMethodCalls:
|
||||
thumbnail = patcher._getbestthumb(content_fixture)
|
||||
assert thumbnail == "https://i.ytimg.com/vi/3nQNiWdeH2Q/sddefault.jpg"
|
||||
|
||||
|
||||
def test_pafy_content_available(self):
|
||||
TestPafyContentAvailable._content_available = patcher._content_available
|
||||
assert TestPafyContentAvailable()._content_available("https://youtube.com/")
|
||||
|
||||
@@ -104,19 +104,19 @@ def content_fixture(metadata_fixture):
|
||||
MATCH_METADATA_NO_FALLBACK_TEST_TABLE = [
|
||||
("https://open.spotify.com/track/5nWduGwBGBn1PSqYTJUDbS", True),
|
||||
("http://youtube.com/watch?v=3nQNiWdeH2Q", None),
|
||||
("Linux Talk | Working with Drives and Filesystems", None)
|
||||
("Linux Talk | Working with Drives and Filesystems", None),
|
||||
]
|
||||
|
||||
MATCH_METADATA_FALLBACK_TEST_TABLE = [
|
||||
("https://open.spotify.com/track/5nWduGwBGBn1PSqYTJUDbS", True),
|
||||
("http://youtube.com/watch?v=3nQNiWdeH2Q", False),
|
||||
("Linux Talk | Working with Drives and Filesystems", False)
|
||||
("Linux Talk | Working with Drives and Filesystems", False),
|
||||
]
|
||||
|
||||
MATCH_METADATA_NO_METADATA_TEST_TABLE = [
|
||||
("https://open.spotify.com/track/5nWduGwBGBn1PSqYTJUDbS", None),
|
||||
("http://youtube.com/watch?v=3nQNiWdeH2Q", None),
|
||||
("Linux Talk | Working with Drives and Filesystems", None)
|
||||
("Linux Talk | Working with Drives and Filesystems", None),
|
||||
]
|
||||
|
||||
|
||||
@@ -128,21 +128,37 @@ class TestMetadataOrigin:
|
||||
else:
|
||||
assert metadata["spotify_metadata"] == metadata_type
|
||||
|
||||
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_FALLBACK_TEST_TABLE)
|
||||
def test_match_metadata_with_no_fallback(self, track, metadata_type, content_fixture, monkeypatch):
|
||||
monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
|
||||
@pytest.mark.parametrize(
|
||||
"track, metadata_type", MATCH_METADATA_NO_FALLBACK_TEST_TABLE
|
||||
)
|
||||
def test_match_metadata_with_no_fallback(
|
||||
self, track, metadata_type, content_fixture, monkeypatch
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture
|
||||
)
|
||||
const.args.no_fallback_metadata = True
|
||||
self.match_metadata(track, metadata_type)
|
||||
|
||||
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_FALLBACK_TEST_TABLE)
|
||||
def test_match_metadata_with_fallback(self, track, metadata_type, content_fixture, monkeypatch):
|
||||
monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
|
||||
def test_match_metadata_with_fallback(
|
||||
self, track, metadata_type, content_fixture, monkeypatch
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture
|
||||
)
|
||||
const.args.no_fallback_metadata = False
|
||||
self.match_metadata(track, metadata_type)
|
||||
|
||||
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_METADATA_TEST_TABLE)
|
||||
def test_match_metadata_with_no_metadata(self, track, metadata_type, content_fixture, monkeypatch):
|
||||
monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
|
||||
@pytest.mark.parametrize(
|
||||
"track, metadata_type", MATCH_METADATA_NO_METADATA_TEST_TABLE
|
||||
)
|
||||
def test_match_metadata_with_no_metadata(
|
||||
self, track, metadata_type, content_fixture, monkeypatch
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture
|
||||
)
|
||||
const.args.no_metadata = True
|
||||
self.match_metadata(track, metadata_type)
|
||||
|
||||
@@ -185,7 +201,11 @@ def test_check_exists(metadata_fixture, filename_fixture, tmpdir):
|
||||
|
||||
|
||||
def test_generate_m3u(tmpdir, monkeypatch):
|
||||
monkeypatch.setattr(youtube_tools.GenerateYouTubeURL, "_fetch_response", loader.monkeypatch_youtube_search_page)
|
||||
monkeypatch.setattr(
|
||||
youtube_tools.GenerateYouTubeURL,
|
||||
"_fetch_response",
|
||||
loader.monkeypatch_youtube_search_page,
|
||||
)
|
||||
expect_m3u = (
|
||||
"#EXTM3U\n\n"
|
||||
"#EXTINF:208,Janji - Heroes Tonight (feat. Johnning) [NCS Release]\n"
|
||||
|
||||
Reference in New Issue
Block a user