diff --git a/src/ytdl_sub/entries/base_entry.py b/src/ytdl_sub/entries/base_entry.py index eea80b09..950c7dfb 100644 --- a/src/ytdl_sub/entries/base_entry.py +++ b/src/ytdl_sub/entries/base_entry.py @@ -12,6 +12,7 @@ from yt_dlp.utils import sanitize_filename from ytdl_sub.entries.variables.kwargs import DESCRIPTION from ytdl_sub.entries.variables.kwargs import TITLE +from ytdl_sub.entries.variables.kwargs import UID from ytdl_sub.entries.variables.kwargs import UPLOADER from ytdl_sub.entries.variables.kwargs import UPLOADER_ID from ytdl_sub.entries.variables.kwargs import UPLOADER_URL @@ -37,7 +38,7 @@ class BaseEntryVariables: str The entry's unique ID """ - return self.kwargs("id") + return self.kwargs(UID) @property def extractor(self: "BaseEntry") -> str: diff --git a/src/ytdl_sub/entries/entry_parent.py b/src/ytdl_sub/entries/entry_parent.py index 114b8c61..7c4f8ff3 100644 --- a/src/ytdl_sub/entries/entry_parent.py +++ b/src/ytdl_sub/entries/entry_parent.py @@ -9,6 +9,7 @@ import mergedeep from ytdl_sub.entries.base_entry import BaseEntry from ytdl_sub.entries.base_entry import TBaseEntry from ytdl_sub.entries.entry import Entry +from ytdl_sub.entries.variables.kwargs import DESCRIPTION from ytdl_sub.entries.variables.kwargs import PLAYLIST_COUNT from ytdl_sub.entries.variables.kwargs import PLAYLIST_DESCRIPTION from ytdl_sub.entries.variables.kwargs import PLAYLIST_ENTRY @@ -31,6 +32,12 @@ from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER_ID from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER_URL from ytdl_sub.entries.variables.kwargs import SOURCE_WEBPAGE_URL +from ytdl_sub.entries.variables.kwargs import TITLE +from ytdl_sub.entries.variables.kwargs import UID +from ytdl_sub.entries.variables.kwargs import UPLOADER +from ytdl_sub.entries.variables.kwargs import UPLOADER_ID +from ytdl_sub.entries.variables.kwargs import UPLOADER_URL +from ytdl_sub.entries.variables.kwargs import WEBPAGE_URL class ParentType: @@ -77,15 +84,18 @@ class EntryParent(BaseEntry): def _(source_key: str, playlist_key: str) -> str: return playlist_key if parent_type == ParentType.PLAYLIST else source_key + def __(key: str) -> Optional[str]: + return self.kwargs_get(key=key) + return { _(SOURCE_ENTRY, PLAYLIST_ENTRY): self._kwargs, - _(SOURCE_TITLE, PLAYLIST_TITLE): self.title, - _(SOURCE_WEBPAGE_URL, PLAYLIST_WEBPAGE_URL): self.webpage_url, - _(SOURCE_UID, PLAYLIST_UID): self.uid, - _(SOURCE_DESCRIPTION, PLAYLIST_DESCRIPTION): self.description, - _(SOURCE_UPLOADER, PLAYLIST_UPLOADER): self.uploader, - _(SOURCE_UPLOADER_ID, PLAYLIST_UPLOADER_ID): self.uploader_id, - _(SOURCE_UPLOADER_URL, PLAYLIST_UPLOADER_URL): self.uploader_url, + _(SOURCE_TITLE, PLAYLIST_TITLE): __(TITLE), + _(SOURCE_WEBPAGE_URL, PLAYLIST_WEBPAGE_URL): __(WEBPAGE_URL), + _(SOURCE_UID, PLAYLIST_UID): __(UID), + _(SOURCE_DESCRIPTION, PLAYLIST_DESCRIPTION): __(DESCRIPTION), + _(SOURCE_UPLOADER, PLAYLIST_UPLOADER): __(UPLOADER), + _(SOURCE_UPLOADER_ID, PLAYLIST_UPLOADER_ID): __(UPLOADER_ID), + _(SOURCE_UPLOADER_URL, PLAYLIST_UPLOADER_URL): __(UPLOADER_URL), } def _get_entry_children_variable_list(self, variable_name: str) -> List[str | int]: diff --git a/src/ytdl_sub/entries/variables/kwargs.py b/src/ytdl_sub/entries/variables/kwargs.py index a55223fe..91c6edc6 100644 --- a/src/ytdl_sub/entries/variables/kwargs.py +++ b/src/ytdl_sub/entries/variables/kwargs.py @@ -40,6 +40,7 @@ PLAYLIST_UPLOADER = _("playlist_uploader") PLAYLIST_UPLOADER_ID = _("playlist_uploader_id") PLAYLIST_UPLOADER_URL = _("playlist_uploader_url") +UID = _("id") EXT = _("ext") TITLE = _("title") DESCRIPTION = _("description") diff --git a/src/ytdl_sub/plugins/split_by_chapters.py b/src/ytdl_sub/plugins/split_by_chapters.py index 54385b97..1dfbceb8 100644 --- a/src/ytdl_sub/plugins/split_by_chapters.py +++ b/src/ytdl_sub/plugins/split_by_chapters.py @@ -8,6 +8,7 @@ from typing import Tuple from yt_dlp.utils import sanitize_filename from ytdl_sub.entries.entry import Entry +from ytdl_sub.entries.variables.kwargs import UID from ytdl_sub.plugins.plugin import Plugin from ytdl_sub.plugins.plugin import PluginOptions from ytdl_sub.utils.chapters import Chapters @@ -113,7 +114,7 @@ class SplitByChaptersPlugin(Plugin[SplitByChaptersOptions]): ) # pylint: disable=protected-access - entry._kwargs["id"] = _split_video_uid(source_uid=entry.uid, idx=idx) + entry._kwargs[UID] = _split_video_uid(source_uid=entry.uid, idx=idx) if "chapters" in entry._kwargs: del entry._kwargs["chapters"] if "sponsorblock_chapters" in entry._kwargs: