getting into real world
This commit is contained in:
parent
1d465a7d69
commit
a4920c03c3
7 changed files with 37 additions and 11 deletions
|
|
@ -109,7 +109,10 @@ class InfoJsonDownloader(SourcePlugin[InfoJsonDownloaderOptions]):
|
|||
prior_variables = entry.kwargs(YTDL_SUB_ENTRY_VARIABLES_KWARG_KEY)
|
||||
del entry._kwargs[YTDL_SUB_ENTRY_VARIABLES_KWARG_KEY]
|
||||
|
||||
entry.initialize_script(override_variables=self.overrides.dict_with_format_strings).add(
|
||||
entry.initialize_script(
|
||||
override_variables=self.overrides.dict_with_format_strings,
|
||||
unresolvable=self.overrides.unresolvable,
|
||||
).add(
|
||||
{
|
||||
inj.variable_name: prior_variables.get(
|
||||
inj.variable_name,
|
||||
|
|
|
|||
|
|
@ -460,7 +460,8 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
|
|||
url_validator=collection_url, parents=parents, orphans=orphan_entries
|
||||
):
|
||||
entry.initialize_script(
|
||||
override_variables=self.overrides.dict_with_format_strings
|
||||
override_variables=self.overrides.dict_with_format_strings,
|
||||
unresolvable=self.overrides.unresolvable,
|
||||
).add(
|
||||
{
|
||||
v.ytdl_sub_input_url.variable_name: self.overrides.apply_formatter(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import os
|
|||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from typing import Optional
|
||||
from typing import Set
|
||||
from typing import Type
|
||||
from typing import TypeVar
|
||||
from typing import final
|
||||
|
|
@ -29,8 +30,26 @@ class Entry(BaseEntry, Scriptable):
|
|||
BaseEntry.__init__(self, entry_dict=entry_dict, working_directory=working_directory)
|
||||
Scriptable.__init__(self)
|
||||
|
||||
def initialize_script(self, override_variables: Dict[str, str]) -> "Entry":
|
||||
def initialize_script(
|
||||
self, override_variables: Dict[str, str], unresolvable: Set[str]
|
||||
) -> "Entry":
|
||||
# TODO: CLEAN THIS SHIT UP
|
||||
# Overrides contains added variables that are unresolvable, add them here
|
||||
self.unresolvable |= unresolvable
|
||||
|
||||
# Remove the entry variable
|
||||
self.unresolvable.remove(VARIABLES.entry_metadata.variable_name)
|
||||
|
||||
# Add entry metadata, but avoid the `.add()` helper since it also adds sanitized
|
||||
self.script.add({VARIABLES.entry_metadata.variable_name: f"{{{json.dumps(self._kwargs)}}}"})
|
||||
self.script.add(
|
||||
{
|
||||
unresolved: f"{{%throw('Variable {unresolved} has not been resolved yet')}}"
|
||||
for unresolved in self.unresolvable
|
||||
}
|
||||
)
|
||||
|
||||
# use .add here to get sanitized
|
||||
self.add(override_variables)
|
||||
self.update_script()
|
||||
return self
|
||||
|
|
|
|||
|
|
@ -354,14 +354,16 @@ class Script:
|
|||
pre_resolved=resolved, unresolvable=unresolvable, update=update, output_filter=None
|
||||
)
|
||||
|
||||
def add(self, variables: Dict[str, str]) -> "Script":
|
||||
def add(self, variables: Dict[str, str], unresolvable: Optional[Set[str]] = None) -> "Script":
|
||||
added_variables_to_validate: Set[str] = set()
|
||||
for variable_name, variable_definition in variables.items():
|
||||
self._variables[variable_name] = parse(
|
||||
text=variable_definition,
|
||||
name=variable_name,
|
||||
custom_function_names=set(self._functions.keys()),
|
||||
variable_names=set(self._variables.keys()).union(variables.keys()),
|
||||
variable_names=set(self._variables.keys())
|
||||
.union(variables.keys())
|
||||
.union(unresolvable or set()),
|
||||
)
|
||||
|
||||
if self._variables[variable_name].maybe_resolvable is None:
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ class Scriptable(ABC):
|
|||
self.script.resolve(unresolvable=self.unresolvable, update=True)
|
||||
|
||||
def add(self, values: Dict[str, Any]) -> None:
|
||||
self.unresolvable -= set(list(values.keys()))
|
||||
self.script.add(
|
||||
ScriptUtils.add_sanitized_variables(
|
||||
{name: ScriptUtils.to_script(value) for name, value in values.items()}
|
||||
)
|
||||
),
|
||||
unresolvable=self.unresolvable,
|
||||
)
|
||||
|
||||
self.unresolvable -= set(list(values.keys()))
|
||||
self.update_script()
|
||||
|
|
|
|||
|
|
@ -179,5 +179,6 @@ def mock_entry_kwargs(
|
|||
@pytest.fixture
|
||||
def mock_entry(mock_entry_kwargs):
|
||||
return Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script(
|
||||
override_variables={}
|
||||
override_variables={},
|
||||
unresolvable=set(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TestEntry(object):
|
|||
|
||||
mock_entry_kwargs["upload_date"] = upload_date
|
||||
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script(
|
||||
override_variables={}
|
||||
override_variables={}, unresolvable=set()
|
||||
)
|
||||
assert entry.get_int(v.upload_year_truncated_reversed) == year_rev
|
||||
assert entry.get_int(v.upload_month_reversed) == month_rev
|
||||
|
|
@ -58,7 +58,7 @@ class TestEntry(object):
|
|||
):
|
||||
mock_entry_kwargs["upload_date"] = upload_date
|
||||
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script(
|
||||
override_variables={}
|
||||
override_variables={}, unresolvable=set()
|
||||
)
|
||||
|
||||
assert entry.get_int(v.upload_day_of_year) == day_year
|
||||
|
|
|
|||
Loading…
Reference in a new issue