From 3098a96f31baeb65c56983cef9faa32dace5906a Mon Sep 17 00:00:00 2001 From: jbannon Date: Sun, 14 Aug 2022 07:14:19 +0000 Subject: [PATCH] playlists working, need to fix retry --- examples/youtube_extract_and_tag_audio.yaml | 12 ++++- src/ytdl_sub/downloaders/downloader.py | 2 +- src/ytdl_sub/downloaders/youtube/playlist.py | 1 - tests/e2e/plugins/test_audio_extract.py | 48 +++++++++++++++++++ .../plugins/test_audio_extract_playlist.json | 5 ++ .../plugins/test_audio_extract_playlist.txt | 29 +++++++++++ 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_playlist.json create mode 100644 tests/e2e/resources/transaction_log_summaries/plugins/test_audio_extract_playlist.txt diff --git a/examples/youtube_extract_and_tag_audio.yaml b/examples/youtube_extract_and_tag_audio.yaml index 000dd7ac..8c004fd1 100644 --- a/examples/youtube_extract_and_tag_audio.yaml +++ b/examples/youtube_extract_and_tag_audio.yaml @@ -1,3 +1,4 @@ +# TODO: add comments explaining stuff configuration: working_directory: '.ytdl-sub-downloads' @@ -25,4 +26,13 @@ presets: genre: "Unset" overrides: - music_directory: "/path/to/music" \ No newline at end of file + music_directory: "/path/to/music" + + yt_song_playlist: + preset: yt_song + youtube: + download_strategy: "playlist" + + music_tags: + tags: + track: "{playlist_index}" \ No newline at end of file diff --git a/src/ytdl_sub/downloaders/downloader.py b/src/ytdl_sub/downloaders/downloader.py index e8a872a9..ae808f95 100644 --- a/src/ytdl_sub/downloaders/downloader.py +++ b/src/ytdl_sub/downloaders/downloader.py @@ -132,7 +132,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT] def extract_info_with_retry( self, - is_downloaded_fn: Optional[Callable[[], bool]], + is_downloaded_fn: Optional[Callable[[], bool]] = None, ytdl_options_overrides: Optional[Dict] = None, **kwargs, ) -> Dict: diff --git a/src/ytdl_sub/downloaders/youtube/playlist.py b/src/ytdl_sub/downloaders/youtube/playlist.py index b6edf69c..3b89545b 100644 --- a/src/ytdl_sub/downloaders/youtube/playlist.py +++ b/src/ytdl_sub/downloaders/youtube/playlist.py @@ -92,7 +92,6 @@ class YoutubePlaylistDownloader( # Re-download the contents even if it's a dry-run as a single video. At this time, # playlists do not download subtitles or subtitle metadata as_single_video_dict = self.extract_info_with_retry( - is_downloaded_fn=None if self.is_dry_run else video.is_downloaded, ytdl_options_overrides={"writeinfojson": False, "skip_download": self.is_dry_run}, url=video.kwargs("webpage_url"), ) diff --git a/tests/e2e/plugins/test_audio_extract.py b/tests/e2e/plugins/test_audio_extract.py index 0ea127e4..28f8891a 100644 --- a/tests/e2e/plugins/test_audio_extract.py +++ b/tests/e2e/plugins/test_audio_extract.py @@ -12,6 +12,26 @@ def single_song_preset_dict(output_directory): "preset": "yt_song", "youtube": {"video_url": "https://www.youtube.com/watch?v=2lAe1cqCOXo"}, "output_options": {"output_directory": output_directory}, + # download the worst format so it is fast + "ytdl_options": { + "format": "worst[ext=mp4]", + }, + } + +@pytest.fixture +def multiple_songs_preset_dict(output_directory): + return { + "preset": "yt_song_playlist", + "youtube": {"playlist_url": "https://youtube.com/playlist?list=PL5BC0FC26BECA5A35"}, + "output_options": {"output_directory": output_directory}, + "audio_extract": { + "codec": "vorbis", + "quality": 140 + }, + # download the worst format so it is fast + "ytdl_options": { + "format": "worst[ext=mp4]", + }, } @@ -43,3 +63,31 @@ class TestAudioExtract: expected_download_summary_file_name="plugins/test_audio_extract_single.json", regenerate_expected_download_summary=True, ) + + @pytest.mark.parametrize("dry_run", [True, False]) + def test_audio_extract_multiple_songs( + self, + youtube_audio_config, + multiple_songs_preset_dict, + output_directory, + dry_run, + ): + subscription = Subscription.from_dict( + config=youtube_audio_config, + preset_name="multiple_songs_test", + preset_dict=multiple_songs_preset_dict, + ) + + transaction_log = subscription.download(dry_run=dry_run) + assert_transaction_log_matches( + output_directory=output_directory, + transaction_log=transaction_log, + transaction_log_summary_file_name="plugins/test_audio_extract_playlist.txt", + regenerate_transaction_log=True, + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=dry_run, + expected_download_summary_file_name="plugins/test_audio_extract_playlist.json", + regenerate_expected_download_summary=True, + ) \ No newline at end of file diff --git a/tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_playlist.json b/tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_playlist.json new file mode 100644 index 00000000..cef2bc8e --- /dev/null +++ b/tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_playlist.json @@ -0,0 +1,5 @@ +{ + "Jesse's Minecraft Server [Trailer - Feb.1].ogg": "3f701a4b2437704bc443cf07c9832dae", + "Jesse's Minecraft Server [Trailer - Feb.27].ogg": "430d1c8ec20573a73e2149c10c9c741f", + "Jesse's Minecraft Server [Trailer - Mar.21].ogg": "11742c96e9ea3a520b2411d8b3516472" +} \ No newline at end of file diff --git a/tests/e2e/resources/transaction_log_summaries/plugins/test_audio_extract_playlist.txt b/tests/e2e/resources/transaction_log_summaries/plugins/test_audio_extract_playlist.txt new file mode 100644 index 00000000..b02d60ac --- /dev/null +++ b/tests/e2e/resources/transaction_log_summaries/plugins/test_audio_extract_playlist.txt @@ -0,0 +1,29 @@ +Files created in '{output_directory}' +---------------------------------------- +Jesse's Minecraft Server [Trailer - Feb.1].ogg + Music Tags: + album: Singles + albumartist: Project Zombie + artist: Project Zombie + genre: Unset + title: Jesse's Minecraft Server [Trailer - Feb.1] + track: 3 + year: 2011 +Jesse's Minecraft Server [Trailer - Feb.27].ogg + Music Tags: + album: Singles + albumartist: Project Zombie + artist: Project Zombie + genre: Unset + title: Jesse's Minecraft Server [Trailer - Feb.27] + track: 2 + year: 2011 +Jesse's Minecraft Server [Trailer - Mar.21].ogg + Music Tags: + album: Singles + albumartist: Project Zombie + artist: Project Zombie + genre: Unset + title: Jesse's Minecraft Server [Trailer - Mar.21] + track: 1 + year: 2011 \ No newline at end of file