make it more compatible
This commit is contained in:
parent
196199e034
commit
3400a877a7
8 changed files with 108 additions and 15 deletions
|
|
@ -24,3 +24,13 @@ __preset__:
|
||||||
"Michael Jackson": "https://www.youtube.com/playlist?list=OLAK5uy_mnY03zP6abNWH929q2XhGzWD_2uKJ_n8E"
|
"Michael Jackson": "https://www.youtube.com/playlist?list=OLAK5uy_mnY03zP6abNWH929q2XhGzWD_2uKJ_n8E"
|
||||||
= Blues:
|
= Blues:
|
||||||
"Eric Clapton": "https://www.youtube.com/playlist?list=PLABGggHhsbEeaRtdzqnxYoEINsJE_4GF4"
|
"Eric Clapton": "https://www.youtube.com/playlist?list=PLABGggHhsbEeaRtdzqnxYoEINsJE_4GF4"
|
||||||
|
|
||||||
|
= Rock:
|
||||||
|
# TODO: DOCUMENTATION
|
||||||
|
"+ Guns N' Roses":
|
||||||
|
Music Videos:
|
||||||
|
- "https://www.youtube.com/playlist?list=PLOTK54q5K4INNXaHKtmXYr6J7CajWjqeJ"
|
||||||
|
Concerts:
|
||||||
|
- title: "Live at The Ritz - New York City"
|
||||||
|
date: "1988"
|
||||||
|
url: "https://www.youtube.com/watch?v=OldpIhHPsbs"
|
||||||
|
|
@ -3,6 +3,7 @@ from typing import Set
|
||||||
|
|
||||||
from ytdl_sub.entries.script.function_scripts import CUSTOM_FUNCTION_SCRIPTS
|
from ytdl_sub.entries.script.function_scripts import CUSTOM_FUNCTION_SCRIPTS
|
||||||
from ytdl_sub.entries.script.variable_definitions import VARIABLE_SCRIPTS
|
from ytdl_sub.entries.script.variable_definitions import VARIABLE_SCRIPTS
|
||||||
|
from ytdl_sub.entries.script.variable_types import ArrayVariable
|
||||||
from ytdl_sub.entries.script.variable_types import BooleanVariable
|
from ytdl_sub.entries.script.variable_types import BooleanVariable
|
||||||
from ytdl_sub.entries.script.variable_types import MapVariable
|
from ytdl_sub.entries.script.variable_types import MapVariable
|
||||||
from ytdl_sub.entries.script.variable_types import StringVariable
|
from ytdl_sub.entries.script.variable_types import StringVariable
|
||||||
|
|
@ -36,6 +37,21 @@ class SubscriptionVariables:
|
||||||
"""
|
"""
|
||||||
return StringVariable(variable_name="subscription_value", definition="{ %string('') }")
|
return StringVariable(variable_name="subscription_value", definition="{ %string('') }")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def subscription_array() -> ArrayVariable:
|
||||||
|
"""
|
||||||
|
For subscriptions in the form of
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
"Subscription Name":
|
||||||
|
- "https://url1.com/..."
|
||||||
|
- "https://url2.com/..."
|
||||||
|
|
||||||
|
Store all values into an array named ``subscription_array``.
|
||||||
|
"""
|
||||||
|
return ArrayVariable(variable_name="subscription_array", definition="{ [] }")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def subscription_indent_i(index: int) -> StringVariable:
|
def subscription_indent_i(index: int) -> StringVariable:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ presets:
|
||||||
avatar_uncropped_thumbnail_file_name: ""
|
avatar_uncropped_thumbnail_file_name: ""
|
||||||
banner_uncropped_thumbnail_file_name: ""
|
banner_uncropped_thumbnail_file_name: ""
|
||||||
|
|
||||||
|
subscription_array: "{ [] }"
|
||||||
subscription_value: ""
|
subscription_value: ""
|
||||||
subscription_value_2: ""
|
subscription_value_2: ""
|
||||||
subscription_value_3: ""
|
subscription_value_3: ""
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ presets:
|
||||||
|
|
||||||
# Creates an array in the form of [ { url: ..., category: ..., metadata_field_1: ... }, ... ]
|
# Creates an array in the form of [ { url: ..., category: ..., metadata_field_1: ... }, ... ]
|
||||||
category_url_array: >-
|
category_url_array: >-
|
||||||
{ %array_flatten( %map_apply( subscription_dict, %flat_array__category_to_map_format ) ) }
|
{ %array_flatten( %map_apply( subscription_map, %flat_array__category_to_map_format ) ) }
|
||||||
|
|
||||||
# Creates a map in the form of { <url value>: { category: ..., metadata_field_1: ... }, ... }
|
# Creates a map in the form of { <url value>: { category: ..., metadata_field_1: ... }, ... }
|
||||||
category_url_map: >-
|
category_url_map: >-
|
||||||
|
|
@ -82,8 +82,16 @@ presets:
|
||||||
# Output:
|
# Output:
|
||||||
# Metadata field value if it exists. Otherwise, return default value
|
# Metadata field value if it exists. Otherwise, return default value
|
||||||
"%get_url_field": >-
|
"%get_url_field": >-
|
||||||
{
|
{ %map_get( %map( %map_get( category_url_map, ytdl_sub_input_url, {} ) ), $0, $1 ) }
|
||||||
%map_get( %map( %map_get( category_url_map, ytdl_sub_input_url, {} ) ), $0, $1 ) }
|
|
||||||
|
# Parameters:
|
||||||
|
# $0: metadata field to fetch for the current url
|
||||||
|
#
|
||||||
|
# Output:
|
||||||
|
# True if field is specified. False otherwise.
|
||||||
|
"%contains_url_field": >-
|
||||||
|
{ %not( %is_null( %get_url_field( $0, null ) ) ) }
|
||||||
|
|
||||||
|
|
||||||
# Parameters:
|
# Parameters:
|
||||||
# $0: integer to fetch the i'th url using 1-based indexing
|
# $0: integer to fetch the i'th url using 1-based indexing
|
||||||
|
|
@ -91,8 +99,15 @@ presets:
|
||||||
# Output:
|
# Output:
|
||||||
# i'th url in the category map
|
# i'th url in the category map
|
||||||
"%get_url_i": >-
|
"%get_url_i": >-
|
||||||
{ %map_get( %map( %array_at( category_url_array, %int( %sub($0, 1) ), {} ) ), "url", null )}
|
{
|
||||||
|
%map_get(
|
||||||
|
%map( %array_at( category_url_array, %int( %sub($0, 1) ), {} ) ),
|
||||||
|
"url",
|
||||||
|
%array_at(subscription_array, %int( %sub($0, 1) ), null)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
subscription_map: "{ {} }"
|
||||||
url: "{ %get_url_i(1) }"
|
url: "{ %get_url_i(1) }"
|
||||||
url2: "{ %get_url_i(2) }"
|
url2: "{ %get_url_i(2) }"
|
||||||
url3: "{ %get_url_i(3) }"
|
url3: "{ %get_url_i(3) }"
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ presets:
|
||||||
# Defaults
|
# Defaults
|
||||||
music_video_genre_default: "ytdl-sub"
|
music_video_genre_default: "ytdl-sub"
|
||||||
music_video_album_default: "Music Videos"
|
music_video_album_default: "Music Videos"
|
||||||
subscription_dict: "{ {} }"
|
|
||||||
|
|
||||||
# Subscription overrides
|
# Subscription overrides
|
||||||
subscription_indent_1: "{music_video_genre_default}"
|
subscription_indent_1: "{music_video_genre_default}"
|
||||||
|
|
@ -34,9 +33,29 @@ presets:
|
||||||
music_video_title: >-
|
music_video_title: >-
|
||||||
{ %get_url_field("title", title) }
|
{ %get_url_field("title", title) }
|
||||||
music_video_date: >-
|
music_video_date: >-
|
||||||
{ %get_url_field("date", upload_date_standardized) }
|
{
|
||||||
|
%elif(
|
||||||
|
%contains_url_field("date"),
|
||||||
|
%get_url_field("date", upload_date_standardized),
|
||||||
|
|
||||||
|
%contains_url_field("year"),
|
||||||
|
%concat( %get_url_field("date", upload_year), "-01-01"),
|
||||||
|
|
||||||
|
upload_date_standardized
|
||||||
|
)
|
||||||
|
}
|
||||||
music_video_year: >-
|
music_video_year: >-
|
||||||
{ %int( %slice( music_video_date, 0, 4 ) ) }
|
{
|
||||||
|
%int(%elif(
|
||||||
|
%contains_url_field("date"),
|
||||||
|
%slice( %get_url_field("date", upload_date_standardized), 0, 4 ),
|
||||||
|
|
||||||
|
%contains_url_field("year"),
|
||||||
|
%get_url_field("date", upload_year),
|
||||||
|
|
||||||
|
upload_year
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Directory Overrides
|
# Directory Overrides
|
||||||
|
|
|
||||||
|
|
@ -143,10 +143,21 @@ class SubscriptionValueValidator(SubscriptionLeafValidator, StringValidator):
|
||||||
presets=presets,
|
presets=presets,
|
||||||
indent_overrides=indent_overrides,
|
indent_overrides=indent_overrides,
|
||||||
)
|
)
|
||||||
|
# subscription_value
|
||||||
self._overrides_to_add[SubscriptionVariables.subscription_value().variable_name] = (
|
self._overrides_to_add[SubscriptionVariables.subscription_value().variable_name] = (
|
||||||
self.value
|
self.value
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# subscription_value_0
|
||||||
|
self._overrides_to_add[
|
||||||
|
SubscriptionVariables.subscription_value_i(index=0).variable_name
|
||||||
|
] = self.value
|
||||||
|
|
||||||
|
# And the array variable
|
||||||
|
self._overrides_to_add[SubscriptionVariables.subscription_array().variable_name] = (
|
||||||
|
ScriptUtils.to_script([self.value])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionListValuesValidator(SubscriptionLeafValidator, StringListValidator):
|
class SubscriptionListValuesValidator(SubscriptionLeafValidator, StringListValidator):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -167,6 +178,7 @@ class SubscriptionListValuesValidator(SubscriptionLeafValidator, StringListValid
|
||||||
indent_overrides=indent_overrides,
|
indent_overrides=indent_overrides,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add indexed variables
|
||||||
for idx, list_value in enumerate(self.list):
|
for idx, list_value in enumerate(self.list):
|
||||||
# Write the first list value into subscription_value as well
|
# Write the first list value into subscription_value as well
|
||||||
if idx == 0:
|
if idx == 0:
|
||||||
|
|
@ -178,6 +190,11 @@ class SubscriptionListValuesValidator(SubscriptionLeafValidator, StringListValid
|
||||||
SubscriptionVariables.subscription_value_i(index=idx).variable_name
|
SubscriptionVariables.subscription_value_i(index=idx).variable_name
|
||||||
] = list_value.value
|
] = list_value.value
|
||||||
|
|
||||||
|
# And the array variable
|
||||||
|
self._overrides_to_add[SubscriptionVariables.subscription_array().variable_name] = (
|
||||||
|
ScriptUtils.to_script([list_value.value for list_value in self.list])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionWithOverridesValidator(SubscriptionLeafValidator, DictFormatterValidator):
|
class SubscriptionWithOverridesValidator(SubscriptionLeafValidator, DictFormatterValidator):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -220,7 +237,7 @@ class SubscriptionMapValidator(SubscriptionLeafValidator, LiteralDictValidator):
|
||||||
indent_overrides=indent_overrides,
|
indent_overrides=indent_overrides,
|
||||||
)
|
)
|
||||||
self._overrides_to_add[SubscriptionVariables.subscription_map().variable_name] = (
|
self._overrides_to_add[SubscriptionVariables.subscription_map().variable_name] = (
|
||||||
ScriptUtils.to_script(self.dict)
|
ScriptUtils.to_script(self.dict, sort_keys=False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class ScriptUtils:
|
||||||
return dict(variables, **sanitized_variables)
|
return dict(variables, **sanitized_variables)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def to_script(cls, value: Any) -> str:
|
def to_script(cls, value: Any, sort_keys: bool = True) -> str:
|
||||||
"""
|
"""
|
||||||
Converts a python value to a script value
|
Converts a python value to a script value
|
||||||
"""
|
"""
|
||||||
|
|
@ -50,7 +50,7 @@ class ScriptUtils:
|
||||||
elif isinstance(value, float):
|
elif isinstance(value, float):
|
||||||
out = f"{{%float({value})}}"
|
out = f"{{%float({value})}}"
|
||||||
else:
|
else:
|
||||||
dumped_json = json.dumps(value, ensure_ascii=False, sort_keys=True)
|
dumped_json = json.dumps(value, ensure_ascii=False, sort_keys=sort_keys)
|
||||||
# Remove triple-single-quotes from JSON to avoid parsing issues
|
# Remove triple-single-quotes from JSON to avoid parsing issues
|
||||||
dumped_json = re.sub("'{3,}", "'", dumped_json)
|
dumped_json = re.sub("'{3,}", "'", dumped_json)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -493,16 +493,31 @@ def test_music_video_subscriptions(default_config: ConfigFile, music_video_subsc
|
||||||
config=default_config, subscription_path=music_video_subscription_path
|
config=default_config, subscription_path=music_video_subscription_path
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(subs) == 3
|
assert len(subs) == 4
|
||||||
assert subs[1].name == "Michael Jackson"
|
assert subs[1].name == "Michael Jackson"
|
||||||
monk = subs[1].overrides.script
|
jackson = subs[1].overrides.script
|
||||||
|
|
||||||
assert monk.get("subscription_name").native == "Michael Jackson"
|
assert jackson.get("subscription_name").native == "Michael Jackson"
|
||||||
assert (
|
assert (
|
||||||
monk.get("subscription_value").native
|
jackson.get("subscription_value").native
|
||||||
== "https://www.youtube.com/playlist?list=OLAK5uy_mnY03zP6abNWH929q2XhGzWD_2uKJ_n8E"
|
== "https://www.youtube.com/playlist?list=OLAK5uy_mnY03zP6abNWH929q2XhGzWD_2uKJ_n8E"
|
||||||
)
|
)
|
||||||
assert monk.get("subscription_indent_1").native == "Pop"
|
assert jackson.get("subscription_indent_1").native == "Pop"
|
||||||
|
assert (
|
||||||
|
jackson.get("url").native
|
||||||
|
== "https://www.youtube.com/playlist?list=OLAK5uy_mnY03zP6abNWH929q2XhGzWD_2uKJ_n8E"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert subs[3].name == "Guns N' Roses"
|
||||||
|
gnr = subs[3].overrides.script
|
||||||
|
|
||||||
|
assert gnr.get("subscription_name").native == "Guns N' Roses"
|
||||||
|
assert (
|
||||||
|
gnr.get("url").native
|
||||||
|
== "https://www.youtube.com/playlist?list=PLOTK54q5K4INNXaHKtmXYr6J7CajWjqeJ"
|
||||||
|
)
|
||||||
|
assert gnr.get("subscription_indent_1").native == "Rock"
|
||||||
|
assert gnr.get("url2").native == "https://www.youtube.com/watch?v=OldpIhHPsbs"
|
||||||
|
|
||||||
|
|
||||||
def test_default_docker_config_and_subscriptions():
|
def test_default_docker_config_and_subscriptions():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue