updates
This commit is contained in:
parent
9998de64c3
commit
afdd11977a
5 changed files with 36 additions and 26 deletions
|
|
@ -61,6 +61,7 @@ presets:
|
|||
- url: "{url19}"
|
||||
- url: "{url20}"
|
||||
overrides:
|
||||
url: "{subscription_value}"
|
||||
url2: ""
|
||||
url3: ""
|
||||
url4: ""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import copy
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
|
@ -92,7 +93,9 @@ class Subscription(SubscriptionDownload):
|
|||
return subscription_value_key
|
||||
|
||||
@classmethod
|
||||
def from_file_path(cls, config: ConfigFile, subscription_path: str) -> List["Subscription"]:
|
||||
def from_file_path(
|
||||
cls, config: ConfigFile, subscription_path: str | Path
|
||||
) -> List["Subscription"]:
|
||||
"""
|
||||
Loads subscriptions from a file and applies ``__preset__`` to all of them if present.
|
||||
If a subscription is in the form of key: value, it will set value to the override
|
||||
|
|
|
|||
|
|
@ -112,24 +112,19 @@ class SubscriptionValueValidator(SubscriptionOutput, StringValidator):
|
|||
f"{self._leaf_name} conflicts with an existing preset name and cannot be "
|
||||
f"used as a subscription name"
|
||||
)
|
||||
|
||||
if subscription_value is None:
|
||||
raise self._validation_exception(
|
||||
f"Subscription {self._leaf_name} is a string, but the subscription value "
|
||||
f"is not set to an override variable"
|
||||
)
|
||||
|
||||
self._subscription_value: str = subscription_value
|
||||
self._subscription_value: Optional[str] = subscription_value
|
||||
|
||||
def subscription_dicts(self) -> Dict[str, Dict]:
|
||||
subscription_value_dict: Dict[str, str] = {"subscription_value": self.value}
|
||||
# TODO: Eventually delete in favor of {subscription_value}
|
||||
if self._subscription_value:
|
||||
subscription_value_dict[self._subscription_value] = self.value
|
||||
|
||||
return {
|
||||
self._leaf_name: {
|
||||
"preset": self._presets,
|
||||
"overrides": dict(
|
||||
{
|
||||
self._subscription_value: self.value,
|
||||
"subscription_value": self.value,
|
||||
},
|
||||
subscription_value_dict,
|
||||
**self._indent_overrides_dict(),
|
||||
),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,6 +179,11 @@ def channel_as_tv_show_config(working_directory) -> ConfigFile:
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def tv_show_subscriptions_path() -> Path:
|
||||
return Path("examples/tv_show_subscriptions.yaml")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def music_audio_config(working_directory) -> ConfigFile:
|
||||
return _load_config(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import re
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from unittest.mock import patch
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ from ytdl_sub.plugins.nfo_tags import NfoTagsOptions
|
|||
from ytdl_sub.subscriptions.subscription import FILE_SUBSCRIPTION_VALUE_KEY
|
||||
from ytdl_sub.subscriptions.subscription import Subscription
|
||||
from ytdl_sub.utils.exceptions import ValidationException
|
||||
from ytdl_sub.utils.yaml import load_yaml
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -306,19 +308,6 @@ def test_subscription_file_bad_value(config_file: ConfigFile):
|
|||
_ = Subscription.from_file_path(config=config_file, subscription_path="mocked")
|
||||
|
||||
|
||||
def test_subscription_file_using_value_when_not_defined(config_file: ConfigFile):
|
||||
with mock_load_yaml(
|
||||
preset_dict={"=[INDENTS_IN_ERR_MSG]": {"sub_name": "single value, __value__ not defined"}}
|
||||
), pytest.raises(
|
||||
ValidationException,
|
||||
match=re.escape(
|
||||
"Validation error in =[INDENTS_IN_ERR_MSG].sub_name: Subscription "
|
||||
"sub_name is a string, but the subscription value is not set to an override variable"
|
||||
),
|
||||
):
|
||||
_ = Subscription.from_file_path(config=config_file, subscription_path="mocked")
|
||||
|
||||
|
||||
def test_subscription_file_using_conflicting_preset_name(config_file: ConfigFile):
|
||||
with mock_load_yaml(
|
||||
preset_dict={
|
||||
|
|
@ -343,3 +332,20 @@ def test_subscription_file_invalid_form(config_file: ConfigFile):
|
|||
match=re.escape(f"Validation error in sub_name: should be of type object."),
|
||||
):
|
||||
_ = Subscription.from_file_path(config=config_file, subscription_path="mocked")
|
||||
|
||||
|
||||
def test_tv_show_subscriptions(
|
||||
channel_as_tv_show_config: ConfigFile, tv_show_subscriptions_path: Path
|
||||
):
|
||||
subs = Subscription.from_file_path(
|
||||
config=channel_as_tv_show_config, subscription_path=tv_show_subscriptions_path
|
||||
)
|
||||
|
||||
assert len(subs) == 6
|
||||
assert subs[2].name == "Jake Trains"
|
||||
jake_train_overrides = subs[2].overrides.dict_with_format_strings
|
||||
|
||||
assert jake_train_overrides["subscription_name"] == "Jake Trains"
|
||||
assert jake_train_overrides["subscription_value"] == "https://www.youtube.com/@JakeTrains"
|
||||
assert jake_train_overrides["subscription_indent_1"] == "Kids"
|
||||
assert jake_train_overrides["subscription_indent_2"] == "TV-Y"
|
||||
|
|
|
|||
Loading…
Reference in a new issue