more lint
This commit is contained in:
parent
bf0eafb04a
commit
4382591748
11 changed files with 38 additions and 7 deletions
|
|
@ -116,6 +116,7 @@ class VariableValidation:
|
|||
if added_variables:
|
||||
for added_variable in added_variables:
|
||||
if added_variable in self.resolved_variables:
|
||||
# pylint: disable=protected-access
|
||||
raise options._validation_exception(
|
||||
f"Tried added the variable '{added_variable}', but it already "
|
||||
f"exists as a defined variable."
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ class Entry(BaseEntry, Scriptable):
|
|||
self.update_script()
|
||||
|
||||
def initialize_script(self, other: Optional[Scriptable] = None) -> "Entry":
|
||||
"""
|
||||
Initializes the entry script using the Overrides script, then adding
|
||||
its kwargs to the entry metadata variable
|
||||
"""
|
||||
# Overrides contains added variables that are unresolvable, add them here
|
||||
if other:
|
||||
self.script = copy.deepcopy(other.script)
|
||||
|
|
@ -50,10 +54,16 @@ class Entry(BaseEntry, Scriptable):
|
|||
return self
|
||||
|
||||
def get(self, variable: Variable, expected_type: Type[TypeT]) -> TypeT:
|
||||
"""
|
||||
Gets a variable of an expected type. Will error if it does not exist or is not resolved.
|
||||
"""
|
||||
out = self.script.resolve(unresolvable=self.unresolvable).get_native(variable.variable_name)
|
||||
return expected_type(out)
|
||||
|
||||
def try_get(self, variable: Variable, expected_type: Type[TypeT]) -> Optional[TypeT]:
|
||||
"""
|
||||
Gets a variable of an expected type. Returns None if it does not exist or is not resolved.
|
||||
"""
|
||||
try:
|
||||
return self.get(variable=variable, expected_type=expected_type)
|
||||
except ScriptVariableNotResolved:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
|||
v: VariableDefinitions = VARIABLES
|
||||
|
||||
CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
|
||||
"%extract_field_from_metadata_array_getter": """{
|
||||
"%extract_field_from_metadata_array_getter": """{
|
||||
%map_get( %map(%array_at($0, 0)), %array_at($0, 1) )
|
||||
}""",
|
||||
"%extract_field_from_metadata_array": """{
|
||||
|
|
|
|||
|
|
@ -545,22 +545,37 @@ class VariableDefinitions:
|
|||
|
||||
@property
|
||||
def comments(self) -> MetadataVariable:
|
||||
"""
|
||||
Comments if they are requested
|
||||
"""
|
||||
return MetadataVariable("comments", "comments")
|
||||
|
||||
@property
|
||||
def chapters(self) -> MetadataVariable:
|
||||
"""
|
||||
Chapters if they exist
|
||||
"""
|
||||
return MetadataVariable("chapters", "chapters")
|
||||
|
||||
@property
|
||||
def sponsorblock_chapters(self) -> MetadataVariable:
|
||||
"""
|
||||
Sponsorblock Chapters if they are requested and exist
|
||||
"""
|
||||
return MetadataVariable("sponsorblock_chapters", "sponsorblock_chapters")
|
||||
|
||||
@property
|
||||
def requested_subtitles(self) -> MetadataVariable:
|
||||
"""
|
||||
Subtitles if they are requested and exist
|
||||
"""
|
||||
return MetadataVariable("requested_subtitles", "requested_subtitles")
|
||||
|
||||
@property
|
||||
def ytdl_sub_input_url(self) -> Variable:
|
||||
"""
|
||||
The input URL used in ytdl-sub to create this entry.
|
||||
"""
|
||||
return Variable("ytdl_sub_input_url")
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ def _get(
|
|||
# TODO: assert with good error message if key DNE
|
||||
out = f"%map_get({metadata.variable_name}, '{key.metadata_key}')"
|
||||
elif isinstance(default, Variable):
|
||||
out = f"%map_get_non_empty({metadata.variable_name}, '{key.metadata_key}', {default.variable_name})"
|
||||
args = f"{metadata.variable_name}, '{key.metadata_key}', {default.variable_name}"
|
||||
out = f"%map_get_non_empty({args})"
|
||||
elif isinstance(default, str):
|
||||
out = f"%map_get_non_empty({metadata.variable_name}, '{key.metadata_key}', '{default}')"
|
||||
elif isinstance(default, dict):
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ class Functions(
|
|||
def register_function(cls, function: Callable[..., Resolvable]) -> None:
|
||||
if cls.is_built_in(function.__name__):
|
||||
raise ValueError(
|
||||
f"Cannot register a function with name {function.__name__} because it already exists"
|
||||
f"Cannot register a function with name {function.__name__} "
|
||||
f"because it already exists"
|
||||
)
|
||||
cls._custom_functions[function.__name__] = function
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
|||
|
||||
|
||||
def _from_json(out: Any) -> Resolvable:
|
||||
# pylint: disable=too-many-return-statements
|
||||
if out is None:
|
||||
return String("")
|
||||
if isinstance(out, int):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
from typing import Optional
|
||||
|
||||
from yt_dlp.utils import sanitize_filename
|
||||
|
||||
from ytdl_sub.script.types.resolvable import AnyArgument
|
||||
from ytdl_sub.script.types.resolvable import Integer
|
||||
from ytdl_sub.script.types.resolvable import Numeric
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class Hashable(Resolvable, ABC):
|
|||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class NonHashable(ABC):
|
||||
class NonHashable(NamedType, ABC):
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -166,6 +166,7 @@ class BuiltInFunctionType(FunctionType, ABC):
|
|||
class Lambda(Resolvable):
|
||||
value: str
|
||||
|
||||
@property
|
||||
def native(self) -> Any:
|
||||
return f"%{self.value}"
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ class VariableDependency(ABC):
|
|||
-------
|
||||
Resolved value
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def _resolve_argument_type(
|
||||
|
|
|
|||
|
|
@ -95,6 +95,8 @@ class StringFormatterValidator(StringValidator):
|
|||
"""
|
||||
return self._value
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
|
||||
def post_process(self, resolved: str) -> str:
|
||||
"""
|
||||
Returns
|
||||
|
|
@ -103,6 +105,8 @@ class StringFormatterValidator(StringValidator):
|
|||
"""
|
||||
return resolved
|
||||
|
||||
# pylint: enable=no-self-use
|
||||
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
class OverridesStringFormatterValidator(StringFormatterValidator):
|
||||
|
|
|
|||
Loading…
Reference in a new issue