all except one
This commit is contained in:
parent
3086318d9a
commit
97c2a66fbd
4 changed files with 369 additions and 279 deletions
|
|
@ -48,7 +48,7 @@ class CustomFunctions:
|
|||
return String(out)
|
||||
|
||||
@staticmethod
|
||||
def date_metadata(yyyymmdd: String) -> Map:
|
||||
def to_date_metadata(yyyymmdd: String) -> Map:
|
||||
date_str = yyyymmdd.value
|
||||
if not (date_str.isnumeric() and len(date_str) == 6):
|
||||
raise RuntimeException(
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,60 +1,99 @@
|
|||
from typing import Dict
|
||||
from typing import Optional
|
||||
|
||||
from ytdl_sub.entries.script.variable_definitions import KwargKey
|
||||
from ytdl_sub.entries.script.variable_definitions import Variables
|
||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
|
||||
from ytdl_sub.entries.script.variable_definitions import Metadata
|
||||
from ytdl_sub.entries.script.variable_definitions import MetadataVariable
|
||||
from ytdl_sub.entries.script.variable_definitions import Variable
|
||||
|
||||
ENTRY_MAP_VARIABLE = "entry_metadata"
|
||||
PLAYLIST_MAP_VARIABLE = "playlist_metadata"
|
||||
SOURCE_MAP_VARIABLE = "source_metadata"
|
||||
###############################################################################################
|
||||
# Helpers
|
||||
|
||||
|
||||
def _entry_get(key: KwargKey, default: Optional[KwargKey | str | int]) -> str:
|
||||
if default is None:
|
||||
# TODO: assert with good error message if key DNE
|
||||
return f"%map_get({ENTRY_MAP_VARIABLE}, '{key.entry_key}')"
|
||||
if isinstance(default, KwargKey):
|
||||
return f"%map_get({ENTRY_MAP_VARIABLE}, '{key.entry_key}', {default.variable_name})"
|
||||
if isinstance(default, str):
|
||||
return f"%map_get({ENTRY_MAP_VARIABLE}, '{key.entry_key}', '{default}')"
|
||||
|
||||
return f"%map_get({ENTRY_MAP_VARIABLE}, '{key.entry_key}', {default})"
|
||||
|
||||
|
||||
def entry_get(key: KwargKey, default: Optional[KwargKey | str | int] = None) -> str:
|
||||
return f"{{{_entry_get(key=key, default=default)}}}"
|
||||
|
||||
|
||||
def entry_get_int(key: KwargKey, default: Optional[KwargKey] = None) -> str:
|
||||
return f"{{%int({_entry_get(key=key, default=default)}}}"
|
||||
|
||||
|
||||
def pad_int(key: KwargKey, pad: int) -> str:
|
||||
def pad_int(key: Variable, pad: int) -> str:
|
||||
return f"{{%pad_zero({key.variable_name}, {pad})}}"
|
||||
|
||||
|
||||
def sanitized(key: KwargKey) -> str:
|
||||
def sanitized(key: Variable) -> str:
|
||||
return f"{{%sanitize({key.variable_name})}}"
|
||||
|
||||
|
||||
def sanitized_plex(key: KwargKey) -> str:
|
||||
def sanitized_plex(key: Variable) -> str:
|
||||
return f"{{%sanitize_plex_episode({key.variable_name})}}"
|
||||
|
||||
|
||||
def date_metadata(date_key: KwargKey, metadata_key: str) -> str:
|
||||
return f"{{%map_get(%date_metadata({date_key.variable_name}), '{metadata_key}')}}"
|
||||
def date_metadata(date_key: Variable, metadata_key: str) -> str:
|
||||
return f"{{%map_get(%to_date_metadata({date_key.variable_name}), '{metadata_key}')}}"
|
||||
|
||||
|
||||
# singleton to produce variable keys
|
||||
v = Variables()
|
||||
###############################################################################################
|
||||
# Metadata Getters
|
||||
|
||||
|
||||
ENTRY_HARDCODED_VARIABLES: Dict[KwargKey, str] = {
|
||||
def _get(metadata: Metadata, key: MetadataVariable, default: Optional[Variable | str | int]) -> str:
|
||||
if default is None:
|
||||
# TODO: assert with good error message if key DNE
|
||||
return f"%map_get({metadata.variable_name}, '{key.metadata_key}')"
|
||||
if isinstance(default, Variable):
|
||||
return f"%map_get({metadata.variable_name}, '{key.metadata_key}', {default.variable_name})"
|
||||
if isinstance(default, str):
|
||||
return f"%map_get({metadata.variable_name}, '{key.metadata_key}', '{default}')"
|
||||
|
||||
return f"%map_get({metadata.variable_name}, '{key.metadata_key}', {default})"
|
||||
|
||||
|
||||
def _get_int(
|
||||
metadata: Metadata, key: MetadataVariable, default: Optional[Variable | int] = None
|
||||
) -> str:
|
||||
return f"{{%int({_get(metadata=metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
###############################################################################################
|
||||
# Entry Getters
|
||||
|
||||
|
||||
def entry_get(key: MetadataVariable, default: Optional[Variable | str | int] = None) -> str:
|
||||
return f"{{{_get(metadata=v.entry_metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
def entry_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
||||
return f"{{%int({_get_int(metadata=v.entry_metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
###############################################################################################
|
||||
# Playlist Getters
|
||||
|
||||
|
||||
def playlist_get(key: MetadataVariable, default: Optional[Variable | str | int] = None) -> str:
|
||||
return f"{{{_get(metadata=v.playlist_metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
def playlist_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
||||
return f"{{%int({_get_int(metadata=v.playlist_metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
###############################################################################################
|
||||
# Source Getters
|
||||
|
||||
|
||||
def source_get(key: MetadataVariable, default: Optional[Variable | str | int] = None) -> str:
|
||||
return f"{{{_get(metadata=v.source_metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
def source_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
||||
return f"{{%int({_get_int(metadata=v.source_metadata, key=key, default=default)}}}"
|
||||
|
||||
|
||||
###############################################################################################
|
||||
# Scripts
|
||||
|
||||
|
||||
ENTRY_HARDCODED_VARIABLES: Dict[Variable, str] = {
|
||||
v.info_json_ext: "info.json",
|
||||
v.thumbnail_ext: "jpg",
|
||||
}
|
||||
|
||||
ENTRY_REQUIRED_VARIABLES: Dict[KwargKey, str] = {
|
||||
ENTRY_REQUIRED_VARIABLES: Dict[MetadataVariable, str] = {
|
||||
v.uid: entry_get(v.uid),
|
||||
v.ie_key: entry_get(v.ie_key),
|
||||
v.epoch: entry_get_int(v.epoch),
|
||||
|
|
@ -62,41 +101,42 @@ ENTRY_REQUIRED_VARIABLES: Dict[KwargKey, str] = {
|
|||
v.ext: entry_get(v.ext),
|
||||
}
|
||||
|
||||
ENTRY_DEFAULT_VARIABLES: Dict[KwargKey, str] = {
|
||||
ENTRY_DEFAULT_VARIABLES: Dict[MetadataVariable, str] = {
|
||||
v.playlist_index: playlist_get_int(v.playlist_index, 1),
|
||||
v.title: entry_get(v.title, v.uid),
|
||||
v.extractor: entry_get(v.extractor, v.ie_key),
|
||||
v.description: entry_get(v.description, ""),
|
||||
v.uploader_id: entry_get(v.uploader_id, v.uid),
|
||||
v.uploader: entry_get(v.uploader, v.uploader_id),
|
||||
v.uploader_url: entry_get(v.uploader_url, v.webpage_url),
|
||||
v.upload_date: entry_get(v.upload_date, v.epoch_date),
|
||||
v.release_date: entry_get(v.release_date, v.upload_date),
|
||||
v.channel: entry_get(v.channel, v.uploader),
|
||||
v.creator: entry_get(v.creator, v.channel),
|
||||
v.channel_id: entry_get(v.channel_id, v.uploader_id),
|
||||
}
|
||||
|
||||
ENTRY_DERIVED_VARIABLES: Dict[KwargKey, str] = {
|
||||
ENTRY_INJECTED_VARIABLES: Dict[MetadataVariable, str] = {
|
||||
v.download_index: entry_get_int(v.download_index),
|
||||
v.upload_date_index: entry_get_int(v.upload_date_index),
|
||||
}
|
||||
|
||||
ENTRY_DERIVED_VARIABLES: Dict[Variable, str] = {
|
||||
v.uid_sanitized: sanitized(v.uid),
|
||||
v.uid_sanitized_plex: sanitized_plex(v.uid_sanitized_plex),
|
||||
v.title_sanitized: sanitized(v.title),
|
||||
v.title_sanitized_plex: sanitized_plex(v.title),
|
||||
v.epoch_date: f"{{%datetime_strftime({v.epoch.variable_name}, '%Y%m%d')}}",
|
||||
v.epoch_hour: f"{{%datetime_strftime({v.epoch.variable_name}, '%H')}}",
|
||||
v.upload_date: entry_get(v.upload_date, v.epoch_date),
|
||||
v.release_date: entry_get(v.release_date, v.upload_date),
|
||||
v.channel: entry_get(v.channel, v.uploader),
|
||||
v.channel_sanitized: sanitized(v.channel),
|
||||
v.creator: entry_get(v.creator, v.channel),
|
||||
v.creator_sanitized: sanitized(v.creator),
|
||||
v.channel_id: entry_get(v.channel_id, v.uploader_id),
|
||||
}
|
||||
|
||||
ENTRY_ARCHIVE_VARIABLES: Dict[KwargKey, str] = {
|
||||
v.download_index: entry_get_int(v.download_index),
|
||||
v.download_index_padded6: pad_int(v.download_index, 6),
|
||||
v.upload_date_index: entry_get_int(v.upload_date_index),
|
||||
v.upload_date_index_padded: pad_int(v.upload_date_index, 2),
|
||||
v.upload_date_index_reversed: f"{{%sub(100, {v.download_index})}}",
|
||||
v.upload_date_index_reversed_padded: pad_int(v.upload_date_index_reversed, 2),
|
||||
}
|
||||
|
||||
ENTRY_UPLOAD_DATE_VARIABLES: Dict[KwargKey, str] = {
|
||||
ENTRY_UPLOAD_DATE_VARIABLES: Dict[Variable, str] = {
|
||||
v.upload_year: date_metadata(v.upload_date, "year"),
|
||||
v.upload_year_truncated: date_metadata(v.upload_date, "year_truncated"),
|
||||
v.upload_year_truncated_reversed: date_metadata(v.upload_date, "year_truncated_reversed"),
|
||||
|
|
@ -117,7 +157,7 @@ ENTRY_UPLOAD_DATE_VARIABLES: Dict[KwargKey, str] = {
|
|||
v.upload_date_standardized: date_metadata(v.upload_date, "date_standardized"),
|
||||
}
|
||||
|
||||
ENTRY_RELEASE_DATE_VARIABLES: Dict[KwargKey, str] = {
|
||||
ENTRY_RELEASE_DATE_VARIABLES: Dict[Variable, str] = {
|
||||
v.release_year: date_metadata(v.release_date, "year"),
|
||||
v.release_year_truncated: date_metadata(v.release_date, "year_truncated"),
|
||||
v.release_year_truncated_reversed: date_metadata(v.release_date, "year_truncated_reversed"),
|
||||
|
|
@ -138,37 +178,46 @@ ENTRY_RELEASE_DATE_VARIABLES: Dict[KwargKey, str] = {
|
|||
v.release_date_standardized: date_metadata(v.release_date, "date_standardized"),
|
||||
}
|
||||
|
||||
ENTRY_SOURCE_VARIABLES: Dict[KwargKey, str] = {
|
||||
# source_title
|
||||
# source_title_sanitized
|
||||
# source_uid
|
||||
# source_index
|
||||
# source_index_padded
|
||||
# source_count
|
||||
# source_webpage_url
|
||||
# source_description
|
||||
# source_uploader_id
|
||||
# source_uploader
|
||||
# source_uploader_url
|
||||
PLAYLIST_VARIABLES: Dict[MetadataVariable, str] = {
|
||||
v.playlist_uid: playlist_get(v.playlist_uid, v.uid),
|
||||
v.playlist_title: playlist_get(v.playlist_title, v.title),
|
||||
v.playlist_webpage_url: playlist_get(v.playlist_webpage_url, v.webpage_url),
|
||||
v.playlist_count: playlist_get_int(v.playlist_count, 1),
|
||||
v.playlist_description: playlist_get(v.playlist_description, v.description),
|
||||
v.playlist_uploader_id: playlist_get(v.playlist_uploader_id, v.uploader_id),
|
||||
v.playlist_uploader: playlist_get(v.playlist_uploader, v.uploader),
|
||||
v.playlist_uploader_url: playlist_get(v.playlist_uploader_url, v.uploader_url),
|
||||
}
|
||||
|
||||
ENTRY_PLAYLIST_VARIABLES: Dict[KwargKey, str] = {
|
||||
# playlist_uid
|
||||
# playlist_title
|
||||
# playlist_title_sanitized
|
||||
# playlist_index
|
||||
# playlist_index_reversed
|
||||
# playlist_index_padded
|
||||
# playlist_index_reversed_padded
|
||||
# playlist_index_padded6
|
||||
# playlist_index_reversed_padded6
|
||||
# playlist_count
|
||||
# playlist_description
|
||||
# playlist_webpage_url
|
||||
# playlist_max_upload_year
|
||||
# playlist_max_upload_year_truncated
|
||||
# playlist_uploader_id
|
||||
# playlist_uploader
|
||||
# playlist_uploader_sanitized
|
||||
# playlist_uploader_url
|
||||
PLAYLIST_INJECTED_VARIABLES: Dict[MetadataVariable, str] = {
|
||||
v.playlist_max_upload_year: playlist_get(v.playlist_max_upload_year, v.upload_year)
|
||||
}
|
||||
|
||||
PLAYLIST_DERIVED_VARIABLES: Dict[Variable, str] = {
|
||||
v.playlist_title_sanitized: sanitized(v.playlist_title),
|
||||
v.playlist_index_reversed: f"{{%sub({v.playlist_count, v.playlist_index, 1})}}",
|
||||
v.playlist_index_padded: pad_int(v.playlist_index, 2),
|
||||
v.playlist_index_reversed_padded: pad_int(v.playlist_index_reversed, 2),
|
||||
v.playlist_index_padded6: pad_int(v.playlist_index, 6),
|
||||
v.playlist_index_reversed_padded6: pad_int(v.playlist_index_reversed, 6),
|
||||
v.playlist_uploader_sanitized: sanitized(v.playlist_uploader),
|
||||
# v.playlist_max_upload_year_truncated:
|
||||
}
|
||||
|
||||
|
||||
SOURCE_VARIABLES: Dict[MetadataVariable, str] = {
|
||||
v.source_uid: source_get(v.source_uid, v.playlist_uid),
|
||||
v.source_title: source_get(v.source_title, v.playlist_title),
|
||||
v.source_webpage_url: source_get(v.source_webpage_url, v.playlist_webpage_url),
|
||||
v.source_index: source_get_int(v.source_index, 1),
|
||||
v.source_count: source_get_int(v.source_count, 1),
|
||||
v.source_description: source_get(v.source_description, v.playlist_description),
|
||||
v.source_uploader_id: source_get(v.source_uploader_id, v.playlist_uploader_id),
|
||||
v.source_uploader: source_get(v.source_uploader, v.playlist_uploader),
|
||||
v.source_uploader_url: source_get(v.source_uploader_url, v.playlist_uploader_url),
|
||||
}
|
||||
|
||||
SOURCE_DERIVED_VARIABLES: Dict[Variable, str] = {
|
||||
v.source_title_sanitized: sanitized(v.source_title),
|
||||
v.source_index_padded: pad_int(v.source_index, 2),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class EntryVariables(BaseEntryVariables):
|
|||
Returns
|
||||
-------
|
||||
int
|
||||
The source count if it exists, otherwise returns the playlist count.
|
||||
The source count if it exists, otherwise returns 1.
|
||||
"""
|
||||
return self.kwargs_get(SOURCE_COUNT, self.playlist_count)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue