From 150ab69da250d013a05bcad9d0282f8f1b2fc2c8 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sun, 12 Mar 2023 18:17:58 -0700 Subject: [PATCH] ability to disable with empty string --- src/ytdl_sub/downloaders/downloader.py | 4 + src/ytdl_sub/validators/validators.py | 4 + tests/e2e/youtube/test_video.py | 22 +++-- .../youtube/test_video_nulled_values.txt | 82 +++++++++++++++++++ tests/unit/validators/test_dict_validator.py | 7 ++ 5 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 tests/resources/transaction_log_summaries/youtube/test_video_nulled_values.txt diff --git a/src/ytdl_sub/downloaders/downloader.py b/src/ytdl_sub/downloaders/downloader.py index 862d4927..35edf695 100644 --- a/src/ytdl_sub/downloaders/downloader.py +++ b/src/ytdl_sub/downloaders/downloader.py @@ -642,6 +642,10 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT], ABC): Downloads and moves channel avatar and banner images to the output directory. """ for thumbnail_info in thumbnail_list_info.list: + # If thumbnail name was set to empty, do nothing + if thumbnail_info.name is None: + continue + thumbnail_name = self.overrides.apply_formatter(thumbnail_info.name, entry=entry) thumbnail_id = self.overrides.apply_formatter(thumbnail_info.uid) diff --git a/src/ytdl_sub/validators/validators.py b/src/ytdl_sub/validators/validators.py index da25b1e9..51842d81 100644 --- a/src/ytdl_sub/validators/validators.py +++ b/src/ytdl_sub/validators/validators.py @@ -260,8 +260,12 @@ class DictValidator(Validator): ------- An instance of the specified validator """ + # If the key does not exist and default is None, return None if key not in self._dict and default is None: return None + # If the key exists but is None (null in YAML) or empty string, return None + if key in self._dict and self._dict[key] in (None, ""): + return None return self._validate_key(key=key, validator=validator, default=default) diff --git a/tests/e2e/youtube/test_video.py b/tests/e2e/youtube/test_video.py index c7cdcbb9..9e39a715 100644 --- a/tests/e2e/youtube/test_video.py +++ b/tests/e2e/youtube/test_video.py @@ -1,10 +1,9 @@ import pytest -from mergedeep import mergedeep - from conftest import preset_dict_to_dl_args from e2e.conftest import mock_run_from_cli from expected_download import assert_expected_downloads from expected_transaction_log import assert_transaction_log_matches +from mergedeep import mergedeep from ytdl_sub.subscriptions.subscription import Subscription @@ -32,24 +31,24 @@ def single_video_preset_dict(output_directory): "overrides": {"artist": "JMC"}, } + @pytest.fixture def single_tv_show_video_nulled_values_preset_dict(output_directory): return { "preset": [ "jellyfin_tv_show_by_date", "season_by_year__episode_by_download_index", + "chunk_initial_download", ], "download": {"url": "https://www.youtube.com/@ProjectZombie603"}, # set file output fields to None "output_options": { - "thumbnail_name": None, - "info_json_name": None, - }, - "nfo_tags": { - "nfo_name": None, + "thumbnail_name": "", + "info_json_name": "", }, "ytdl_options": { "format": "worst[ext=mp4]", + "max_downloads": 2, }, "overrides": { "tv_show_name": "Project Zombie", @@ -117,12 +116,11 @@ class TestYoutubeVideo: expected_download_summary_file_name="youtube/test_video_cli.json", ) - def test_single_video_nulled_values( - self, - channel_as_tv_show_config, - single_tv_show_video_nulled_values_preset_dict, - output_directory, + self, + channel_as_tv_show_config, + single_tv_show_video_nulled_values_preset_dict, + output_directory, ): single_video_subscription = Subscription.from_dict( config=channel_as_tv_show_config, diff --git a/tests/resources/transaction_log_summaries/youtube/test_video_nulled_values.txt b/tests/resources/transaction_log_summaries/youtube/test_video_nulled_values.txt new file mode 100644 index 00000000..ff98d350 --- /dev/null +++ b/tests/resources/transaction_log_summaries/youtube/test_video_nulled_values.txt @@ -0,0 +1,82 @@ +Files created: +---------------------------------------- +{output_directory} + .ytdl-sub-tv_video_nulled_values-download-archive.json + fanart.jpg + poster.jpg + tvshow.nfo + NFO tags: + tvshow: + genre: ytdl-sub + title: Project Zombie +{output_directory}/Season 2010 + s2010.e000001 - Oblivion Mod "Falcor" p.1.mp4 + Video Tags: + date: 2010-08-13 + episode_id: 1 + genre: ytdl-sub + show: Project Zombie + synopsis: + https://www.youtube.com/watch?v=HKTNxEqsN3Q + + PLEASE WATCH IN HD! + + This is the castle in the mod "Falcor" which we are currently working on. + You can find some more information about the mod @ http://www.oblivionfalcormod.webs.com/ + + This is the first time I've really used the editor, and the beginning of our first mod. Hope you enjoy. + title: 2010-08-13 - Oblivion Mod "Falcor" p.1 + year: 2010 + s2010.e000001 - Oblivion Mod "Falcor" p.1.nfo + NFO tags: + episodedetails: + aired: 2010-08-13 + episode: 1 + genre: ytdl-sub + plot: + https://www.youtube.com/watch?v=HKTNxEqsN3Q + + PLEASE WATCH IN HD! + + This is the castle in the mod "Falcor" which we are currently working on. + You can find some more information about the mod @ http://www.oblivionfalcormod.webs.com/ + + This is the first time I've really used the editor, and the beginning of our first mod. Hope you enjoy. + season: 2010 + title: 2010-08-13 - Oblivion Mod "Falcor" p.1 + year: 2010 + s2010.e000002 - Oblivion Mod "Falcor" p.2.mp4 + Video Tags: + date: 2010-12-02 + episode_id: 2 + genre: ytdl-sub + show: Project Zombie + synopsis: + https://www.youtube.com/watch?v=IV9Z4wcA-z8 + + PLEASE WATCH IN HD. + + Download Link: + http://www.tesnexus.com/downloads/file.php?id=36306 + + Please keep in mind that the mod is not complete, so you'll see some blank areas during the video. I haven't made LOD (Level of Distance) yet either, so areas far away will not appear. + title: 2010-12-02 - Oblivion Mod "Falcor" p.2 + year: 2010 + s2010.e000002 - Oblivion Mod "Falcor" p.2.nfo + NFO tags: + episodedetails: + aired: 2010-12-02 + episode: 2 + genre: ytdl-sub + plot: + https://www.youtube.com/watch?v=IV9Z4wcA-z8 + + PLEASE WATCH IN HD. + + Download Link: + http://www.tesnexus.com/downloads/file.php?id=36306 + + Please keep in mind that the mod is not complete, so you'll see some blank areas during the video. I haven't made LOD (Level of Distance) yet either, so areas far away will not appear. + season: 2010 + title: 2010-12-02 - Oblivion Mod "Falcor" p.2 + year: 2010 \ No newline at end of file diff --git a/tests/unit/validators/test_dict_validator.py b/tests/unit/validators/test_dict_validator.py index 5ae9b0d5..544c67eb 100644 --- a/tests/unit/validators/test_dict_validator.py +++ b/tests/unit/validators/test_dict_validator.py @@ -80,6 +80,13 @@ class TestDictValidator: assert isinstance(out, StringValidator) assert out.value == "default" + @pytest.mark.parametrize("empty_value", [None, ""]) + def test_dict_validator_validate_key_if_present_has_empty_value(self, empty_value): + dict_validator = DictValidator(name="validate_key", value={"key_name": empty_value}) + out = dict_validator._validate_key_if_present(key="key_name", validator=StringValidator) + + assert out is None + @pytest.mark.parametrize("bad_value", [True, None, {}]) def test_dict_validator_validate_key_errors_none_bad_validation(self, bad_value): dict_validator = DictValidator(name="parent", value={"child": bad_value})