diff --git a/src/ytdl_sub/entries/variables/kwargs.py b/src/ytdl_sub/entries/variables/kwargs.py index b9c74161..59e2729e 100644 --- a/src/ytdl_sub/entries/variables/kwargs.py +++ b/src/ytdl_sub/entries/variables/kwargs.py @@ -43,7 +43,9 @@ PLAYLIST_UPLOADER_URL = _("playlist_uploader_url") DOWNLOAD_INDEX = _("download_index", backend=True) UPLOAD_DATE_INDEX = _("upload_date_index", backend=True) REQUESTED_SUBTITLES = _("requested_subtitles", backend=True) +CHAPTERS = _("chapters", backend=True) SPONSORBLOCK_CHAPTERS = _("sponsorblock_chapters", backend=True) +SPLIT_BY_CHAPTERS_PARENT_ENTRY = _("split_by_chapters_parent_entry", backend=True) UID = _("id") EXTRACTOR = _("extractor") EPOCH = _("epoch") diff --git a/src/ytdl_sub/plugins/split_by_chapters.py b/src/ytdl_sub/plugins/split_by_chapters.py index c7fa4b50..5f531c40 100644 --- a/src/ytdl_sub/plugins/split_by_chapters.py +++ b/src/ytdl_sub/plugins/split_by_chapters.py @@ -9,6 +9,9 @@ from typing import Tuple from yt_dlp.utils import sanitize_filename from ytdl_sub.entries.entry import Entry +from ytdl_sub.entries.variables.kwargs import CHAPTERS +from ytdl_sub.entries.variables.kwargs import SPLIT_BY_CHAPTERS_PARENT_ENTRY +from ytdl_sub.entries.variables.kwargs import SPONSORBLOCK_CHAPTERS from ytdl_sub.entries.variables.kwargs import UID from ytdl_sub.plugins.plugin import Plugin from ytdl_sub.plugins.plugin import PluginOptions @@ -121,11 +124,17 @@ class SplitByChaptersPlugin(Plugin[SplitByChaptersOptions]): ) # pylint: disable=protected-access - entry._kwargs[UID] = _split_video_uid(source_uid=entry.uid, idx=idx) - if "chapters" in entry._kwargs: - del entry._kwargs["chapters"] - if "sponsorblock_chapters" in entry._kwargs: - del entry._kwargs["sponsorblock_chapters"] + entry.add_kwargs( + { + UID: _split_video_uid(source_uid=entry.uid, idx=idx), + SPLIT_BY_CHAPTERS_PARENT_ENTRY: source_entry._kwargs, + } + ) + + if entry.kwargs_contains(CHAPTERS): + del entry._kwargs[CHAPTERS] + if entry.kwargs_contains(SPONSORBLOCK_CHAPTERS): + del entry._kwargs[SPONSORBLOCK_CHAPTERS] # pylint: enable=protected-access timestamp_begin = chapters.timestamps[idx].readable_str diff --git a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py index cd6d34b7..cbb3b211 100644 --- a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py +++ b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py @@ -13,6 +13,7 @@ from typing import Set from yt_dlp import DateRange from ytdl_sub.entries.entry import Entry +from ytdl_sub.entries.variables.kwargs import SPLIT_BY_CHAPTERS_PARENT_ENTRY from ytdl_sub.utils.file_handler import FileHandler from ytdl_sub.utils.file_handler import FileHandlerTransactionLog from ytdl_sub.utils.file_handler import FileMetadata @@ -587,7 +588,15 @@ class EnhancedDownloadArchive: if output_file_name is None: output_file_name = file_name - if entry: + # If the entry is created from splitting via chapters, store it to the mapping + # using its parent entry + if entry and entry.kwargs_contains(SPLIT_BY_CHAPTERS_PARENT_ENTRY): + parent_entry = Entry( + entry_dict=entry.kwargs(SPLIT_BY_CHAPTERS_PARENT_ENTRY), + working_directory=entry.working_directory(), + ) + self.mapping.add_entry(parent_entry, entry_file_path=output_file_name) + elif entry: self.mapping.add_entry(entry=entry, entry_file_path=output_file_name) self._file_handler.move_file_to_output_directory( diff --git a/tests/e2e/plugins/test_split_by_chapters.py b/tests/e2e/plugins/test_split_by_chapters.py index 9e3f0377..1320bc3a 100644 --- a/tests/e2e/plugins/test_split_by_chapters.py +++ b/tests/e2e/plugins/test_split_by_chapters.py @@ -15,7 +15,7 @@ def yt_album_as_chapters_preset_dict(output_directory): "preset": "album_from_chapters", "download": {"url": "https://www.youtube.com/watch?v=zeR2_YjlXWA"}, # override the output directory with our fixture-generated dir - "output_options": {"output_directory": output_directory}, + "output_options": {"output_directory": output_directory, "maintain_download_archive": True}, # download the worst format so it is fast "ytdl_options": { "format": "worst[ext=mp4]", @@ -89,6 +89,10 @@ class TestSplitByChapters: expected_download_summary_file_name="plugins/split_by_chapters_video.json", ) + if not dry_run: + transaction_log = subscription.download() + assert transaction_log.is_empty + @pytest.mark.parametrize("dry_run", [True, False]) def test_video_with_chapters_and_regex( self, diff --git a/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_video.json b/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_video.json index d1c039e2..726ef3cb 100644 --- a/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_video.json +++ b/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_video.json @@ -1,4 +1,5 @@ { + ".ytdl-sub-split_by_chapters_video-download-archive.json": "7001417f7a398959f3296ece81575a77", "Alfa Mist - Nocturne [Full Album]/01 - 01. Intro (Feat. Racheal Ofori & Barney Artist).mp3": "1ede8775719b99d05c89d6d0a2a74df5", "Alfa Mist - Nocturne [Full Album]/02 - 02. Answers (Feat. Rick David & Kaya Thomas - Dyke).mp3": "2430b44a6c15050f7e2ee09274c26600", "Alfa Mist - Nocturne [Full Album]/03 - 03. Blaze (Feat. Kaya Thomas - Dyke).mp3": "8dbb8d15109955c4540dfe3c015157b8", diff --git a/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt b/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt index f0d11530..ec039d90 100644 --- a/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt +++ b/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt @@ -1,4 +1,5 @@ { + ".ytdl-sub-split_by_chapters_with_regex_video-download-archive.json": "11367ac13068646e35a53d25deeba834", "Oblivion Mod "Falcor" p.1/01 - Oblivion Mod "Falcor" p.1.mp3": "6d570f225f6c3a14de0ba4c912995641", "Oblivion Mod "Falcor" p.1/folder.jpg": "fb95b510681676e81c321171fc23143e" } \ No newline at end of file diff --git a/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_video.json b/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_video.json index b6f1baad..0a7ee0a6 100644 --- a/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_video.json +++ b/tests/resources/expected_downloads_summaries/plugins/split_by_chapters_with_regex_video.json @@ -1,4 +1,5 @@ { + ".ytdl-sub-split_by_chapters_with_regex_video-download-archive.json": "5f281991d441f406b0d721b250e74b79", "Nocturne/01 - Intro (Feat. Racheal Ofori & Barney Artist).mp3": "b2e2a9834f03d1928e0c8a0602899d4d", "Nocturne/02 - Answers (Feat. Rick David & Kaya Thomas - Dyke).mp3": "8fe76edcc77c5d8db0f7b5b8577a4cf6", "Nocturne/03 - Blaze (Feat. Kaya Thomas - Dyke).mp3": "fd45453753a783ec4f26ef399a8ecece", diff --git a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video-dry-run.txt b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video-dry-run.txt index 9f1fadaa..3e361482 100644 --- a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video-dry-run.txt +++ b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video-dry-run.txt @@ -1,5 +1,7 @@ Files created: ---------------------------------------- +{output_directory} + .ytdl-sub-split_by_chapters_video-download-archive.json {output_directory}/Alfa Mist - Nocturne [Full Album] 01 - 01. Intro (Feat. Racheal Ofori & Barney Artist).mp3 From Chapter Split: diff --git a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video.txt b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video.txt index 3596b43f..b66c8b89 100644 --- a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video.txt +++ b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_video.txt @@ -1,5 +1,7 @@ Files created: ---------------------------------------- +{output_directory} + .ytdl-sub-split_by_chapters_video-download-archive.json {output_directory}/Alfa Mist - Nocturne [Full Album] 01 - 01. Intro (Feat. Racheal Ofori & Barney Artist).mp3 From Chapter Split: diff --git a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt index dc4013bc..9df6899f 100644 --- a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt +++ b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_no_chapters_video_pass.txt @@ -1,5 +1,7 @@ Files created: ---------------------------------------- +{output_directory} + .ytdl-sub-split_by_chapters_with_regex_video-download-archive.json {output_directory}/Oblivion Mod "Falcor" p.1 01 - Oblivion Mod "Falcor" p.1.mp3 Music Tags: diff --git a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video-dry-run.txt b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video-dry-run.txt index 8d1ba2c6..15a31b04 100644 --- a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video-dry-run.txt +++ b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video-dry-run.txt @@ -1,5 +1,7 @@ Files created: ---------------------------------------- +{output_directory} + .ytdl-sub-split_by_chapters_with_regex_video-download-archive.json {output_directory}/Nocturne 01 - Intro (Feat. Racheal Ofori & Barney Artist).mp3 From Chapter Split: diff --git a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video.txt b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video.txt index 9d424a4c..dc546f1c 100644 --- a/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video.txt +++ b/tests/resources/transaction_log_summaries/plugins/split_by_chapters_with_regex_video.txt @@ -1,5 +1,7 @@ Files created: ---------------------------------------- +{output_directory} + .ytdl-sub-split_by_chapters_with_regex_video-download-archive.json {output_directory}/Nocturne 01 - Intro (Feat. Racheal Ofori & Barney Artist).mp3 From Chapter Split: