From 3df583f65636212b7599db43711b60e1b44e815e Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Tue, 17 Oct 2023 10:59:09 -0700 Subject: [PATCH] beautify tv_show_subscriptions --- examples/tv_show_config.yaml | 19 ++++----- examples/tv_show_subscriptions.yaml | 41 +++++++++++-------- .../subscriptions/subscription_validators.py | 5 ++- tests/unit/config/test_subscription.py | 14 +++---- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/examples/tv_show_config.yaml b/examples/tv_show_config.yaml index f81ef60e..c74712f6 100644 --- a/examples/tv_show_config.yaml +++ b/examples/tv_show_config.yaml @@ -22,7 +22,7 @@ configuration: presets: # Your main TV show preset - all your tv show subscriptions will use this. - tv_show: + "TV Show Full Archive": preset: # Choose one of the following player types: # - "kodi_tv_show_by_date" @@ -41,7 +41,6 @@ presets: # Include any of the presets listed below in your 'main preset' if you want # it applied to every TV show. Or, use them on the individual subscriptions. - # - "only_recent_videos" # - "add_subtitles" # - "sponsorblock" # - "include_info_json" @@ -62,8 +61,12 @@ presets: #################################################################################################### - # Preset to only download and keep recent videos - only_recent_videos: + # A secondary TV Show preset that only keeps recent videos + "TV Show Only Recent": + + # Inherit the `TV Show Full Archive` preset + preset: + - "TV Show Full Archive" # Only download videos within the download_range date_range: @@ -113,11 +116,3 @@ presets: - "music_offtopic" remove_sponsorblock_categories: "all" force_key_frames: False - -#################################################################################################### - - # Preset for the hoarders who want to also save the info.json file - include_info_json: - output_options: - info_json_name: "{episode_file_path}.{info_json_ext}" - diff --git a/examples/tv_show_subscriptions.yaml b/examples/tv_show_subscriptions.yaml index 3770b5b3..c3a2be4c 100644 --- a/examples/tv_show_subscriptions.yaml +++ b/examples/tv_show_subscriptions.yaml @@ -1,32 +1,39 @@ +# Global overrides for all subscriptions. Can either be set here or in your config.yaml +__preset__: + overrides: + tv_show_directory: "/tv_shows" + episode_title: "{upload_date_standardized} - {title}" + episode_plot: "{webpage_url}" + download_range: "2months" -# All subscriptions under this will use the `tv_show` preset -tv_show: - # Sets override variable `subscription_indent_1` to "Music", which is used as genre - =[Music]: + +# All subscriptions under this will use the `TV Show Full Archive` preset +TV Show Full Archive: + # Sets "Music" as the TV show genre + = Music: "Rick A": "https://www.youtube.com/channel/UCuAXFkgsw1L7xaCfnd5JJOw" "Opeth": "https://www.youtube.com/channel/UCmQSJTFZaXN85gYk6W3XbdQ" - # Sets override variables `subscription_indent_1` and `subscription_indent_2`. - # Second is used as MPAA rating - =[Kids|TV-Y]: + # Sets "Kids" as the TV show genre, and "TV-Y" as the content rating + = Kids | TV-Y: "Jake Trains": "https://www.youtube.com/@JakeTrains" "Kids Toys Play": "https://www.youtube.com/@KidsToysPlayChannel" - # All subscriptions under this will use both `tv_show` and `only_recent_videos` preset - only_recent_videos: - =[News]: - "BBC": "https://www.youtube.com/@BBCNews" + +# All subscriptions under this will use the `TV Show Only Recent` preset +TV Show Only Recent: + = News | TV-14: + "BBC": "https://www.youtube.com/@BBCNews" -# If a key is not a preset, it is then treated as a subscription. -# Subscriptions can use the same format as a preset, or a single string -# like above which gets set to the override variable `subscription_value` +# ADVANCED USAGE: +# If a key is not a preset, it is treated as a subscription. +# Subscriptions can use the same format as a preset found within a config. "Equivalent to BBC": preset: - - "tv_show" - - "only_recent_videos" - + - "TV Show Only Recent" overrides: tv_show_name: "BBC" url: "https://www.youtube.com/@BBCNews" tv_show_genre: "News" + tv_show_content_rating: "TV-14" diff --git a/src/ytdl_sub/subscriptions/subscription_validators.py b/src/ytdl_sub/subscriptions/subscription_validators.py index 0a4914ee..2b15f065 100644 --- a/src/ytdl_sub/subscriptions/subscription_validators.py +++ b/src/ytdl_sub/subscriptions/subscription_validators.py @@ -42,8 +42,9 @@ def maybe_indent_override_values(value: str) -> List[str]: ------- Value if it is an overide [Value]. None otherwise. """ - if value.startswith("=[") and value.endswith("]"): - return value[2:-1].split("|") + if value.startswith("="): + # Drop the =, split on |, and strip each indent_value (both left + right) + return [indent_value.strip() for indent_value in value[1:].split("|")] return [] diff --git a/tests/unit/config/test_subscription.py b/tests/unit/config/test_subscription.py index f8aaf240..3b99b7bf 100644 --- a/tests/unit/config/test_subscription.py +++ b/tests/unit/config/test_subscription.py @@ -100,9 +100,9 @@ def preset_with_subscription_value_nested_presets_and_indent_variables( preset_with_subscription_value, **{ "parent_preset_2": { - "=[INDENT_1]": { + "= INDENT_1 ": { "parent_preset_1": {"test_2_1": "is_2_1_overwritten"}, - "=[INDENT_2]": { + "=INDENT_2": { "test_1": "is_1_overwritten", }, } @@ -119,9 +119,9 @@ def preset_with_subscription_value_nested_presets_and_indent_variables_same_line preset_with_subscription_value, **{ "parent_preset_2": { - "=[INDENT_1]": { + "=INDENT_1": { "parent_preset_1": {"test_2_1": "is_2_1_overwritten"}, - "=[INDENT_2|INDENT_3]": { + "= INDENT_2 | INDENT_3 ": { "test_1": "is_1_overwritten", }, } @@ -311,14 +311,14 @@ def test_subscription_file_bad_value(config_file: ConfigFile): def test_subscription_file_using_conflicting_preset_name(config_file: ConfigFile): with mock_load_yaml( preset_dict={ - "=[INDENTS_IN_ERR_MSG]": { - "=[ANOTHER]": {"jellyfin_tv_show_by_date": "single value, __value__ not defined"} + "= INDENTS_IN_ERR_MSG ": { + "=ANOTHER": {"jellyfin_tv_show_by_date": "single value, __value__ not defined"} } } ), pytest.raises( ValidationException, match=re.escape( - "Validation error in =[INDENTS_IN_ERR_MSG].=[ANOTHER].jellyfin_tv_show_by_date: " + "Validation error in = INDENTS_IN_ERR_MSG .=ANOTHER.jellyfin_tv_show_by_date: " "jellyfin_tv_show_by_date conflicts with an existing preset name and cannot be used " "as a subscription name" ),