fixed?
This commit is contained in:
parent
64f6a412c0
commit
ba147e0cda
2 changed files with 72 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ from abc import ABC
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
|
from ytdl_sub.entries.script.custom_functions import CustomFunctions
|
||||||
from ytdl_sub.entries.script.variable_types import ArrayMetadataVariable
|
from ytdl_sub.entries.script.variable_types import ArrayMetadataVariable
|
||||||
from ytdl_sub.entries.script.variable_types import IntegerMetadataVariable
|
from ytdl_sub.entries.script.variable_types import IntegerMetadataVariable
|
||||||
from ytdl_sub.entries.script.variable_types import IntegerVariable
|
from ytdl_sub.entries.script.variable_types import IntegerVariable
|
||||||
|
|
@ -15,6 +16,7 @@ from ytdl_sub.entries.script.variable_types import StringVariable
|
||||||
# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion
|
# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
|
# pylint: disable=too-many-lines
|
||||||
|
|
||||||
|
|
||||||
class MetadataVariableDefinitions(ABC):
|
class MetadataVariableDefinitions(ABC):
|
||||||
|
|
@ -62,7 +64,9 @@ class PlaylistVariableDefinitions(ABC):
|
||||||
"""
|
"""
|
||||||
The playlist unique ID if it exists, otherwise return the entry unique ID.
|
The playlist unique ID if it exists, otherwise return the entry unique ID.
|
||||||
"""
|
"""
|
||||||
return StringMetadataVariable.from_playlist(metadata_key="playlist_id", default=self.uid)
|
return StringMetadataVariable.from_playlist(
|
||||||
|
metadata_key="playlist_id", variable_name="playlist_uid", default=self.uid
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def playlist_title(self: "VariableDefinitions") -> StringMetadataVariable:
|
def playlist_title(self: "VariableDefinitions") -> StringMetadataVariable:
|
||||||
|
|
@ -209,7 +213,10 @@ class PlaylistVariableDefinitions(ABC):
|
||||||
"""
|
"""
|
||||||
The playlist uploader id if it exists, otherwise returns the entry uploader ID.
|
The playlist uploader id if it exists, otherwise returns the entry uploader ID.
|
||||||
"""
|
"""
|
||||||
return StringMetadataVariable.from_entry(metadata_key="playlist_uploader_id")
|
return StringMetadataVariable.from_entry(
|
||||||
|
metadata_key="playlist_uploader_id",
|
||||||
|
default=self.uploader_id,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def playlist_uploader(self: "VariableDefinitions") -> StringMetadataVariable:
|
def playlist_uploader(self: "VariableDefinitions") -> StringMetadataVariable:
|
||||||
|
|
@ -296,7 +303,9 @@ class SourceVariableDefinitions(ABC):
|
||||||
The source webpage url if it exists, otherwise returns the playlist webpage url.
|
The source webpage url if it exists, otherwise returns the playlist webpage url.
|
||||||
"""
|
"""
|
||||||
return StringMetadataVariable.from_source(
|
return StringMetadataVariable.from_source(
|
||||||
metadata_key=self.webpage_url.metadata_key, variable_name="source_webpage_url"
|
metadata_key=self.webpage_url.metadata_key,
|
||||||
|
variable_name="source_webpage_url",
|
||||||
|
default=self.playlist_webpage_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -740,14 +749,15 @@ class EntryVariableDefinitions(ABC):
|
||||||
The sanitized uid with additional sanitizing for Plex. Replaces numbers with
|
The sanitized uid with additional sanitizing for Plex. Replaces numbers with
|
||||||
fixed-width numbers so Plex does not recognize them as season or episode numbers.
|
fixed-width numbers so Plex does not recognize them as season or episode numbers.
|
||||||
"""
|
"""
|
||||||
return self.uid.to_sanitized_plex("uid_sanitized_plex")
|
return self.uid.to_sanitized_plex(variable_name="uid_sanitized_plex")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ie_key(self: "VariableDefinitions") -> StringMetadataVariable:
|
def ie_key(self: "VariableDefinitions") -> StringMetadataVariable:
|
||||||
"""
|
"""
|
||||||
The ie_key, used in legacy yt-dlp things as the 'info-extractor key'
|
The ie_key, used in legacy yt-dlp things as the 'info-extractor key'.
|
||||||
|
If it does not exist, return ``extractor_key``
|
||||||
"""
|
"""
|
||||||
return StringMetadataVariable.from_entry(metadata_key="ie_key")
|
return StringMetadataVariable.from_entry(metadata_key="ie_key", default=self.extractor_key)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extractor_key(self: "VariableDefinitions") -> StringMetadataVariable:
|
def extractor_key(self: "VariableDefinitions") -> StringMetadataVariable:
|
||||||
|
|
@ -962,6 +972,9 @@ class VariableDefinitions(
|
||||||
):
|
):
|
||||||
@classmethod
|
@classmethod
|
||||||
def scripts(cls) -> Dict[str, str]:
|
def scripts(cls) -> Dict[str, str]:
|
||||||
|
"""
|
||||||
|
Returns all variables and their scripts in dict form
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
property_name: getattr(VARIABLES, property_name).definition
|
property_name: getattr(VARIABLES, property_name).definition
|
||||||
for property_name in [
|
for property_name in [
|
||||||
|
|
@ -971,6 +984,9 @@ class VariableDefinitions(
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def injected_variables(cls) -> Set[MetadataVariable]:
|
def injected_variables(cls) -> Set[MetadataVariable]:
|
||||||
|
"""
|
||||||
|
Returns variables that get injected in the download-stage
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
VARIABLES.download_index,
|
VARIABLES.download_index,
|
||||||
VARIABLES.comments,
|
VARIABLES.comments,
|
||||||
|
|
@ -982,6 +998,9 @@ class VariableDefinitions(
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def required_entry_variables(cls) -> Set[MetadataVariable]:
|
def required_entry_variables(cls) -> Set[MetadataVariable]:
|
||||||
|
"""
|
||||||
|
Returns variables that the entry requires to exist
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
VARIABLES.uid,
|
VARIABLES.uid,
|
||||||
VARIABLES.extractor_key,
|
VARIABLES.extractor_key,
|
||||||
|
|
@ -992,6 +1011,10 @@ class VariableDefinitions(
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def default_entry_variables(cls) -> Set[MetadataVariable]:
|
def default_entry_variables(cls) -> Set[MetadataVariable]:
|
||||||
|
"""
|
||||||
|
Returns variables that reside on the entry that may or may not exist,
|
||||||
|
but have defaults
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
VARIABLES.title,
|
VARIABLES.title,
|
||||||
VARIABLES.extractor,
|
VARIABLES.extractor,
|
||||||
|
|
@ -1015,6 +1038,9 @@ class VariableDefinitions(
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unresolvable_static_variables(cls) -> Set[str]:
|
def unresolvable_static_variables(cls) -> Set[str]:
|
||||||
|
"""
|
||||||
|
Returns variables that are not static (i.e. depend on runtime)
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
VARIABLES.entry_metadata.variable_name,
|
VARIABLES.entry_metadata.variable_name,
|
||||||
} | cls.injected_variables()
|
} | cls.injected_variables()
|
||||||
|
|
@ -1024,3 +1050,5 @@ class VariableDefinitions(
|
||||||
VARIABLES: VariableDefinitions = VariableDefinitions()
|
VARIABLES: VariableDefinitions = VariableDefinitions()
|
||||||
VARIABLE_SCRIPTS: Dict[str, str] = VariableDefinitions.scripts()
|
VARIABLE_SCRIPTS: Dict[str, str] = VariableDefinitions.scripts()
|
||||||
UNRESOLVED_VARIABLES: Set[str] = VariableDefinitions.unresolvable_static_variables()
|
UNRESOLVED_VARIABLES: Set[str] = VariableDefinitions.unresolvable_static_variables()
|
||||||
|
|
||||||
|
CustomFunctions.register()
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ PLAYLIST_METADATA_VARIABLE_NAME = "playlist_metadata"
|
||||||
SOURCE_METADATA_VARIABLE_NAME = "source_metadata"
|
SOURCE_METADATA_VARIABLE_NAME = "source_metadata"
|
||||||
|
|
||||||
TMetadataVariable = TypeVar("TMetadataVariable", bound="MetadataVariable")
|
TMetadataVariable = TypeVar("TMetadataVariable", bound="MetadataVariable")
|
||||||
|
TVariable = TypeVar("TVariable", bound="Variable")
|
||||||
|
|
||||||
|
|
||||||
def _get(
|
def _get(
|
||||||
|
|
@ -24,7 +25,7 @@ def _get(
|
||||||
metadata_variable_name: str,
|
metadata_variable_name: str,
|
||||||
metadata_key: str,
|
metadata_key: str,
|
||||||
variable_name: Optional[str],
|
variable_name: Optional[str],
|
||||||
default: Optional["Variable" | str | int | Dict | List],
|
default: Optional[TVariable | str | int | Dict | List],
|
||||||
as_type: Type[TMetadataVariable],
|
as_type: Type[TMetadataVariable],
|
||||||
) -> TMetadataVariable:
|
) -> TMetadataVariable:
|
||||||
if default is None:
|
if default is None:
|
||||||
|
|
@ -69,12 +70,18 @@ class StringVariable(Variable):
|
||||||
return String.__name__
|
return String.__name__
|
||||||
|
|
||||||
def to_sanitized_plex(self, variable_name: str) -> "StringVariable":
|
def to_sanitized_plex(self, variable_name: str) -> "StringVariable":
|
||||||
|
"""
|
||||||
|
Converts a String variable to be plex sanitized
|
||||||
|
"""
|
||||||
return StringVariable(
|
return StringVariable(
|
||||||
variable_name=variable_name,
|
variable_name=variable_name,
|
||||||
definition=f"{{%sanitize_plex_episode({self.variable_name})}}",
|
definition=f"{{%sanitize_plex_episode({self.variable_name})}}",
|
||||||
)
|
)
|
||||||
|
|
||||||
def as_date_variable(self) -> "StringDateVariable":
|
def as_date_variable(self) -> "StringDateVariable":
|
||||||
|
"""
|
||||||
|
Converts a String variable to a date variable (which has metadata helpers)
|
||||||
|
"""
|
||||||
return StringDateVariable(
|
return StringDateVariable(
|
||||||
variable_name=self.variable_name,
|
variable_name=self.variable_name,
|
||||||
definition=self.definition,
|
definition=self.definition,
|
||||||
|
|
@ -86,6 +93,9 @@ class StringDateVariable(StringVariable):
|
||||||
def get_string_date_metadata(
|
def get_string_date_metadata(
|
||||||
self, date_metadata_key: str, variable_name: Optional[str] = None
|
self, date_metadata_key: str, variable_name: Optional[str] = None
|
||||||
) -> StringVariable:
|
) -> StringVariable:
|
||||||
|
"""
|
||||||
|
Gets a string-based date metadata variable
|
||||||
|
"""
|
||||||
return StringVariable(
|
return StringVariable(
|
||||||
variable_name=variable_name or date_metadata_key,
|
variable_name=variable_name or date_metadata_key,
|
||||||
definition=f"""{{
|
definition=f"""{{
|
||||||
|
|
@ -101,6 +111,9 @@ class StringDateVariable(StringVariable):
|
||||||
def get_integer_date_metadata(
|
def get_integer_date_metadata(
|
||||||
self, date_metadata_key: str, variable_name: str
|
self, date_metadata_key: str, variable_name: str
|
||||||
) -> "IntegerVariable":
|
) -> "IntegerVariable":
|
||||||
|
"""
|
||||||
|
Gets an int-based date metadata variable
|
||||||
|
"""
|
||||||
return IntegerVariable(
|
return IntegerVariable(
|
||||||
variable_name=variable_name,
|
variable_name=variable_name,
|
||||||
definition=f"""{{
|
definition=f"""{{
|
||||||
|
|
@ -121,6 +134,9 @@ class IntegerVariable(Variable):
|
||||||
return Integer.__name__
|
return Integer.__name__
|
||||||
|
|
||||||
def to_padded_int(self, variable_name: str, pad: int) -> StringVariable:
|
def to_padded_int(self, variable_name: str, pad: int) -> StringVariable:
|
||||||
|
"""
|
||||||
|
Pads an integer
|
||||||
|
"""
|
||||||
return StringVariable(
|
return StringVariable(
|
||||||
variable_name=variable_name, definition=f"{{%pad_zero({self.variable_name}, {pad})}}"
|
variable_name=variable_name, definition=f"{{%pad_zero({self.variable_name}, {pad})}}"
|
||||||
)
|
)
|
||||||
|
|
@ -154,6 +170,9 @@ class MapMetadataVariable(MetadataVariable, MapVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional["MapMetadataVariable" | Dict] = None,
|
default: Optional["MapMetadataVariable" | Dict] = None,
|
||||||
) -> "MapMetadataVariable":
|
) -> "MapMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates a map variable from entry metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"map",
|
"map",
|
||||||
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
||||||
|
|
@ -173,6 +192,9 @@ class ArrayMetadataVariable(MetadataVariable, ArrayVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional["ArrayMetadataVariable" | List] = None,
|
default: Optional["ArrayMetadataVariable" | List] = None,
|
||||||
) -> "ArrayMetadataVariable":
|
) -> "ArrayMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates an array variable from entry metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"array",
|
"array",
|
||||||
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
||||||
|
|
@ -192,6 +214,9 @@ class StringMetadataVariable(MetadataVariable, StringVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional[StringVariable | str] = None,
|
default: Optional[StringVariable | str] = None,
|
||||||
) -> "StringMetadataVariable":
|
) -> "StringMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates a string variable from entry metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"string",
|
"string",
|
||||||
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
||||||
|
|
@ -208,6 +233,9 @@ class StringMetadataVariable(MetadataVariable, StringVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional[StringVariable | str] = None,
|
default: Optional[StringVariable | str] = None,
|
||||||
) -> "StringMetadataVariable":
|
) -> "StringMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates a string variable from playlist metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"string",
|
"string",
|
||||||
metadata_variable_name=PLAYLIST_METADATA_VARIABLE_NAME,
|
metadata_variable_name=PLAYLIST_METADATA_VARIABLE_NAME,
|
||||||
|
|
@ -224,6 +252,9 @@ class StringMetadataVariable(MetadataVariable, StringVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional[StringVariable | str] = None,
|
default: Optional[StringVariable | str] = None,
|
||||||
) -> "StringMetadataVariable":
|
) -> "StringMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates a string variable from source metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"string",
|
"string",
|
||||||
metadata_variable_name=SOURCE_METADATA_VARIABLE_NAME,
|
metadata_variable_name=SOURCE_METADATA_VARIABLE_NAME,
|
||||||
|
|
@ -243,6 +274,9 @@ class IntegerMetadataVariable(MetadataVariable, IntegerVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional[IntegerVariable | int] = None,
|
default: Optional[IntegerVariable | int] = None,
|
||||||
) -> "IntegerMetadataVariable":
|
) -> "IntegerMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates an int variable from entry metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"int",
|
"int",
|
||||||
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
metadata_variable_name=ENTRY_METADATA_VARIABLE_NAME,
|
||||||
|
|
@ -259,6 +293,9 @@ class IntegerMetadataVariable(MetadataVariable, IntegerVariable):
|
||||||
variable_name: Optional[str] = None,
|
variable_name: Optional[str] = None,
|
||||||
default: Optional[IntegerVariable | int] = None,
|
default: Optional[IntegerVariable | int] = None,
|
||||||
) -> "IntegerMetadataVariable":
|
) -> "IntegerMetadataVariable":
|
||||||
|
"""
|
||||||
|
Creates an int variable from playlist metadata
|
||||||
|
"""
|
||||||
return _get(
|
return _get(
|
||||||
"int",
|
"int",
|
||||||
metadata_variable_name=PLAYLIST_METADATA_VARIABLE_NAME,
|
metadata_variable_name=PLAYLIST_METADATA_VARIABLE_NAME,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue