From a5c5cb0d4053501f711191cabb398d592226ab69 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Mon, 24 Jul 2023 17:21:14 -0700 Subject: [PATCH] more compatible --- src/ytdl_sub/plugins/music_tags.py | 22 ++++++++++--------- tests/e2e/plugins/test_audio_extract.py | 2 -- .../test_audio_extract_single_old_format.json | 2 +- .../test_audio_extract_single_old_format.txt | 11 +++++++++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/ytdl_sub/plugins/music_tags.py b/src/ytdl_sub/plugins/music_tags.py index 7266bb66..b33fd2f5 100644 --- a/src/ytdl_sub/plugins/music_tags.py +++ b/src/ytdl_sub/plugins/music_tags.py @@ -1,7 +1,8 @@ +import copy from collections import defaultdict +from typing import Any from typing import Dict from typing import List -from typing import Optional import mediafile @@ -80,20 +81,21 @@ class MusicTagsOptions(OptionsDictValidator): def __init__(self, name, value): super().__init__(name, value) - tags_validator: Optional[MusicTagsValidator] = self._validate_key_if_present( - key="tags", validator=MusicTagsValidator + old_tags_validator = self._validate_key( + key="tags", validator=MusicTagsValidator, default={} ) self._embed_thumbnail = self._validate_key_if_present( key="embed_thumbnail", validator=BoolValidator ) + self._is_old_format = old_tags_validator is not None or self._embed_thumbnail is not None - # New format where tags are the keys, no "tags" or "embed_thumbnail" present - if tags_validator is None and self._embed_thumbnail is None: - self._tags = MusicTagsValidator(name=name, value=value) - self._is_old_format = False - else: - self._is_old_format = True - self._tags = tags_validator or MusicTagsValidator(name=name, value={}) + new_tags_dict: Dict[str, Any] = copy.deepcopy(value) + new_tags_dict.pop("tags", None) + new_tags_dict.pop("embed_thumbnail", None) + + self._tags = MusicTagsValidator( + name=name, value=dict(old_tags_validator._dict, **new_tags_dict) + ) @property def tags(self) -> MusicTagsValidator: diff --git a/tests/e2e/plugins/test_audio_extract.py b/tests/e2e/plugins/test_audio_extract.py index d09ab6f0..ef906929 100644 --- a/tests/e2e/plugins/test_audio_extract.py +++ b/tests/e2e/plugins/test_audio_extract.py @@ -11,8 +11,6 @@ def single_song_preset_dict_old_format(output_directory): "preset": "single", # test multi-tags "music_tags": {"embed_thumbnail": True, "tags": {"genres": ["multi_tag_1", "multi_tag_2"]}}, - # test the new embed_thumbnail plugin - "embed_thumbnail": True, # download the worst format so it is fast "ytdl_options": { "format": "worst[ext=mp4]", diff --git a/tests/resources/expected_downloads_summaries/plugins/test_audio_extract_single_old_format.json b/tests/resources/expected_downloads_summaries/plugins/test_audio_extract_single_old_format.json index 0c67e234..f4aa6b67 100644 --- a/tests/resources/expected_downloads_summaries/plugins/test_audio_extract_single_old_format.json +++ b/tests/resources/expected_downloads_summaries/plugins/test_audio_extract_single_old_format.json @@ -1,5 +1,5 @@ { ".ytdl-sub-single_song_test-download-archive.json": "c8ff22ec3304c9f8dab18cedaed4e8b4", - "YouTube/[2019] YouTube Rewind 2019: For the Record | #YouTubeRewind/01 - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp3": "7dcad720d29f5036eb6f75e533757f80", + "YouTube/[2019] YouTube Rewind 2019: For the Record | #YouTubeRewind/01 - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp3": "37b38834eda1293ad503e00dcff7c4dc", "YouTube/[2019] YouTube Rewind 2019: For the Record | #YouTubeRewind/folder.jpg": "50ee47c80f679029f5d3503bb91b045a" } \ No newline at end of file diff --git a/tests/resources/transaction_log_summaries/plugins/test_audio_extract_single_old_format.txt b/tests/resources/transaction_log_summaries/plugins/test_audio_extract_single_old_format.txt index d64f76a1..6327e106 100644 --- a/tests/resources/transaction_log_summaries/plugins/test_audio_extract_single_old_format.txt +++ b/tests/resources/transaction_log_summaries/plugins/test_audio_extract_single_old_format.txt @@ -5,8 +5,17 @@ Files created: {output_directory}/YouTube/[2019] YouTube Rewind 2019: For the Record | #YouTubeRewind 01 - YouTube Rewind 2019: For the Record | #YouTubeRewind.mp3 Embedded Thumbnail, Music Tags: + album: YouTube Rewind 2019: For the Record | #YouTubeRewind + albumartist: YouTube + albumartists: YouTube + artist: YouTube + artists: YouTube + genre: Unset genres: - multi_tag_1 - multi_tag_2 - Embedded thumbnail + title: YouTube Rewind 2019: For the Record | #YouTubeRewind + track: 1 + tracktotal: 1 + year: 2019 folder.jpg \ No newline at end of file