[FEATURE] Add subscription_name override variable by default (#599)

* [FEATURE] Add `subscription_name` override variable by default

* docs for it

* lint

* only test non-cli video test
This commit is contained in:
Jesse Bannon
2023-04-28 22:36:20 -04:00
committed by GitHub
parent d5d9978cdb
commit a2f1a2ba94
7 changed files with 66 additions and 14 deletions

View File

@@ -318,6 +318,12 @@ Source Variables
:inherited-members:
:undoc-members:
Override Variables
------------------
.. autoclass:: ytdl_sub.config.preset_options.OverridesVariables()
:members:
-------------------------------------------------------------------------------
Config Types

View File

@@ -110,9 +110,45 @@ class YTDLOptions(LiteralDictValidator):
"""
class OverridesVariables(DictFormatterValidator):
"""
Override variables that are automatically added to every subscription.
"""
def _add_override_variable(self, key_name: str, format_string: str, sanitize: bool = False):
if sanitize:
key_name = f"{key_name}_sanitized"
format_string = sanitize_filename(format_string)
self._value[key_name] = StringFormatterValidator(
name="__should_never_fail__",
value=format_string,
)
def __init__(self, name, value):
super().__init__(name, value)
# Add sanitized and non-sanitized override variables
for sanitize in [True, False]:
self._add_override_variable(
key_name="subscription_name",
format_string=self.subscription_name,
sanitize=sanitize,
)
@property
def subscription_name(self) -> str:
"""
Returns
-------
Name of the subscription
"""
return self._root_name
# Disable for proper docstring formatting
# pylint: disable=line-too-long
class Overrides(DictFormatterValidator):
class Overrides(OverridesVariables):
"""
Optional. This section allows you to define variables that can be used in any string formatter.
For example, if you want your file and thumbnail files to match without copy-pasting a large
@@ -142,16 +178,6 @@ class Overrides(DictFormatterValidator):
# pylint: enable=line-too-long
def _add_override_variable(self, key_name: str, format_string: str, sanitize: bool = False):
if sanitize:
key_name = f"{key_name}_sanitized"
format_string = sanitize_filename(format_string)
self._value[key_name] = StringFormatterValidator(
name="__should_never_fail__",
value=format_string,
)
def __init__(self, name, value):
super().__init__(name, value)

View File

@@ -179,6 +179,16 @@ class DictValidator(Validator):
super().__init__(name, value)
self.__validator_dict: Dict[str, Validator] = {}
@final
@property
def _root_name(self) -> str:
"""
Returns
-------
"first" from the first.element.of.the.name
"""
return self._name.split(".")[0]
@final
@property
def _dict(self) -> dict:

View File

@@ -3,7 +3,6 @@ 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
@@ -49,6 +48,13 @@ def single_tv_show_video_nulled_values_preset_dict(output_directory):
"format": "worst[ext=mp4]",
"max_downloads": 2,
},
# test override variables added by ytdl-sub
"nfo_tags": {
"tags": {
"subscription_name": "{subscription_name}",
"subscription_name_sanitized": "{subscription_name_sanitized}",
}
},
"overrides": {
"url": "https://www.youtube.com/@ProjectZombie603",
"tv_show_name": "Project Zombie",

View File

@@ -1,6 +1,6 @@
{
"JMC/JMC - Oblivion Mod Falcor p.1-thumb.jpg": "fb95b510681676e81c321171fc23143e",
"JMC/JMC - Oblivion Mod Falcor p.1.info.json": "e4eb0e33920f9b4dce1fcba0561614c9",
"JMC/JMC - Oblivion Mod Falcor p.1.info.json": "59ac500bb4778b37bd8c8fb472269e95",
"JMC/JMC - Oblivion Mod Falcor p.1.mp4": "3744c49f2e447bd7712a5aad5ed36be2",
"JMC/JMC - Oblivion Mod Falcor p.1.nfo": "24cc4e17d2bebc89b2759ce5471d403e"
}

View File

@@ -1,6 +1,6 @@
{
"JMC/JMC - Oblivion Mod Falcor p.1-thumb.jpg": "fb95b510681676e81c321171fc23143e",
"JMC/JMC - Oblivion Mod Falcor p.1.info.json": "62101bc3899f69860004ddcfc061a28b",
"JMC/JMC - Oblivion Mod Falcor p.1.info.json": "2ad1e593fc1c50a53a107db062e82c4a",
"JMC/JMC - Oblivion Mod Falcor p.1.mp4": "3744c49f2e447bd7712a5aad5ed36be2",
"JMC/JMC - Oblivion Mod Falcor p.1.nfo": "24cc4e17d2bebc89b2759ce5471d403e"
}

View File

@@ -43,6 +43,8 @@ Files created:
This is the first time I've really used the editor, and the beginning of our first mod. Hope you enjoy.
season: 2010
subscription_name: tv_video_nulled_values
subscription_name_sanitized: tv_video_nulled_values
title: 2010-08-13 - Oblivion Mod "Falcor" p.1
year: 2010
s2010.e000002 - Oblivion Mod Falcor p.2.mp4
@@ -78,5 +80,7 @@ Files created:
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
subscription_name: tv_video_nulled_values
subscription_name_sanitized: tv_video_nulled_values
title: 2010-12-02 - Oblivion Mod "Falcor" p.2
year: 2010