mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Re-add test for m3u files (removed accidently in #448)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from spotdl import const
|
from spotdl import const
|
||||||
from spotdl import handle
|
from spotdl import handle
|
||||||
from spotdl import spotdl
|
from spotdl import spotdl
|
||||||
|
import urllib
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -13,3 +14,13 @@ def load_defaults():
|
|||||||
spotdl.log = const.logzero.setup_logger(
|
spotdl.log = const.logzero.setup_logger(
|
||||||
formatter=const._formatter, level=const.args.log_level
|
formatter=const._formatter, level=const.args.log_level
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# GIST_URL is the monkeypatched version of: https://www.youtube.com/results?search_query=janji+-+heroes
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import urllib
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -54,16 +53,11 @@ class TestFileFormat:
|
|||||||
assert title == EXPECTED_SPOTIFY_TITLE.replace(" ", "_")
|
assert title == EXPECTED_SPOTIFY_TITLE.replace(" ", "_")
|
||||||
|
|
||||||
|
|
||||||
def monkeypatch_youtube_search_page(*args, **kwargs):
|
|
||||||
fake_urlopen = urllib.request.urlopen(GIST_URL)
|
|
||||||
return fake_urlopen
|
|
||||||
|
|
||||||
|
|
||||||
def test_youtube_url(metadata_fixture, monkeypatch):
|
def test_youtube_url(metadata_fixture, monkeypatch):
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
youtube_tools.GenerateYouTubeURL,
|
youtube_tools.GenerateYouTubeURL,
|
||||||
"_fetch_response",
|
"_fetch_response",
|
||||||
monkeypatch_youtube_search_page,
|
loader.monkeypatch_youtube_search_page,
|
||||||
)
|
)
|
||||||
url = youtube_tools.generate_youtube_url(SPOTIFY_TRACK_URL, metadata_fixture)
|
url = youtube_tools.generate_youtube_url(SPOTIFY_TRACK_URL, metadata_fixture)
|
||||||
assert url == EXPECTED_YOUTUBE_URL
|
assert url == EXPECTED_YOUTUBE_URL
|
||||||
@@ -73,7 +67,7 @@ def test_youtube_title(metadata_fixture, monkeypatch):
|
|||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
youtube_tools.GenerateYouTubeURL,
|
youtube_tools.GenerateYouTubeURL,
|
||||||
"_fetch_response",
|
"_fetch_response",
|
||||||
monkeypatch_youtube_search_page,
|
loader.monkeypatch_youtube_search_page,
|
||||||
)
|
)
|
||||||
content = youtube_tools.go_pafy(SPOTIFY_TRACK_URL, metadata_fixture)
|
content = youtube_tools.go_pafy(SPOTIFY_TRACK_URL, metadata_fixture)
|
||||||
pytest.content_fixture = content
|
pytest.content_fixture = content
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ YT_API_KEY = "AIzaSyAnItl3udec-Q1d5bkjKJGL-RgrKO_vU90"
|
|||||||
TRACK_SEARCH = "Tony's Videos VERY SHORT VIDEO 28.10.2016"
|
TRACK_SEARCH = "Tony's Videos VERY SHORT VIDEO 28.10.2016"
|
||||||
EXPECTED_TITLE = TRACK_SEARCH
|
EXPECTED_TITLE = TRACK_SEARCH
|
||||||
EXPECTED_YT_URL = "http://youtube.com/watch?v=qOOcy2-tmbk"
|
EXPECTED_YT_URL = "http://youtube.com/watch?v=qOOcy2-tmbk"
|
||||||
EXPECTED_YT_URLS = (EXPECTED_YT_URL, "http://youtube.com/watch?v=5USR1Omo7f0")
|
|
||||||
|
|
||||||
RESULT_COUNT_SEARCH = "she is still sleeping SAO"
|
RESULT_COUNT_SEARCH = "she is still sleeping SAO"
|
||||||
|
|
||||||
@@ -71,8 +70,7 @@ class TestYouTubeURL:
|
|||||||
def test_only_music_category(self, metadata_fixture):
|
def test_only_music_category(self, metadata_fixture):
|
||||||
const.args.music_videos_only = True
|
const.args.music_videos_only = True
|
||||||
url = youtube_tools.generate_youtube_url(TRACK_SEARCH, metadata_fixture)
|
url = youtube_tools.generate_youtube_url(TRACK_SEARCH, metadata_fixture)
|
||||||
# YouTube keeps changing its results
|
assert url == EXPECTED_YT_URL
|
||||||
assert url in EXPECTED_YT_URLS
|
|
||||||
|
|
||||||
def test_all_categories(self, metadata_fixture):
|
def test_all_categories(self, metadata_fixture):
|
||||||
const.args.music_videos_only = False
|
const.args.music_videos_only = False
|
||||||
@@ -131,19 +129,19 @@ class TestMetadataOrigin:
|
|||||||
assert metadata["spotify_metadata"] == metadata_type
|
assert metadata["spotify_metadata"] == metadata_type
|
||||||
|
|
||||||
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_FALLBACK_TEST_TABLE)
|
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_FALLBACK_TEST_TABLE)
|
||||||
def test_match_metadata_with_no_fallback(self, track, metadata_type, monkeypatch, content_fixture):
|
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)
|
monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
|
||||||
const.args.no_fallback_metadata = True
|
const.args.no_fallback_metadata = True
|
||||||
self.match_metadata(track, metadata_type)
|
self.match_metadata(track, metadata_type)
|
||||||
|
|
||||||
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_FALLBACK_TEST_TABLE)
|
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_FALLBACK_TEST_TABLE)
|
||||||
def test_match_metadata_with_fallback(self, track, metadata_type, monkeypatch, 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)
|
monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
|
||||||
const.args.no_fallback_metadata = False
|
const.args.no_fallback_metadata = False
|
||||||
self.match_metadata(track, metadata_type)
|
self.match_metadata(track, metadata_type)
|
||||||
|
|
||||||
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_METADATA_TEST_TABLE)
|
@pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_METADATA_TEST_TABLE)
|
||||||
def test_match_metadata_with_no_metadata(self, track, metadata_type, monkeypatch, content_fixture):
|
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)
|
monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
|
||||||
const.args.no_metadata = True
|
const.args.no_metadata = True
|
||||||
self.match_metadata(track, metadata_type)
|
self.match_metadata(track, metadata_type)
|
||||||
@@ -186,6 +184,26 @@ def test_check_exists(metadata_fixture, filename_fixture, tmpdir):
|
|||||||
assert check == expect_check
|
assert check == expect_check
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_m3u(tmpdir, monkeypatch):
|
||||||
|
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"
|
||||||
|
"http://www.youtube.com/watch?v=3nQNiWdeH2Q\n"
|
||||||
|
"#EXTINF:226,Alan Walker - Spectre [NCS Release]\n"
|
||||||
|
"http://www.youtube.com/watch?v=AOeY-nDp7hI\n"
|
||||||
|
)
|
||||||
|
m3u_track_file = os.path.join(str(tmpdir), "m3u_test.txt")
|
||||||
|
with open(m3u_track_file, "w") as track_file:
|
||||||
|
track_file.write("\nhttps://open.spotify.com/track/3SipFlNddvL0XNZRLXvdZD")
|
||||||
|
track_file.write("\nhttp://www.youtube.com/watch?v=AOeY-nDp7hI")
|
||||||
|
youtube_tools.generate_m3u(m3u_track_file)
|
||||||
|
m3u_file = "{}.m3u".format(m3u_track_file.split(".")[0])
|
||||||
|
with open(m3u_file, "r") as m3u_in:
|
||||||
|
m3u = m3u_in.readlines()
|
||||||
|
assert "".join(m3u) == expect_m3u
|
||||||
|
|
||||||
|
|
||||||
class TestDownload:
|
class TestDownload:
|
||||||
def test_webm(self, content_fixture, filename_fixture, monkeypatch):
|
def test_webm(self, content_fixture, filename_fixture, monkeypatch):
|
||||||
# content_fixture does not have any .webm audiostream
|
# content_fixture does not have any .webm audiostream
|
||||||
|
|||||||
Reference in New Issue
Block a user