setes
This commit is contained in:
parent
9d43849a64
commit
5f36531113
3 changed files with 28 additions and 23 deletions
|
|
@ -62,7 +62,10 @@ class YTDLOptions(UnstructuredOverridesDictFormatterValidator):
|
||||||
Materializes the entire ytdl-options dict from OverrideStringFormatters into
|
Materializes the entire ytdl-options dict from OverrideStringFormatters into
|
||||||
native python.
|
native python.
|
||||||
"""
|
"""
|
||||||
out = {key: overrides.apply_formatter(val) for key, val in self.dict.items()}
|
out = {
|
||||||
|
key: overrides.apply_formatter(val, expected_type=object)
|
||||||
|
for key, val in self.dict.items()
|
||||||
|
}
|
||||||
if "cookiefile" in out:
|
if "cookiefile" in out:
|
||||||
if not FileHandler.is_file_existent(out["cookiefile"]):
|
if not FileHandler.is_file_existent(out["cookiefile"]):
|
||||||
raise ValidationException(
|
raise ValidationException(
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,22 @@ class OverridesDictFormatterValidator(DictFormatterValidator):
|
||||||
_key_validator = OverridesStringFormatterValidator
|
_key_validator = OverridesStringFormatterValidator
|
||||||
|
|
||||||
|
|
||||||
|
class AnyFormatterValidator(StringFormatterValidator):
|
||||||
|
"""
|
||||||
|
Applies no post-processing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def post_process(self, resolved: Any) -> Any:
|
||||||
|
return resolved
|
||||||
|
|
||||||
|
|
||||||
|
class AnyOverridesFormatterValidator(AnyFormatterValidator, OverridesStringFormatterValidator):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UnstructuredDictFormatterValidator(DictFormatterValidator):
|
class UnstructuredDictFormatterValidator(DictFormatterValidator):
|
||||||
|
_key_validator = AnyFormatterValidator
|
||||||
|
|
||||||
def __init__(self, name, value):
|
def __init__(self, name, value):
|
||||||
# Convert the unstructured-ness into a script
|
# Convert the unstructured-ness into a script
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
|
|
@ -223,19 +238,7 @@ class UnstructuredDictFormatterValidator(DictFormatterValidator):
|
||||||
|
|
||||||
|
|
||||||
class UnstructuredOverridesDictFormatterValidator(UnstructuredDictFormatterValidator):
|
class UnstructuredOverridesDictFormatterValidator(UnstructuredDictFormatterValidator):
|
||||||
_key_validator = OverridesStringFormatterValidator
|
_key_validator = AnyOverridesFormatterValidator
|
||||||
|
|
||||||
|
|
||||||
def to_variable_dependency_format_string(script: Script, parsed_format_string: SyntaxTree) -> str:
|
|
||||||
"""
|
|
||||||
Create a dummy format string that contains all variable deps as a string.
|
|
||||||
"""
|
|
||||||
dummy_format_string = ""
|
|
||||||
for var in parsed_format_string.variables:
|
|
||||||
dummy_format_string += f"{{ {var.name} }}"
|
|
||||||
for variable_dependency in script._variables[var.name].variables:
|
|
||||||
dummy_format_string += f"{{ {variable_dependency.name} }}"
|
|
||||||
return dummy_format_string
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_formatter(
|
def _validate_formatter(
|
||||||
|
|
|
||||||
|
|
@ -82,13 +82,17 @@ class TestYtdlOptions:
|
||||||
default_config: ConfigFile,
|
default_config: ConfigFile,
|
||||||
output_directory: str,
|
output_directory: str,
|
||||||
):
|
):
|
||||||
|
expected = {
|
||||||
|
"break_on_existing": True,
|
||||||
|
"js_runtimes": {"deno": {"path": "/usr/local/bin/deno"}},
|
||||||
|
"string_path": "test",
|
||||||
|
"list_test": ["hmmm"],
|
||||||
|
}
|
||||||
|
|
||||||
preset_dict = {
|
preset_dict = {
|
||||||
"download": "https://your.name.here",
|
"download": "https://your.name.here",
|
||||||
"output_options": {"output_directory": output_directory, "file_name": "will_error.mp4"},
|
"output_options": {"output_directory": output_directory, "file_name": "will_error.mp4"},
|
||||||
"ytdl_options": {
|
"ytdl_options": expected,
|
||||||
"break_on_existing": True,
|
|
||||||
"js_runtimes": {"deno": {"path": "/usr/local/bin/deno"}},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub = Subscription.from_dict(
|
sub = Subscription.from_dict(
|
||||||
|
|
@ -97,10 +101,5 @@ class TestYtdlOptions:
|
||||||
preset_dict=preset_dict,
|
preset_dict=preset_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
expected = {
|
|
||||||
"break_on_existing": True,
|
|
||||||
"js_runtimes": {"deno": {"path": "/usr/local/bin/deno"}},
|
|
||||||
}
|
|
||||||
out = sub.ytdl_options.to_native_dict(sub.overrides)
|
out = sub.ytdl_options.to_native_dict(sub.overrides)
|
||||||
|
|
||||||
assert out == expected
|
assert out == expected
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue