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:
|
if added_variables:
|
||||||
for added_variable in added_variables:
|
for added_variable in added_variables:
|
||||||
if added_variable in self.resolved_variables:
|
if added_variable in self.resolved_variables:
|
||||||
|
# pylint: disable=protected-access
|
||||||
raise options._validation_exception(
|
raise options._validation_exception(
|
||||||
f"Tried added the variable '{added_variable}', but it already "
|
f"Tried added the variable '{added_variable}', but it already "
|
||||||
f"exists as a defined variable."
|
f"exists as a defined variable."
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ class Entry(BaseEntry, Scriptable):
|
||||||
self.update_script()
|
self.update_script()
|
||||||
|
|
||||||
def initialize_script(self, other: Optional[Scriptable] = None) -> "Entry":
|
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
|
# Overrides contains added variables that are unresolvable, add them here
|
||||||
if other:
|
if other:
|
||||||
self.script = copy.deepcopy(other.script)
|
self.script = copy.deepcopy(other.script)
|
||||||
|
|
@ -50,10 +54,16 @@ class Entry(BaseEntry, Scriptable):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get(self, variable: Variable, expected_type: Type[TypeT]) -> TypeT:
|
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)
|
out = self.script.resolve(unresolvable=self.unresolvable).get_native(variable.variable_name)
|
||||||
return expected_type(out)
|
return expected_type(out)
|
||||||
|
|
||||||
def try_get(self, variable: Variable, expected_type: Type[TypeT]) -> Optional[TypeT]:
|
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:
|
try:
|
||||||
return self.get(variable=variable, expected_type=expected_type)
|
return self.get(variable=variable, expected_type=expected_type)
|
||||||
except ScriptVariableNotResolved:
|
except ScriptVariableNotResolved:
|
||||||
|
|
|
||||||
|
|
@ -545,22 +545,37 @@ class VariableDefinitions:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def comments(self) -> MetadataVariable:
|
def comments(self) -> MetadataVariable:
|
||||||
|
"""
|
||||||
|
Comments if they are requested
|
||||||
|
"""
|
||||||
return MetadataVariable("comments", "comments")
|
return MetadataVariable("comments", "comments")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chapters(self) -> MetadataVariable:
|
def chapters(self) -> MetadataVariable:
|
||||||
|
"""
|
||||||
|
Chapters if they exist
|
||||||
|
"""
|
||||||
return MetadataVariable("chapters", "chapters")
|
return MetadataVariable("chapters", "chapters")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sponsorblock_chapters(self) -> MetadataVariable:
|
def sponsorblock_chapters(self) -> MetadataVariable:
|
||||||
|
"""
|
||||||
|
Sponsorblock Chapters if they are requested and exist
|
||||||
|
"""
|
||||||
return MetadataVariable("sponsorblock_chapters", "sponsorblock_chapters")
|
return MetadataVariable("sponsorblock_chapters", "sponsorblock_chapters")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def requested_subtitles(self) -> MetadataVariable:
|
def requested_subtitles(self) -> MetadataVariable:
|
||||||
|
"""
|
||||||
|
Subtitles if they are requested and exist
|
||||||
|
"""
|
||||||
return MetadataVariable("requested_subtitles", "requested_subtitles")
|
return MetadataVariable("requested_subtitles", "requested_subtitles")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ytdl_sub_input_url(self) -> Variable:
|
def ytdl_sub_input_url(self) -> Variable:
|
||||||
|
"""
|
||||||
|
The input URL used in ytdl-sub to create this entry.
|
||||||
|
"""
|
||||||
return Variable("ytdl_sub_input_url")
|
return Variable("ytdl_sub_input_url")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ def _get(
|
||||||
# TODO: assert with good error message if key DNE
|
# TODO: assert with good error message if key DNE
|
||||||
out = f"%map_get({metadata.variable_name}, '{key.metadata_key}')"
|
out = f"%map_get({metadata.variable_name}, '{key.metadata_key}')"
|
||||||
elif isinstance(default, Variable):
|
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):
|
elif isinstance(default, str):
|
||||||
out = f"%map_get_non_empty({metadata.variable_name}, '{key.metadata_key}', '{default}')"
|
out = f"%map_get_non_empty({metadata.variable_name}, '{key.metadata_key}', '{default}')"
|
||||||
elif isinstance(default, dict):
|
elif isinstance(default, dict):
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ class Functions(
|
||||||
def register_function(cls, function: Callable[..., Resolvable]) -> None:
|
def register_function(cls, function: Callable[..., Resolvable]) -> None:
|
||||||
if cls.is_built_in(function.__name__):
|
if cls.is_built_in(function.__name__):
|
||||||
raise ValueError(
|
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
|
cls._custom_functions[function.__name__] = function
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||||
|
|
||||||
|
|
||||||
def _from_json(out: Any) -> Resolvable:
|
def _from_json(out: Any) -> Resolvable:
|
||||||
|
# pylint: disable=too-many-return-statements
|
||||||
if out is None:
|
if out is None:
|
||||||
return String("")
|
return String("")
|
||||||
if isinstance(out, int):
|
if isinstance(out, int):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
from typing import Optional
|
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 AnyArgument
|
||||||
from ytdl_sub.script.types.resolvable import Integer
|
from ytdl_sub.script.types.resolvable import Integer
|
||||||
from ytdl_sub.script.types.resolvable import Numeric
|
from ytdl_sub.script.types.resolvable import Numeric
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ class Hashable(Resolvable, ABC):
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class NonHashable(ABC):
|
class NonHashable(NamedType, ABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -166,6 +166,7 @@ class BuiltInFunctionType(FunctionType, ABC):
|
||||||
class Lambda(Resolvable):
|
class Lambda(Resolvable):
|
||||||
value: str
|
value: str
|
||||||
|
|
||||||
|
@property
|
||||||
def native(self) -> Any:
|
def native(self) -> Any:
|
||||||
return f"%{self.value}"
|
return f"%{self.value}"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,6 @@ class VariableDependency(ABC):
|
||||||
-------
|
-------
|
||||||
Resolved value
|
Resolved value
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _resolve_argument_type(
|
def _resolve_argument_type(
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,8 @@ class StringFormatterValidator(StringValidator):
|
||||||
"""
|
"""
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
|
|
||||||
def post_process(self, resolved: str) -> str:
|
def post_process(self, resolved: str) -> str:
|
||||||
"""
|
"""
|
||||||
Returns
|
Returns
|
||||||
|
|
@ -103,6 +105,8 @@ class StringFormatterValidator(StringValidator):
|
||||||
"""
|
"""
|
||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
|
# pylint: enable=no-self-use
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=line-too-long
|
# pylint: disable=line-too-long
|
||||||
class OverridesStringFormatterValidator(StringFormatterValidator):
|
class OverridesStringFormatterValidator(StringFormatterValidator):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue