chapters working

This commit is contained in:
Jesse Bannon 2023-12-12 13:08:25 -08:00
parent 67a6972b0a
commit f97ab6aaa8
3 changed files with 4 additions and 9 deletions

View file

@ -18,7 +18,6 @@ def _(key: str, backend: bool = False) -> str:
CHAPTERS = _("chapters", backend=True) CHAPTERS = _("chapters", backend=True)
YTDL_SUB_CUSTOM_CHAPTERS = _("ytdl_sub_custom_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) SPLIT_BY_CHAPTERS_PARENT_ENTRY = _("split_by_chapters_parent_entry", backend=True)
COMMENTS = _("comments", backend=True) COMMENTS = _("comments", backend=True)
UID = _("id") UID = _("id")

View file

@ -9,6 +9,7 @@ from ytdl_sub.config.plugin import Plugin
from ytdl_sub.config.preset_options import OptionsDictValidator from ytdl_sub.config.preset_options import OptionsDictValidator
from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder
from ytdl_sub.entries.entry import Entry 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.script.variable_definitions import VARIABLES as v
from ytdl_sub.entries.variables.kwargs import YTDL_SUB_CUSTOM_CHAPTERS from ytdl_sub.entries.variables.kwargs import YTDL_SUB_CUSTOM_CHAPTERS
from ytdl_sub.utils.chapters import 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]: def _sponsorblock_chapters(entry: Entry) -> List[Dict]:
if entry.kwargs_contains("sponsorblock_chapters"): return entry.get(v.sponsorblock_chapters, list)
return entry.kwargs("sponsorblock_chapters") or []
return []
def _contains_any_chapters(entry: Entry) -> bool: def _contains_any_chapters(entry: Entry) -> bool:
@ -300,10 +299,10 @@ class ChaptersPlugin(Plugin[ChaptersOptions]):
------- -------
entry entry
""" """
chapters = Chapters.from_empty()
# If there are no embedded chapters, and comment chapters are allowed... # 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: if not _contains_any_chapters(entry) and self.plugin_options.allow_chapters_from_comments:
chapters = Chapters.from_empty()
# Try to get chapters from comments # Try to get chapters from comments
for comment in entry.get(v.comments, list): for comment in entry.get(v.comments, list):
chapters = Chapters.from_string(comment.get("text", "")) chapters = Chapters.from_string(comment.get("text", ""))

View file

@ -15,7 +15,6 @@ from ytdl_sub.config.preset_options import PluginOperation
from ytdl_sub.entries.entry import Entry from ytdl_sub.entries.entry import Entry
from ytdl_sub.entries.variables.kwargs import CHAPTERS 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 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.entries.variables.kwargs import UID
from ytdl_sub.utils.chapters import Chapters from ytdl_sub.utils.chapters import Chapters
from ytdl_sub.utils.chapters import Timestamp from ytdl_sub.utils.chapters import Timestamp
@ -137,8 +136,6 @@ class SplitByChaptersPlugin(SplitPlugin[SplitByChaptersOptions]):
if entry.kwargs_contains(CHAPTERS): if entry.kwargs_contains(CHAPTERS):
del entry._kwargs[CHAPTERS] del entry._kwargs[CHAPTERS]
if entry.kwargs_contains(SPONSORBLOCK_CHAPTERS):
del entry._kwargs[SPONSORBLOCK_CHAPTERS]
# pylint: enable=protected-access # pylint: enable=protected-access
timestamp_begin = chapters.timestamps[idx].readable_str timestamp_begin = chapters.timestamps[idx].readable_str