From 4c4dfcc21fc139956bf045539837ed21f8df2f65 Mon Sep 17 00:00:00 2001 From: jbannon Date: Sat, 13 Aug 2022 08:04:00 +0000 Subject: [PATCH] potentially working --- src/ytdl_sub/utils/ffmpeg.py | 6 ++- tests/e2e/plugins/test_subtitles.py | 37 +++++++++++++++++++ .../plugins/test_subtitles_tags_chapters.json | 5 +++ .../plugins/test_subtitles_tags_chapters.txt | 21 +++++++++++ .../test_video_with_chapter_timestamps.txt | 5 +++ tests/e2e/youtube/test_video.py | 4 -- 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 tests/e2e/resources/expected_downloads_summaries/plugins/test_subtitles_tags_chapters.json create mode 100644 tests/e2e/resources/transaction_log_summaries/plugins/test_subtitles_tags_chapters.txt diff --git a/src/ytdl_sub/utils/ffmpeg.py b/src/ytdl_sub/utils/ffmpeg.py index a58ce064..affed520 100644 --- a/src/ytdl_sub/utils/ffmpeg.py +++ b/src/ytdl_sub/utils/ffmpeg.py @@ -122,7 +122,9 @@ def set_ffmpeg_metadata_chapters( file_path, "-i", metadata_file.name, - "-map_metadata", + "-map", + "0", + "-map_chapters", "1", "-bitexact", # for reproducibility "-codec", @@ -146,7 +148,7 @@ def add_ffmpeg_metadata_key_values(file_path: str, key_values: Dict[str, str]) - file_path_ext = file_path.split(".")[-1] output_file_path = f"{file_path}.out.{file_path_ext}" - ffmpeg_args = ["-i", file_path] + ffmpeg_args = ["-i", file_path, "-map", "0"] for key, value in key_values.items(): ffmpeg_args.extend(["-metadata", f"{key}={value}"]) ffmpeg_args.extend(["-codec", "copy", output_file_path]) diff --git a/tests/e2e/plugins/test_subtitles.py b/tests/e2e/plugins/test_subtitles.py index bea0cbe5..041855c6 100644 --- a/tests/e2e/plugins/test_subtitles.py +++ b/tests/e2e/plugins/test_subtitles.py @@ -1,3 +1,4 @@ +import mergedeep import pytest from e2e.expected_download import assert_expected_downloads from e2e.expected_transaction_log import assert_transaction_log_matches @@ -85,3 +86,39 @@ class TestSubtitles: dry_run=dry_run, expected_download_summary_file_name="plugins/test_subtitles_embedded_and_file.json", ) + + @pytest.mark.parametrize("dry_run", [True, False]) + def test_subtitles_chapters_tags_embedded( + self, + music_video_config, + timestamps_file_path, + single_video_subs_embed_preset_dict, + output_directory, + dry_run, + ): + # Test chapters and video tags in addition to subtitles + mergedeep.merge( + single_video_subs_embed_preset_dict, + { + "youtube": {"chapter_timestamps": timestamps_file_path}, + "video_tags": {"tags": {"title": "{title}"}}, + }, + ) + + subscription = Subscription.from_dict( + config=music_video_config, + preset_name="subtitles_embedded_test", + preset_dict=single_video_subs_embed_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_subtitles_tags_chapters.txt", + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=dry_run, + expected_download_summary_file_name="plugins/test_subtitles_tags_chapters.json", + ) diff --git a/tests/e2e/resources/expected_downloads_summaries/plugins/test_subtitles_tags_chapters.json b/tests/e2e/resources/expected_downloads_summaries/plugins/test_subtitles_tags_chapters.json new file mode 100644 index 00000000..f695f22d --- /dev/null +++ b/tests/e2e/resources/expected_downloads_summaries/plugins/test_subtitles_tags_chapters.json @@ -0,0 +1,5 @@ +{ + "JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind-thumb.jpg": "704246dd78074e8a0ec001dd8d03fd60", + "JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4": "e2e60d3e3ff7739d071aa953642980af", + "JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo": "ffa10f1cbc098ace7b1c7a8fbe3097a8" +} \ No newline at end of file diff --git a/tests/e2e/resources/transaction_log_summaries/plugins/test_subtitles_tags_chapters.txt b/tests/e2e/resources/transaction_log_summaries/plugins/test_subtitles_tags_chapters.txt new file mode 100644 index 00000000..250be877 --- /dev/null +++ b/tests/e2e/resources/transaction_log_summaries/plugins/test_subtitles_tags_chapters.txt @@ -0,0 +1,21 @@ +Files created in '{output_directory}' +---------------------------------------- +JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind-thumb.jpg +JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp4 + Chapters embedded into the video: + 0:00: Intro + 0:10: Part 1 + 0:20: Part 2 + 0:30: Part 3 + 0:40: Part 4 + 1:01: Part 5 + Embedded subtitles with lang(s) en, de + Video Tags: + title: YouTube Rewind 2019: For the Record | #YouTubeRewind +JMC - YouTube Rewind 2019: For the Record | #YouTubeRewind.nfo + NFO tags: + musicvideo: + album: Music Videos + artist: JMC + title: YouTube Rewind 2019: For the Record | #YouTubeRewind + year: 2019 \ No newline at end of file diff --git a/tests/e2e/resources/transaction_log_summaries/youtube/test_video_with_chapter_timestamps.txt b/tests/e2e/resources/transaction_log_summaries/youtube/test_video_with_chapter_timestamps.txt index d329bbb9..ce6e41e2 100644 --- a/tests/e2e/resources/transaction_log_summaries/youtube/test_video_with_chapter_timestamps.txt +++ b/tests/e2e/resources/transaction_log_summaries/youtube/test_video_with_chapter_timestamps.txt @@ -9,6 +9,11 @@ JMC - Oblivion Mod "Falcor" p.1.mp4 0:30: Part 3 0:40: Part 4 1:01: Part 5 + Video Tags: + description: + 🎸 / ' " + newline? + title: Oblivion Mod "Falcor" p.1 JMC - Oblivion Mod "Falcor" p.1.nfo NFO tags: musicvideo: diff --git a/tests/e2e/youtube/test_video.py b/tests/e2e/youtube/test_video.py index e12bb448..77dba7ef 100644 --- a/tests/e2e/youtube/test_video.py +++ b/tests/e2e/youtube/test_video.py @@ -53,13 +53,11 @@ class TestYoutubeVideo: output_directory=output_directory, transaction_log=transaction_log, transaction_log_summary_file_name="youtube/test_video.txt", - regenerate_transaction_log=True, ) assert_expected_downloads( output_directory=output_directory, dry_run=dry_run, expected_download_summary_file_name="youtube/test_video.json", - regenerate_expected_download_summary=True, ) @pytest.mark.parametrize("dry_run", [True, False]) @@ -113,11 +111,9 @@ class TestYoutubeVideo: output_directory=output_directory, transaction_log=transaction_log, transaction_log_summary_file_name="youtube/test_video_with_chapter_timestamps.txt", - regenerate_transaction_log=True, ) assert_expected_downloads( output_directory=output_directory, dry_run=dry_run, expected_download_summary_file_name="youtube/test_video_with_chapter_timestamps.json", - regenerate_expected_download_summary=True, )