more linting
This commit is contained in:
parent
57c8cb1ff5
commit
fb4d9066c9
13 changed files with 178 additions and 127 deletions
|
|
@ -123,7 +123,7 @@ class InfoJsonDownloader(SourcePlugin[InfoJsonDownloaderOptions]):
|
||||||
)
|
)
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
|
|
||||||
for entry in sorted(entries, key=lambda ent: ent.get_str(v.download_index)):
|
for entry in sorted(entries, key=lambda ent: ent.get(v.download_index, int)):
|
||||||
# Remove each entry from the live download archive since it will get re-added
|
# Remove each entry from the live download archive since it will get re-added
|
||||||
# unless it is filtered
|
# unless it is filtered
|
||||||
self._enhanced_download_archive.mapping.remove_entry(entry.uid)
|
self._enhanced_download_archive.mapping.remove_entry(entry.uid)
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ class UrlDownloaderThumbnailPlugin(SourcePluginExtension):
|
||||||
if not self.is_dry_run:
|
if not self.is_dry_run:
|
||||||
try_convert_download_thumbnail(entry=entry)
|
try_convert_download_thumbnail(entry=entry)
|
||||||
|
|
||||||
if (input_url := entry.get_str(v.ytdl_sub_input_url)) in self._collection_url_mapping:
|
if (input_url := entry.get(v.ytdl_sub_input_url, str)) in self._collection_url_mapping:
|
||||||
self._download_url_thumbnails(
|
self._download_url_thumbnails(
|
||||||
collection_url=self._collection_url_mapping[input_url],
|
collection_url=self._collection_url_mapping[input_url],
|
||||||
entry=entry,
|
entry=entry,
|
||||||
|
|
@ -168,7 +168,7 @@ class UrlDownloaderCollectionVariablePlugin(SourcePluginExtension):
|
||||||
"""
|
"""
|
||||||
# COLLECTION_URL is a recent variable that may not exist for old entries when updating.
|
# COLLECTION_URL is a recent variable that may not exist for old entries when updating.
|
||||||
# Try to use source_webpage_url if it does not exist
|
# Try to use source_webpage_url if it does not exist
|
||||||
entry_collection_url = entry.get_str(v.ytdl_sub_input_url)
|
entry_collection_url = entry.get(v.ytdl_sub_input_url, str)
|
||||||
|
|
||||||
# If the collection URL cannot find its mapping, use the last URL
|
# If the collection URL cannot find its mapping, use the last URL
|
||||||
collection_url = (
|
collection_url = (
|
||||||
|
|
@ -488,7 +488,7 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
upload_date_idx = self._enhanced_download_archive.mapping.get_num_entries_with_upload_date(
|
upload_date_idx = self._enhanced_download_archive.mapping.get_num_entries_with_upload_date(
|
||||||
upload_date_standardized=entry.get_str(v.upload_date_standardized)
|
upload_date_standardized=entry.get(v.upload_date_standardized, str)
|
||||||
)
|
)
|
||||||
download_idx = self._enhanced_download_archive.num_entries
|
download_idx = self._enhanced_download_archive.num_entries
|
||||||
entry.add(
|
entry.add(
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,6 @@ class Entry(BaseEntry, Scriptable):
|
||||||
except ScriptVariableNotResolved:
|
except ScriptVariableNotResolved:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_str(self, variable: Variable) -> str:
|
|
||||||
return self.get(variable, str)
|
|
||||||
|
|
||||||
def get_int(self, variable: Variable) -> int:
|
|
||||||
return self.get(variable, int)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ext(self) -> str:
|
def ext(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
@ -98,7 +92,7 @@ class Entry(BaseEntry, Scriptable):
|
||||||
-------
|
-------
|
||||||
The download thumbnail's file name
|
The download thumbnail's file name
|
||||||
"""
|
"""
|
||||||
return f"{self.uid}.{self.get_str(v.thumbnail_ext)}"
|
return f"{self.uid}.{self.get(v.thumbnail_ext, str)}"
|
||||||
|
|
||||||
def get_download_thumbnail_path(self) -> str:
|
def get_download_thumbnail_path(self) -> str:
|
||||||
"""Returns the entry's thumbnail's file path to where it was downloaded"""
|
"""Returns the entry's thumbnail's file path to where it was downloaded"""
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ v: VariableDefinitions = VARIABLES
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
|
|
||||||
def _sort_entries(entries: List[TBaseEntry]) -> List[TBaseEntry]:
|
def _sort_entries(entries: List[TBaseEntry]) -> List[TBaseEntry]:
|
||||||
"""Try sorting by playlist_id first, then fall back to uid"""
|
"""Try sorting by playlist_id first, then fall back to uid"""
|
||||||
return sorted(
|
return sorted(
|
||||||
|
|
@ -203,8 +204,6 @@ class EntryParent(BaseEntry):
|
||||||
|
|
||||||
return parents
|
return parents
|
||||||
|
|
||||||
# pylint: enable=protected-access
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_entry_dicts_with_no_parents(
|
def from_entry_dicts_with_no_parents(
|
||||||
cls,
|
cls,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
||||||
v: VariableDefinitions = VARIABLES
|
v: VariableDefinitions = VARIABLES
|
||||||
|
|
||||||
CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
|
CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
|
||||||
"%extract_field_from_metadata_array_getter": "{ %map_get( %map(%array_at($0, 0)), %array_at($0, 1) ) }",
|
"%extract_field_from_metadata_array_getter": """{
|
||||||
|
%map_get( %map(%array_at($0, 0)), %array_at($0, 1) )
|
||||||
|
}""",
|
||||||
"%extract_field_from_metadata_array": """{
|
"%extract_field_from_metadata_array": """{
|
||||||
%if(
|
%if(
|
||||||
%bool($0),
|
%bool($0),
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,15 @@ from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
||||||
v: VariableDefinitions = VARIABLES
|
v: VariableDefinitions = VARIABLES
|
||||||
|
|
||||||
|
|
||||||
def pad_int(key: Variable, pad: int) -> str:
|
def _pad_int(key: Variable, pad: int) -> str:
|
||||||
return f"{{%pad_zero({key.variable_name}, {pad})}}"
|
return f"{{%pad_zero({key.variable_name}, {pad})}}"
|
||||||
|
|
||||||
|
|
||||||
def sanitized_plex(key: Variable) -> str:
|
def _sanitized_plex(key: Variable) -> str:
|
||||||
return f"{{%sanitize_plex_episode({key.variable_name})}}"
|
return f"{{%sanitize_plex_episode({key.variable_name})}}"
|
||||||
|
|
||||||
|
|
||||||
def date_metadata(date_key: Variable, metadata_key: str) -> str:
|
def _date_metadata(date_key: Variable, metadata_key: str) -> str:
|
||||||
return f"{{%map_get(%to_date_metadata({date_key.variable_name}), '{metadata_key}')}}"
|
return f"{{%map_get(%to_date_metadata({date_key.variable_name}), '{metadata_key}')}}"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -61,19 +61,19 @@ def _get(
|
||||||
# Entry Getters
|
# Entry Getters
|
||||||
|
|
||||||
|
|
||||||
def entry_get_str(key: MetadataVariable, default: Optional[Variable | str] = None) -> str:
|
def _entry_get_str(key: MetadataVariable, default: Optional[Variable | str] = None) -> str:
|
||||||
return _get("string", metadata=v.entry_metadata, key=key, default=default)
|
return _get("string", metadata=v.entry_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
def entry_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
def _entry_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
||||||
return _get("int", metadata=v.entry_metadata, key=key, default=default)
|
return _get("int", metadata=v.entry_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
def entry_get_map(key: MetadataVariable, default: Optional[Variable | Dict] = None):
|
def _entry_get_map(key: MetadataVariable, default: Optional[Variable | Dict] = None):
|
||||||
return _get("map", metadata=v.entry_metadata, key=key, default=default)
|
return _get("map", metadata=v.entry_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
def entry_get_array(key: MetadataVariable, default: Optional[Variable | List] = None):
|
def _entry_get_array(key: MetadataVariable, default: Optional[Variable | List] = None):
|
||||||
return _get("array", metadata=v.entry_metadata, key=key, default=default)
|
return _get("array", metadata=v.entry_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,11 +81,11 @@ def entry_get_array(key: MetadataVariable, default: Optional[Variable | List] =
|
||||||
# Playlist Getters
|
# Playlist Getters
|
||||||
|
|
||||||
|
|
||||||
def playlist_get_str(key: MetadataVariable, default: Optional[Variable | str] = None) -> str:
|
def _playlist_get_str(key: MetadataVariable, default: Optional[Variable | str] = None) -> str:
|
||||||
return _get("string", metadata=v.playlist_metadata, key=key, default=default)
|
return _get("string", metadata=v.playlist_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
def playlist_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
def _playlist_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
||||||
return _get("int", metadata=v.playlist_metadata, key=key, default=default)
|
return _get("int", metadata=v.playlist_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,14 +93,10 @@ def playlist_get_int(key: MetadataVariable, default: Optional[Variable | int] =
|
||||||
# Source Getters
|
# Source Getters
|
||||||
|
|
||||||
|
|
||||||
def source_get_str(key: MetadataVariable, default: Optional[Variable | str] = None) -> str:
|
def _source_get_str(key: MetadataVariable, default: Optional[Variable | str] = None) -> str:
|
||||||
return _get("string", metadata=v.source_metadata, key=key, default=default)
|
return _get("string", metadata=v.source_metadata, key=key, default=default)
|
||||||
|
|
||||||
|
|
||||||
def source_get_int(key: MetadataVariable, default: Optional[Variable | int] = None) -> str:
|
|
||||||
return _get("int", metadata=v.source_metadata, key=key, default=default)
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################################
|
###############################################################################################
|
||||||
# Scripts
|
# Scripts
|
||||||
|
|
||||||
|
|
@ -112,38 +108,38 @@ ENTRY_HARDCODED_VARIABLES: Dict[Variable, str] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTRY_RELATIVE_VARIABLES: Dict[MetadataVariable, str] = {
|
ENTRY_RELATIVE_VARIABLES: Dict[MetadataVariable, str] = {
|
||||||
v.playlist_metadata: entry_get_map(v.playlist_metadata, {}),
|
v.playlist_metadata: _entry_get_map(v.playlist_metadata, {}),
|
||||||
v.source_metadata: entry_get_map(v.source_metadata, {}),
|
v.source_metadata: _entry_get_map(v.source_metadata, {}),
|
||||||
v.sibling_metadata: entry_get_array(v.sibling_metadata, []),
|
v.sibling_metadata: _entry_get_array(v.sibling_metadata, []),
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTRY_REQUIRED_VARIABLES: Dict[MetadataVariable, str] = {
|
ENTRY_REQUIRED_VARIABLES: Dict[MetadataVariable, str] = {
|
||||||
v.uid: entry_get_str(v.uid),
|
v.uid: _entry_get_str(v.uid),
|
||||||
v.extractor_key: entry_get_str(v.extractor_key),
|
v.extractor_key: _entry_get_str(v.extractor_key),
|
||||||
v.epoch: entry_get_int(v.epoch),
|
v.epoch: _entry_get_int(v.epoch),
|
||||||
v.webpage_url: entry_get_str(v.webpage_url),
|
v.webpage_url: _entry_get_str(v.webpage_url),
|
||||||
v.ext: entry_get_str(v.ext),
|
v.ext: _entry_get_str(v.ext),
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTRY_DEFAULT_VARIABLES: Dict[MetadataVariable, str] = {
|
ENTRY_DEFAULT_VARIABLES: Dict[MetadataVariable, str] = {
|
||||||
v.title: entry_get_str(v.title, v.uid),
|
v.title: _entry_get_str(v.title, v.uid),
|
||||||
v.extractor: entry_get_str(v.extractor, v.extractor_key),
|
v.extractor: _entry_get_str(v.extractor, v.extractor_key),
|
||||||
v.description: entry_get_str(v.description, ""),
|
v.description: _entry_get_str(v.description, ""),
|
||||||
v.ie_key: entry_get_str(v.ie_key, v.extractor_key),
|
v.ie_key: _entry_get_str(v.ie_key, v.extractor_key),
|
||||||
v.uploader_id: entry_get_str(v.uploader_id, v.uid),
|
v.uploader_id: _entry_get_str(v.uploader_id, v.uid),
|
||||||
v.uploader: entry_get_str(v.uploader, v.uploader_id),
|
v.uploader: _entry_get_str(v.uploader, v.uploader_id),
|
||||||
v.uploader_url: entry_get_str(v.uploader_url, v.webpage_url),
|
v.uploader_url: _entry_get_str(v.uploader_url, v.webpage_url),
|
||||||
v.upload_date: entry_get_str(v.upload_date, v.epoch_date),
|
v.upload_date: _entry_get_str(v.upload_date, v.epoch_date),
|
||||||
v.release_date: entry_get_str(v.release_date, v.upload_date),
|
v.release_date: _entry_get_str(v.release_date, v.upload_date),
|
||||||
v.channel: entry_get_str(v.channel, v.uploader),
|
v.channel: _entry_get_str(v.channel, v.uploader),
|
||||||
v.creator: entry_get_str(v.creator, v.channel),
|
v.creator: _entry_get_str(v.creator, v.channel),
|
||||||
v.channel_id: entry_get_str(v.channel_id, v.uploader_id),
|
v.channel_id: _entry_get_str(v.channel_id, v.uploader_id),
|
||||||
v.duration: entry_get_int(v.duration, 0),
|
v.duration: _entry_get_int(v.duration, 0),
|
||||||
v.playlist_index: entry_get_int(v.playlist_index, 1),
|
v.playlist_index: _entry_get_int(v.playlist_index, 1),
|
||||||
v.playlist_count: entry_get_int(v.playlist_count, 1),
|
v.playlist_count: _entry_get_int(v.playlist_count, 1),
|
||||||
v.playlist_uid: entry_get_str(v.playlist_uid, v.uid),
|
v.playlist_uid: _entry_get_str(v.playlist_uid, v.uid),
|
||||||
v.playlist_title: entry_get_str(v.playlist_title, v.title),
|
v.playlist_title: _entry_get_str(v.playlist_title, v.title),
|
||||||
v.playlist_uploader_id: entry_get_str(v.playlist_uploader_id, v.uploader_id),
|
v.playlist_uploader_id: _entry_get_str(v.playlist_uploader_id, v.uploader_id),
|
||||||
}
|
}
|
||||||
|
|
||||||
# MARK AS UNRESOLVABLE UNTIL THEY ARE ADDED IN THE DOWNLOADER
|
# MARK AS UNRESOLVABLE UNTIL THEY ARE ADDED IN THE DOWNLOADER
|
||||||
|
|
@ -158,85 +154,85 @@ DOWNLOADER_INJECTED_VARIABLES: Dict[Variable, str] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTRY_DERIVED_VARIABLES: Dict[Variable, str] = {
|
ENTRY_DERIVED_VARIABLES: Dict[Variable, str] = {
|
||||||
v.uid_sanitized_plex: sanitized_plex(v.uid),
|
v.uid_sanitized_plex: _sanitized_plex(v.uid),
|
||||||
v.title_sanitized_plex: sanitized_plex(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_date: f"{{%datetime_strftime({v.epoch.variable_name}, '%Y%m%d')}}",
|
||||||
v.epoch_hour: f"{{%datetime_strftime({v.epoch.variable_name}, '%H')}}",
|
v.epoch_hour: f"{{%datetime_strftime({v.epoch.variable_name}, '%H')}}",
|
||||||
v.download_index_padded6: pad_int(v.download_index, 6),
|
v.download_index_padded6: _pad_int(v.download_index, 6),
|
||||||
v.upload_date_index_padded: pad_int(v.upload_date_index, 2),
|
v.upload_date_index_padded: _pad_int(v.upload_date_index, 2),
|
||||||
v.upload_date_index_reversed: f"{{%sub(100, {v.upload_date_index.variable_name})}}",
|
v.upload_date_index_reversed: f"{{%sub(100, {v.upload_date_index.variable_name})}}",
|
||||||
v.upload_date_index_reversed_padded: pad_int(v.upload_date_index_reversed, 2),
|
v.upload_date_index_reversed_padded: _pad_int(v.upload_date_index_reversed, 2),
|
||||||
v.playlist_index_reversed: f"{{%sub({v.playlist_count.variable_name}, {v.playlist_index.variable_name}, -1)}}",
|
v.playlist_index_reversed: f"{{%sub({v.playlist_count.variable_name}, {v.playlist_index.variable_name}, -1)}}",
|
||||||
v.playlist_index_padded: pad_int(v.playlist_index, 2),
|
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_reversed_padded: _pad_int(v.playlist_index_reversed, 2),
|
||||||
v.playlist_index_padded6: pad_int(v.playlist_index, 6),
|
v.playlist_index_padded6: _pad_int(v.playlist_index, 6),
|
||||||
v.playlist_index_reversed_padded6: pad_int(v.playlist_index_reversed, 6),
|
v.playlist_index_reversed_padded6: _pad_int(v.playlist_index_reversed, 6),
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTRY_UPLOAD_DATE_VARIABLES: Dict[Variable, str] = {
|
ENTRY_UPLOAD_DATE_VARIABLES: Dict[Variable, str] = {
|
||||||
v.upload_year: date_metadata(v.upload_date, "year"),
|
v.upload_year: _date_metadata(v.upload_date, "year"),
|
||||||
v.upload_year_truncated: date_metadata(v.upload_date, "year_truncated"),
|
v.upload_year_truncated: _date_metadata(v.upload_date, "year_truncated"),
|
||||||
v.upload_year_truncated_reversed: date_metadata(v.upload_date, "year_truncated_reversed"),
|
v.upload_year_truncated_reversed: _date_metadata(v.upload_date, "year_truncated_reversed"),
|
||||||
v.upload_month_reversed: date_metadata(v.upload_date, "month_reversed"),
|
v.upload_month_reversed: _date_metadata(v.upload_date, "month_reversed"),
|
||||||
v.upload_month_reversed_padded: date_metadata(v.upload_date, "month_reversed_padded"),
|
v.upload_month_reversed_padded: _date_metadata(v.upload_date, "month_reversed_padded"),
|
||||||
v.upload_month_padded: date_metadata(v.upload_date, "month_padded"),
|
v.upload_month_padded: _date_metadata(v.upload_date, "month_padded"),
|
||||||
v.upload_day_padded: date_metadata(v.upload_date, "day_padded"),
|
v.upload_day_padded: _date_metadata(v.upload_date, "day_padded"),
|
||||||
v.upload_month: date_metadata(v.upload_date, "month"),
|
v.upload_month: _date_metadata(v.upload_date, "month"),
|
||||||
v.upload_day: date_metadata(v.upload_date, "day"),
|
v.upload_day: _date_metadata(v.upload_date, "day"),
|
||||||
v.upload_day_reversed: date_metadata(v.upload_date, "day_reversed"),
|
v.upload_day_reversed: _date_metadata(v.upload_date, "day_reversed"),
|
||||||
v.upload_day_reversed_padded: date_metadata(v.upload_date, "day_reversed_padded"),
|
v.upload_day_reversed_padded: _date_metadata(v.upload_date, "day_reversed_padded"),
|
||||||
v.upload_day_of_year: date_metadata(v.upload_date, "day_of_year"),
|
v.upload_day_of_year: _date_metadata(v.upload_date, "day_of_year"),
|
||||||
v.upload_day_of_year_padded: date_metadata(v.upload_date, "day_of_year_padded"),
|
v.upload_day_of_year_padded: _date_metadata(v.upload_date, "day_of_year_padded"),
|
||||||
v.upload_day_of_year_reversed: date_metadata(v.upload_date, "day_of_year_reversed"),
|
v.upload_day_of_year_reversed: _date_metadata(v.upload_date, "day_of_year_reversed"),
|
||||||
v.upload_day_of_year_reversed_padded: date_metadata(
|
v.upload_day_of_year_reversed_padded: _date_metadata(
|
||||||
v.upload_date, "day_of_year_reversed_padded"
|
v.upload_date, "day_of_year_reversed_padded"
|
||||||
),
|
),
|
||||||
v.upload_date_standardized: date_metadata(v.upload_date, "date_standardized"),
|
v.upload_date_standardized: _date_metadata(v.upload_date, "date_standardized"),
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTRY_RELEASE_DATE_VARIABLES: Dict[Variable, str] = {
|
ENTRY_RELEASE_DATE_VARIABLES: Dict[Variable, str] = {
|
||||||
v.release_year: date_metadata(v.release_date, "year"),
|
v.release_year: _date_metadata(v.release_date, "year"),
|
||||||
v.release_year_truncated: date_metadata(v.release_date, "year_truncated"),
|
v.release_year_truncated: _date_metadata(v.release_date, "year_truncated"),
|
||||||
v.release_year_truncated_reversed: date_metadata(v.release_date, "year_truncated_reversed"),
|
v.release_year_truncated_reversed: _date_metadata(v.release_date, "year_truncated_reversed"),
|
||||||
v.release_month_reversed: date_metadata(v.release_date, "month_reversed"),
|
v.release_month_reversed: _date_metadata(v.release_date, "month_reversed"),
|
||||||
v.release_month_reversed_padded: date_metadata(v.release_date, "month_reversed_padded"),
|
v.release_month_reversed_padded: _date_metadata(v.release_date, "month_reversed_padded"),
|
||||||
v.release_month_padded: date_metadata(v.release_date, "month_padded"),
|
v.release_month_padded: _date_metadata(v.release_date, "month_padded"),
|
||||||
v.release_day_padded: date_metadata(v.release_date, "day_padded"),
|
v.release_day_padded: _date_metadata(v.release_date, "day_padded"),
|
||||||
v.release_month: date_metadata(v.release_date, "month"),
|
v.release_month: _date_metadata(v.release_date, "month"),
|
||||||
v.release_day: date_metadata(v.release_date, "day"),
|
v.release_day: _date_metadata(v.release_date, "day"),
|
||||||
v.release_day_reversed: date_metadata(v.release_date, "day_reversed"),
|
v.release_day_reversed: _date_metadata(v.release_date, "day_reversed"),
|
||||||
v.release_day_reversed_padded: date_metadata(v.release_date, "day_reversed_padded"),
|
v.release_day_reversed_padded: _date_metadata(v.release_date, "day_reversed_padded"),
|
||||||
v.release_day_of_year: date_metadata(v.release_date, "day_of_year"),
|
v.release_day_of_year: _date_metadata(v.release_date, "day_of_year"),
|
||||||
v.release_day_of_year_padded: date_metadata(v.release_date, "day_of_year_padded"),
|
v.release_day_of_year_padded: _date_metadata(v.release_date, "day_of_year_padded"),
|
||||||
v.release_day_of_year_reversed: date_metadata(v.release_date, "day_of_year_reversed"),
|
v.release_day_of_year_reversed: _date_metadata(v.release_date, "day_of_year_reversed"),
|
||||||
v.release_day_of_year_reversed_padded: date_metadata(
|
v.release_day_of_year_reversed_padded: _date_metadata(
|
||||||
v.release_date, "day_of_year_reversed_padded"
|
v.release_date, "day_of_year_reversed_padded"
|
||||||
),
|
),
|
||||||
v.release_date_standardized: date_metadata(v.release_date, "date_standardized"),
|
v.release_date_standardized: _date_metadata(v.release_date, "date_standardized"),
|
||||||
}
|
}
|
||||||
|
|
||||||
PLAYLIST_VARIABLES: Dict[Variable, str] = {
|
PLAYLIST_VARIABLES: Dict[Variable, str] = {
|
||||||
v.playlist_webpage_url: playlist_get_str(v.playlist_webpage_url, v.webpage_url),
|
v.playlist_webpage_url: _playlist_get_str(v.playlist_webpage_url, v.webpage_url),
|
||||||
v.playlist_description: playlist_get_str(v.playlist_description, v.description),
|
v.playlist_description: _playlist_get_str(v.playlist_description, v.description),
|
||||||
v.playlist_uploader: playlist_get_str(v.playlist_uploader, v.uploader),
|
v.playlist_uploader: _playlist_get_str(v.playlist_uploader, v.uploader),
|
||||||
v.playlist_uploader_url: playlist_get_str(v.playlist_uploader_url, v.playlist_webpage_url),
|
v.playlist_uploader_url: _playlist_get_str(v.playlist_uploader_url, v.playlist_webpage_url),
|
||||||
|
v.source_index: _playlist_get_int(v.source_index, 1),
|
||||||
|
v.source_count: _playlist_get_int(v.source_count, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SOURCE_VARIABLES: Dict[Variable, str] = {
|
SOURCE_VARIABLES: Dict[Variable, str] = {
|
||||||
v.source_uid: source_get_str(v.source_uid, v.playlist_uid),
|
v.source_uid: _source_get_str(v.source_uid, v.playlist_uid),
|
||||||
v.source_title: source_get_str(v.source_title, v.playlist_title),
|
v.source_title: _source_get_str(v.source_title, v.playlist_title),
|
||||||
v.source_webpage_url: source_get_str(v.source_webpage_url, v.playlist_webpage_url),
|
v.source_webpage_url: _source_get_str(v.source_webpage_url, v.playlist_webpage_url),
|
||||||
v.source_index: source_get_int(v.source_index, 1),
|
v.source_description: _source_get_str(v.source_description, v.playlist_description),
|
||||||
v.source_count: source_get_int(v.source_count, 1),
|
v.source_uploader_id: _source_get_str(v.source_uploader_id, v.playlist_uploader_id),
|
||||||
v.source_description: source_get_str(v.source_description, v.playlist_description),
|
v.source_uploader: _source_get_str(v.source_uploader, v.playlist_uploader),
|
||||||
v.source_uploader_id: source_get_str(v.source_uploader_id, v.playlist_uploader_id),
|
v.source_uploader_url: _source_get_str(v.source_uploader_url, v.source_webpage_url),
|
||||||
v.source_uploader: source_get_str(v.source_uploader, v.playlist_uploader),
|
|
||||||
v.source_uploader_url: source_get_str(v.source_uploader_url, v.source_webpage_url),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SOURCE_DERIVED_VARIABLES: Dict[Variable, str] = {
|
SOURCE_DERIVED_VARIABLES: Dict[Variable, str] = {
|
||||||
v.source_index_padded: pad_int(v.source_index, 2),
|
v.source_index_padded: _pad_int(v.source_index, 2),
|
||||||
}
|
}
|
||||||
|
|
||||||
SIBLING_VARIABLES: Dict[Variable, str] = {
|
SIBLING_VARIABLES: Dict[Variable, str] = {
|
||||||
|
|
@ -252,8 +248,8 @@ SIBLING_VARIABLES: Dict[Variable, str] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
SIBLING_DERIVED_VARIABLES: Dict[Variable, str] = {
|
SIBLING_DERIVED_VARIABLES: Dict[Variable, str] = {
|
||||||
v.playlist_max_upload_year: date_metadata(v.playlist_max_upload_date, "year"),
|
v.playlist_max_upload_year: _date_metadata(v.playlist_max_upload_date, "year"),
|
||||||
v.playlist_max_upload_year_truncated: date_metadata(
|
v.playlist_max_upload_year_truncated: _date_metadata(
|
||||||
v.playlist_max_upload_date, "year_truncated"
|
v.playlist_max_upload_date, "year_truncated"
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,7 @@ class ChaptersPlugin(Plugin[ChaptersOptions]):
|
||||||
set_ffmpeg_metadata_chapters(
|
set_ffmpeg_metadata_chapters(
|
||||||
file_path=entry.get_download_file_path(),
|
file_path=entry.get_download_file_path(),
|
||||||
chapters=chapters,
|
chapters=chapters,
|
||||||
file_duration_sec=entry.get_int(v.duration),
|
file_duration_sec=entry.get(v.duration, int),
|
||||||
)
|
)
|
||||||
|
|
||||||
if not has_chapters_from_comments:
|
if not has_chapters_from_comments:
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ class MusicTagsPlugin(Plugin[MusicTagsOptions]):
|
||||||
"""
|
"""
|
||||||
Tags the entry's audio file using values defined in the metadata options
|
Tags the entry's audio file using values defined in the metadata options
|
||||||
"""
|
"""
|
||||||
if (ext := entry.get_str(v.ext)) not in AUDIO_CODEC_EXTS:
|
if (ext := entry.get(v.ext, str)) not in AUDIO_CODEC_EXTS:
|
||||||
raise self.plugin_options.validation_exception(
|
raise self.plugin_options.validation_exception(
|
||||||
f"music_tags plugin received a video with the extension '{ext}'. Only audio "
|
f"music_tags plugin received a video with the extension '{ext}'. Only audio "
|
||||||
f"files are supported for setting music tags. Ensure you are converting the video "
|
f"files are supported for setting music tags. Ensure you are converting the video "
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ class SplitByChaptersPlugin(SplitPlugin[SplitByChaptersOptions]):
|
||||||
)
|
)
|
||||||
|
|
||||||
timestamp_begin = chapters.timestamps[idx].readable_str
|
timestamp_begin = chapters.timestamps[idx].readable_str
|
||||||
timestamp_end = Timestamp(new_entry.get_int(v.duration)).readable_str
|
timestamp_end = Timestamp(new_entry.get(v.duration, int)).readable_str
|
||||||
if idx + 1 < len(chapters.timestamps):
|
if idx + 1 < len(chapters.timestamps):
|
||||||
timestamp_end = chapters.timestamps[idx + 1].readable_str
|
timestamp_end = chapters.timestamps[idx + 1].readable_str
|
||||||
|
|
||||||
|
|
@ -220,7 +220,7 @@ class SplitByChaptersPlugin(SplitPlugin[SplitByChaptersOptions]):
|
||||||
FileHandler.copy(
|
FileHandler.copy(
|
||||||
src_file_path=entry.get_download_thumbnail_path(),
|
src_file_path=entry.get_download_thumbnail_path(),
|
||||||
dst_file_path=Path(self.working_directory)
|
dst_file_path=Path(self.working_directory)
|
||||||
/ f"{new_uid}.{entry.get_str(v.thumbnail_ext)}",
|
/ f"{new_uid}.{entry.get(v.thumbnail_ext, str)}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Format the split video
|
# Format the split video
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,9 @@ class CustomFunction(Function, NamedCustomFunction):
|
||||||
|
|
||||||
class BuiltInFunction(Function, BuiltInFunctionType):
|
class BuiltInFunction(Function, BuiltInFunctionType):
|
||||||
def validate_args(self) -> "BuiltInFunction":
|
def validate_args(self) -> "BuiltInFunction":
|
||||||
|
"""
|
||||||
|
Ensures the args are compatible with the BuiltInFunction.
|
||||||
|
"""
|
||||||
if not self.function_spec.is_compatible(input_args=self.args):
|
if not self.function_spec.is_compatible(input_args=self.args):
|
||||||
raise FunctionArgumentsExceptionFormatter(
|
raise FunctionArgumentsExceptionFormatter(
|
||||||
input_spec=self.function_spec,
|
input_spec=self.function_spec,
|
||||||
|
|
@ -92,6 +95,11 @@ class BuiltInFunction(Function, BuiltInFunctionType):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def callable(self) -> Callable[..., Resolvable]:
|
def callable(self) -> Callable[..., Resolvable]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
The actual callable of the BuiltInFunction
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return Functions.get(self.name)
|
return Functions.get(self.name)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
@ -100,6 +108,11 @@ class BuiltInFunction(Function, BuiltInFunctionType):
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def function_spec(self) -> FunctionSpec:
|
def function_spec(self) -> FunctionSpec:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
The FunctionSpec of the BuiltInFunction
|
||||||
|
"""
|
||||||
return FunctionSpec.from_callable(self.callable)
|
return FunctionSpec.from_callable(self.callable)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -134,6 +147,11 @@ class BuiltInFunction(Function, BuiltInFunctionType):
|
||||||
return Union[tuple(union_types_list)]
|
return Union[tuple(union_types_list)]
|
||||||
|
|
||||||
def output_type(self) -> Type[Resolvable]:
|
def output_type(self) -> Type[Resolvable]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
The BuiltInFunction's true output type.
|
||||||
|
"""
|
||||||
if is_union(self.function_spec.return_type):
|
if is_union(self.function_spec.return_type):
|
||||||
return self._output_type(self.function_spec.return_type.__args__)
|
return self._output_type(self.function_spec.return_type.__args__)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,26 +46,51 @@ class VariableDependency(ABC):
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def variables(self) -> Set[Variable]:
|
def variables(self) -> Set[Variable]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
All Variables that this depends on.
|
||||||
|
"""
|
||||||
return set(self._recurse_get(Variable))
|
return set(self._recurse_get(Variable))
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def built_in_functions(self) -> List[BuiltInFunctionType]:
|
def built_in_functions(self) -> List[BuiltInFunctionType]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
All BuiltInFunctions that this depends on.
|
||||||
|
"""
|
||||||
return self._recurse_get(BuiltInFunctionType)
|
return self._recurse_get(BuiltInFunctionType)
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def function_arguments(self) -> Set[FunctionArgument]:
|
def function_arguments(self) -> Set[FunctionArgument]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
All FunctionArguments that this depends on.
|
||||||
|
"""
|
||||||
return set(self._recurse_get(FunctionArgument))
|
return set(self._recurse_get(FunctionArgument))
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def lambdas(self) -> Set[Lambda]:
|
def lambdas(self) -> Set[Lambda]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
All Lambdas that this depends on.
|
||||||
|
"""
|
||||||
return set(self._recurse_get(Lambda, subclass=True))
|
return set(self._recurse_get(Lambda, subclass=True))
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def custom_functions(self) -> Set[ParsedCustomFunction]:
|
def custom_functions(self) -> Set[ParsedCustomFunction]:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
All CustomFunctions that this depends on.
|
||||||
|
"""
|
||||||
output: Set[ParsedCustomFunction] = set()
|
output: Set[ParsedCustomFunction] = set()
|
||||||
for arg in self._iterable_arguments:
|
for arg in self._iterable_arguments:
|
||||||
if isinstance(arg, NamedCustomFunction):
|
if isinstance(arg, NamedCustomFunction):
|
||||||
|
|
@ -86,6 +111,18 @@ class VariableDependency(ABC):
|
||||||
resolved_variables: Dict[Variable, Resolvable],
|
resolved_variables: Dict[Variable, Resolvable],
|
||||||
custom_functions: Dict[str, "VariableDependency"],
|
custom_functions: Dict[str, "VariableDependency"],
|
||||||
) -> Resolvable:
|
) -> Resolvable:
|
||||||
|
"""
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
resolved_variables
|
||||||
|
Lookup of variables that have been resolved
|
||||||
|
custom_functions
|
||||||
|
Lookup of any custom functions that have been parsed
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Resolved value
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -114,10 +151,15 @@ class VariableDependency(ABC):
|
||||||
"""
|
"""
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
True if variable dependency. False otherwise.
|
True if it contains all input variables as a dependency. False otherwise.
|
||||||
"""
|
"""
|
||||||
return not self.variables.issubset(variables)
|
return not self.variables.issubset(variables)
|
||||||
|
|
||||||
@final
|
@final
|
||||||
def contains(self, variables: Iterable[Variable]) -> bool:
|
def contains(self, variables: Iterable[Variable]) -> bool:
|
||||||
|
"""
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
True if it contains any of the input variables. False otherwise.
|
||||||
|
"""
|
||||||
return len(self.variables.intersection(variables)) > 0
|
return len(self.variables.intersection(variables)) > 0
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,8 @@ class DownloadMapping:
|
||||||
DownloadMapping for the entry
|
DownloadMapping for the entry
|
||||||
"""
|
"""
|
||||||
return DownloadMapping(
|
return DownloadMapping(
|
||||||
upload_date=entry.get_str(v.upload_date_standardized),
|
upload_date=entry.get(v.upload_date_standardized, str),
|
||||||
extractor=entry.get_str(v.extractor),
|
extractor=entry.get(v.extractor, str),
|
||||||
file_names=set(),
|
file_names=set(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ class TestEntry(object):
|
||||||
|
|
||||||
mock_entry_kwargs["upload_date"] = upload_date
|
mock_entry_kwargs["upload_date"] = upload_date
|
||||||
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script()
|
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script()
|
||||||
assert entry.get_int(v.upload_year_truncated_reversed) == year_rev
|
assert entry.get(v.upload_year_truncated_reversed, int) == year_rev
|
||||||
assert entry.get_int(v.upload_month_reversed) == month_rev
|
assert entry.get(v.upload_month_reversed, int) == month_rev
|
||||||
assert entry.get_int(v.upload_day_reversed) == day_rev
|
assert entry.get(v.upload_day_reversed, int) == day_rev
|
||||||
assert entry.get_str(v.upload_month_reversed_padded) == month_rev_pad
|
assert entry.get(v.upload_month_reversed_padded, str) == month_rev_pad
|
||||||
assert entry.get_str(v.upload_day_reversed_padded) == day_rev_pad
|
assert entry.get(v.upload_day_reversed_padded, str) == day_rev_pad
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"upload_date, day_year, day_year_rev, day_year_pad, day_year_rev_pad",
|
"upload_date, day_year, day_year_rev, day_year_pad, day_year_rev_pad",
|
||||||
|
|
@ -62,7 +62,7 @@ class TestEntry(object):
|
||||||
mock_entry_kwargs["upload_date"] = upload_date
|
mock_entry_kwargs["upload_date"] = upload_date
|
||||||
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script()
|
entry = Entry(entry_dict=mock_entry_kwargs, working_directory=".").initialize_script()
|
||||||
|
|
||||||
assert entry.get_int(v.upload_day_of_year) == day_year
|
assert entry.get(v.upload_day_of_year, int) == day_year
|
||||||
assert entry.get_int(v.upload_day_of_year_reversed) == day_year_rev
|
assert entry.get(v.upload_day_of_year_reversed, int) == day_year_rev
|
||||||
assert entry.get_str(v.upload_day_of_year_padded) == day_year_pad
|
assert entry.get(v.upload_day_of_year_padded, str) == day_year_pad
|
||||||
assert entry.get_str(v.upload_day_of_year_reversed_padded) == day_year_rev_pad
|
assert entry.get(v.upload_day_of_year_reversed_padded, str) == day_year_rev_pad
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue