diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 31e7ac51..c50773ff 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -57,6 +57,7 @@ def mock_entry_dict_factory(mock_downloaded_file_path) -> Callable: entry_dict = { v.uid.metadata_key: uid, v.epoch.metadata_key: 1596878400, + v.duration.metadata_key: 42 if is_extracted_audio else 31, v.playlist_title.metadata_key: playlist_title, v.playlist_index.metadata_key: playlist_index, v.playlist_count.metadata_key: playlist_count, diff --git a/tests/integration/plugins/conftest.py b/tests/integration/plugins/conftest.py new file mode 100644 index 00000000..48ac4a3f --- /dev/null +++ b/tests/integration/plugins/conftest.py @@ -0,0 +1,21 @@ +import tempfile +from unittest.mock import patch + +import pytest + +from ytdl_sub.utils.chapters import Chapters + + +@pytest.fixture +def mock_chapters_class(): + with patch.object(Chapters, "from_empty") as mock_chapters: + mock_chapters.return_value = Chapters.from_string( + """ + "0:00 Intro\n", + "00:07 Part 1\n", + "0:13 Part 2\n", + "00:19 Part 3\n", + """ + ) + + yield diff --git a/tests/integration/plugins/test_chapters.py b/tests/integration/plugins/test_chapters.py index 8ba3f00a..c0d80ca2 100644 --- a/tests/integration/plugins/test_chapters.py +++ b/tests/integration/plugins/test_chapters.py @@ -1,33 +1,20 @@ from typing import Dict import pytest +from expected_download import assert_expected_downloads +from expected_transaction_log import assert_transaction_log_matches +from integration.plugins.conftest import mock_chapters_class +from mergedeep import mergedeep from ytdl_sub.entries.entry import ytdl_sub_chapters_from_comments from ytdl_sub.subscriptions.subscription import Subscription @pytest.fixture -def sponsorblock_disabled_dict(output_directory) -> Dict: +def chapters_base_subscription_dict(output_directory) -> Dict: return { "preset": "Jellyfin Music Videos", "output_options": {"output_directory": output_directory}, - "chapters": { - "enable": "{enable_sponsorblock}", - "sponsorblock_categories": [ - "outro", - "selfpromo", - "preview", - "interaction", - "sponsor", - "music_offtopic", - "intro", - ], - "remove_sponsorblock_categories": "all", - "remove_chapters_regex": [ - "Intro", - "Outro", - ], - }, "overrides": { "music_video_artist": "JMC", "url": "https://your.name.here", @@ -36,6 +23,50 @@ def sponsorblock_disabled_dict(output_directory) -> Dict: } +@pytest.fixture +def sponsorblock_disabled_dict(chapters_base_subscription_dict) -> Dict: + mergedeep.merge( + chapters_base_subscription_dict, + { + "chapters": { + "enable": "{enable_sponsorblock}", + "sponsorblock_categories": [ + "outro", + "selfpromo", + "preview", + "interaction", + "sponsor", + "music_offtopic", + "intro", + ], + "remove_sponsorblock_categories": "all", + "remove_chapters_regex": [ + "Intro", + "Outro", + ], + }, + "overrides": { + "enable_sponsorblock": "False", + }, + }, + ) + return chapters_base_subscription_dict + + +@pytest.fixture +def chapters_from_comments_subscription_dict(chapters_base_subscription_dict) -> Dict: + mergedeep.merge( + chapters_base_subscription_dict, + { + "chapters": { + "embed_chapters": True, + "allow_chapters_from_comments": True, + }, + }, + ) + return chapters_base_subscription_dict + + class TestChapters: def test_chapters_disabled_respected( self, @@ -58,3 +89,36 @@ class TestChapters: script = subscription.overrides.script assert script.get(ytdl_sub_chapters_from_comments.variable_name).native == "" + + @pytest.mark.usefixtures(mock_chapters_class.__name__) + @pytest.mark.parametrize("dry_run", [True, False]) + def test_chapters_from_comments( + self, + config, + subscription_name, + chapters_from_comments_subscription_dict, + mock_download_collection_entries, + output_directory, + dry_run, + ): + subscription = Subscription.from_dict( + config=config, + preset_name=subscription_name, + preset_dict=chapters_from_comments_subscription_dict, + ) + + with mock_download_collection_entries( + is_youtube_channel=False, num_urls=1, is_dry_run=dry_run + ): + 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/chapters/test_chapters_from_comments.txt", + ) + assert_expected_downloads( + output_directory=output_directory, + dry_run=dry_run, + expected_download_summary_file_name="plugins/chapters/test_chapters_from_comments.json", + ) diff --git a/tests/resources/expected_downloads_summaries/plugins/chapters/test_chapters_from_comments.json b/tests/resources/expected_downloads_summaries/plugins/chapters/test_chapters_from_comments.json index d7ca529e..1c1792d3 100644 --- a/tests/resources/expected_downloads_summaries/plugins/chapters/test_chapters_from_comments.json +++ b/tests/resources/expected_downloads_summaries/plugins/chapters/test_chapters_from_comments.json @@ -1,7 +1,19 @@ { - ".ytdl-sub-chapters_from_comments-download-archive.json": "70bc3bb62af3a344b0256e1d3b98dcb0", - "JMC/Move 78 - Automated Improvisation [Full Album].info.json": "INFO_JSON", - "JMC/Move 78 - Automated Improvisation [Full Album].jpg": "c12e6a6f242680d1096a1a99d74a62c6", - "JMC/Move 78 - Automated Improvisation [Full Album].mp4": "fbe825bf5fb8ce193d47c3da3540e815", - "JMC/Move 78 - Automated Improvisation [Full Album].nfo": "039268e97673a6f2b391772ec3b52fac" + ".ytdl-sub-subscription_test-download-archive.json": "76e202bd03ceef93daaffffee2cfa193", + "JMC/Mock Entry 20-1.info.json": "INFO_JSON", + "JMC/Mock Entry 20-1.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "JMC/Mock Entry 20-1.mp4": "40efe3f597c40c11d0d3f2f87cc7650b", + "JMC/Mock Entry 20-1.nfo": "fefcf0b3e4f4ff80ad636584d50dadec", + "JMC/Mock Entry 20-2.info.json": "INFO_JSON", + "JMC/Mock Entry 20-2.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "JMC/Mock Entry 20-2.mp4": "0747f56d03e720128b1fa5ef25bcf3c8", + "JMC/Mock Entry 20-2.nfo": "025c0b631da5ff5470382b38fce78d2d", + "JMC/Mock Entry 20-3.info.json": "INFO_JSON", + "JMC/Mock Entry 20-3.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "JMC/Mock Entry 20-3.mp4": "eb776b8e6da77a848666d88623600fd6", + "JMC/Mock Entry 20-3.nfo": "618b0ff948d9de2e10cf1da8c0dd6615", + "JMC/Mock Entry 21-1.info.json": "INFO_JSON", + "JMC/Mock Entry 21-1.jpg": "e80c508c4818454300133fe1dc1a9cd7", + "JMC/Mock Entry 21-1.mp4": "5d56530dc8a4cfe55efb791d82bae0f0", + "JMC/Mock Entry 21-1.nfo": "e5c715749efc1603a6e2f59244d87aba" } \ No newline at end of file diff --git a/tests/resources/transaction_log_summaries/plugins/chapters/test_chapters_from_comments.txt b/tests/resources/transaction_log_summaries/plugins/chapters/test_chapters_from_comments.txt index 40f060d6..a0f1171b 100644 --- a/tests/resources/transaction_log_summaries/plugins/chapters/test_chapters_from_comments.txt +++ b/tests/resources/transaction_log_summaries/plugins/chapters/test_chapters_from_comments.txt @@ -1,34 +1,97 @@ Files created: ---------------------------------------- {output_directory} - .ytdl-sub-chapters_from_comments-download-archive.json + .ytdl-sub-subscription_test-download-archive.json {output_directory}/JMC - Move 78 - Automated Improvisation [Full Album].info.json - Move 78 - Automated Improvisation [Full Album].jpg - Move 78 - Automated Improvisation [Full Album].mp4 + Mock Entry 20-1.info.json + Mock Entry 20-1.jpg + Mock Entry 20-1.mp4 Chapters from comments: - 0:00: 01. The Lonely Tears of Lee Seedol - 4:30: 02. But What If We're Wrong - 9:16: 03. Follow the Earworm Pt.2 - 12:25: 04. Keyword Salad - 16:48: 05. Ultra Natural - 20:47: 06. Flight Instructions - 25:46: 07. Dawn of the Useless Class - 29:58: 08. Schnitzel Whisperer - 32:16: 09. Teilo - Embedded subtitles with lang(s) en, de + 0:00: " Intro + 0:07: " Part 1 + 0:13: " Part 2 + 0:19: " Part 3 Video Tags: album: Music Videos artist: JMC genre: ytdl-sub - premiered: 2022-11-21 - title: Move 78 - Automated Improvisation [Full Album] - year: 2022 - Move 78 - Automated Improvisation [Full Album].nfo + premiered: 2020-08-08 + title: Mock Entry 20-1 + year: 2020 + Mock Entry 20-1.nfo NFO tags: musicvideo: album: Music Videos artist: JMC genre: ytdl-sub - premiered: 2022-11-21 - title: Move 78 - Automated Improvisation [Full Album] \ No newline at end of file + premiered: 2020-08-08 + title: Mock Entry 20-1 + Mock Entry 20-2.info.json + Mock Entry 20-2.jpg + Mock Entry 20-2.mp4 + Chapters from comments: + 0:00: " Intro + 0:07: " Part 1 + 0:13: " Part 2 + 0:19: " Part 3 + Video Tags: + album: Music Videos + artist: JMC + genre: ytdl-sub + premiered: 2020-08-08 + title: Mock Entry 20-2 + year: 2020 + Mock Entry 20-2.nfo + NFO tags: + musicvideo: + album: Music Videos + artist: JMC + genre: ytdl-sub + premiered: 2020-08-08 + title: Mock Entry 20-2 + Mock Entry 20-3.info.json + Mock Entry 20-3.jpg + Mock Entry 20-3.mp4 + Chapters from comments: + 0:00: " Intro + 0:07: " Part 1 + 0:13: " Part 2 + 0:19: " Part 3 + Video Tags: + album: Music Videos + artist: JMC + genre: ytdl-sub + premiered: 2020-08-07 + title: Mock Entry 20-3 + year: 2020 + Mock Entry 20-3.nfo + NFO tags: + musicvideo: + album: Music Videos + artist: JMC + genre: ytdl-sub + premiered: 2020-08-07 + title: Mock Entry 20-3 + Mock Entry 21-1.info.json + Mock Entry 21-1.jpg + Mock Entry 21-1.mp4 + Chapters from comments: + 0:00: " Intro + 0:07: " Part 1 + 0:13: " Part 2 + 0:19: " Part 3 + Video Tags: + album: Music Videos + artist: JMC + genre: ytdl-sub + premiered: 2021-08-08 + title: Mock Entry 21-1 + year: 2021 + Mock Entry 21-1.nfo + NFO tags: + musicvideo: + album: Music Videos + artist: JMC + genre: ytdl-sub + premiered: 2021-08-08 + title: Mock Entry 21-1 \ No newline at end of file