From f97ab6aaa86443751dfbe2d6fd63cc0c75b6a8de Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Tue, 12 Dec 2023 13:08:25 -0800 Subject: [PATCH] chapters working --- src/ytdl_sub/entries/variables/kwargs.py | 1 - src/ytdl_sub/plugins/chapters.py | 9 ++++----- src/ytdl_sub/plugins/split_by_chapters.py | 3 --- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ytdl_sub/entries/variables/kwargs.py b/src/ytdl_sub/entries/variables/kwargs.py index 5c66ccfa..a1f6ecae 100644 --- a/src/ytdl_sub/entries/variables/kwargs.py +++ b/src/ytdl_sub/entries/variables/kwargs.py @@ -18,7 +18,6 @@ def _(key: str, backend: bool = False) -> str: CHAPTERS = _("chapters", backend=True) YTDL_SUB_CUSTOM_CHAPTERS = _("ytdl_sub_custom_chapters", backend=True) -SPONSORBLOCK_CHAPTERS = _("sponsorblock_chapters", backend=True) SPLIT_BY_CHAPTERS_PARENT_ENTRY = _("split_by_chapters_parent_entry", backend=True) COMMENTS = _("comments", backend=True) UID = _("id") diff --git a/src/ytdl_sub/plugins/chapters.py b/src/ytdl_sub/plugins/chapters.py index ae507248..a9d5dcec 100644 --- a/src/ytdl_sub/plugins/chapters.py +++ b/src/ytdl_sub/plugins/chapters.py @@ -9,6 +9,7 @@ from ytdl_sub.config.plugin import Plugin from ytdl_sub.config.preset_options import OptionsDictValidator from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder from ytdl_sub.entries.entry import Entry +from ytdl_sub.entries.script.variable_definitions import VARIABLES from ytdl_sub.entries.script.variable_definitions import VARIABLES as v from ytdl_sub.entries.variables.kwargs import YTDL_SUB_CUSTOM_CHAPTERS from ytdl_sub.utils.chapters import Chapters @@ -39,9 +40,7 @@ def _chapters(entry: Entry) -> List[Dict]: def _sponsorblock_chapters(entry: Entry) -> List[Dict]: - if entry.kwargs_contains("sponsorblock_chapters"): - return entry.kwargs("sponsorblock_chapters") or [] - return [] + return entry.get(v.sponsorblock_chapters, list) def _contains_any_chapters(entry: Entry) -> bool: @@ -300,10 +299,10 @@ class ChaptersPlugin(Plugin[ChaptersOptions]): ------- entry """ - chapters = Chapters.from_empty() - # If there are no embedded chapters, and comment chapters are allowed... if not _contains_any_chapters(entry) and self.plugin_options.allow_chapters_from_comments: + chapters = Chapters.from_empty() + # Try to get chapters from comments for comment in entry.get(v.comments, list): chapters = Chapters.from_string(comment.get("text", "")) diff --git a/src/ytdl_sub/plugins/split_by_chapters.py b/src/ytdl_sub/plugins/split_by_chapters.py index 702a68ab..c2266560 100644 --- a/src/ytdl_sub/plugins/split_by_chapters.py +++ b/src/ytdl_sub/plugins/split_by_chapters.py @@ -15,7 +15,6 @@ from ytdl_sub.config.preset_options import PluginOperation from ytdl_sub.entries.entry import Entry from ytdl_sub.entries.variables.kwargs import CHAPTERS from ytdl_sub.entries.variables.kwargs import SPLIT_BY_CHAPTERS_PARENT_ENTRY -from ytdl_sub.entries.variables.kwargs import SPONSORBLOCK_CHAPTERS from ytdl_sub.entries.variables.kwargs import UID from ytdl_sub.utils.chapters import Chapters from ytdl_sub.utils.chapters import Timestamp @@ -137,8 +136,6 @@ class SplitByChaptersPlugin(SplitPlugin[SplitByChaptersOptions]): if entry.kwargs_contains(CHAPTERS): del entry._kwargs[CHAPTERS] - if entry.kwargs_contains(SPONSORBLOCK_CHAPTERS): - del entry._kwargs[SPONSORBLOCK_CHAPTERS] # pylint: enable=protected-access timestamp_begin = chapters.timestamps[idx].readable_str