mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-09-25 16:20:11 +00:00
[SponsorBlock] Add Filler and Highlight categories (#1664)
Authored by: nihil-admirari, pukkandan
This commit is contained in:
@@ -1465,20 +1465,29 @@ def parseOpts(overrideArguments=None):
|
||||
sponsorblock.add_option(
|
||||
'--sponsorblock-mark', metavar='CATS',
|
||||
dest='sponsorblock_mark', default=set(), action='callback', type='str',
|
||||
callback=_set_from_options_callback, callback_kwargs={'allowed_values': SponsorBlockPP.CATEGORIES.keys()},
|
||||
help=(
|
||||
callback=_set_from_options_callback, callback_kwargs={
|
||||
'allowed_values': SponsorBlockPP.CATEGORIES.keys(),
|
||||
'aliases': {'default': ['all']}
|
||||
}, help=(
|
||||
'SponsorBlock categories to create chapters for, separated by commas. '
|
||||
'Available categories are all, %s. You can prefix the category with a "-" to exempt it. '
|
||||
'See https://wiki.sponsor.ajay.app/index.php/Segment_Categories for description of the categories. '
|
||||
'Eg: --sponsorblock-mark all,-preview' % ', '.join(SponsorBlockPP.CATEGORIES.keys())))
|
||||
f'Available categories are all, default(=all), {", ".join(SponsorBlockPP.CATEGORIES.keys())}. '
|
||||
'You can prefix the category with a "-" to exempt it. See [1] for description of the categories. '
|
||||
'Eg: --sponsorblock-mark all,-preview [1] https://wiki.sponsor.ajay.app/w/Segment_Categories'))
|
||||
sponsorblock.add_option(
|
||||
'--sponsorblock-remove', metavar='CATS',
|
||||
dest='sponsorblock_remove', default=set(), action='callback', type='str',
|
||||
callback=_set_from_options_callback, callback_kwargs={'allowed_values': SponsorBlockPP.CATEGORIES.keys()},
|
||||
help=(
|
||||
callback=_set_from_options_callback, callback_kwargs={
|
||||
'allowed_values': set(SponsorBlockPP.CATEGORIES.keys()) - set(SponsorBlockPP.POI_CATEGORIES.keys()),
|
||||
# Note: From https://wiki.sponsor.ajay.app/w/Types:
|
||||
# The filler category is very aggressive.
|
||||
# It is strongly recommended to not use this in a client by default.
|
||||
'aliases': {'default': ['all', '-filler']}
|
||||
}, help=(
|
||||
'SponsorBlock categories to be removed from the video file, separated by commas. '
|
||||
'If a category is present in both mark and remove, remove takes precedence. '
|
||||
'The syntax and available categories are the same as for --sponsorblock-mark'))
|
||||
'The syntax and available categories are the same as for --sponsorblock-mark '
|
||||
'except that "default" refers to "all,-filler" '
|
||||
f'and {", ".join(SponsorBlockPP.POI_CATEGORIES.keys())} is not available'))
|
||||
sponsorblock.add_option(
|
||||
'--sponsorblock-chapter-title', metavar='TEMPLATE',
|
||||
default=DEFAULT_SPONSORBLOCK_CHAPTER_TITLE, dest='sponsorblock_chapter_title',
|
||||
|
@@ -24,7 +24,7 @@ class ModifyChaptersPP(FFmpegPostProcessor):
|
||||
*, sponsorblock_chapter_title=DEFAULT_SPONSORBLOCK_CHAPTER_TITLE, force_keyframes=False):
|
||||
FFmpegPostProcessor.__init__(self, downloader)
|
||||
self._remove_chapters_patterns = set(remove_chapters_patterns or [])
|
||||
self._remove_sponsor_segments = set(remove_sponsor_segments or [])
|
||||
self._remove_sponsor_segments = set(remove_sponsor_segments or []) - set(SponsorBlockPP.POI_CATEGORIES.keys())
|
||||
self._ranges_to_remove = set(remove_ranges or [])
|
||||
self._sponsorblock_chapter_title = sponsorblock_chapter_title
|
||||
self._force_keyframes = force_keyframes
|
||||
@@ -302,7 +302,7 @@ class ModifyChaptersPP(FFmpegPostProcessor):
|
||||
'name': SponsorBlockPP.CATEGORIES[category],
|
||||
'category_names': [SponsorBlockPP.CATEGORIES[c] for c in cats]
|
||||
})
|
||||
c['title'] = self._downloader.evaluate_outtmpl(self._sponsorblock_chapter_title, c)
|
||||
c['title'] = self._downloader.evaluate_outtmpl(self._sponsorblock_chapter_title, c.copy())
|
||||
# Merge identically named sponsors.
|
||||
if (new_chapters and 'categories' in new_chapters[-1]
|
||||
and new_chapters[-1]['title'] == c['title']):
|
||||
|
@@ -10,18 +10,23 @@ from ..utils import PostProcessingError, network_exceptions, sanitized_Request
|
||||
|
||||
|
||||
class SponsorBlockPP(FFmpegPostProcessor):
|
||||
|
||||
# https://wiki.sponsor.ajay.app/w/Types
|
||||
EXTRACTORS = {
|
||||
'Youtube': 'YouTube',
|
||||
}
|
||||
POI_CATEGORIES = {
|
||||
'poi_highlight': 'Highlight',
|
||||
}
|
||||
CATEGORIES = {
|
||||
'sponsor': 'Sponsor',
|
||||
'intro': 'Intermission/Intro Animation',
|
||||
'outro': 'Endcards/Credits',
|
||||
'selfpromo': 'Unpaid/Self Promotion',
|
||||
'interaction': 'Interaction Reminder',
|
||||
'preview': 'Preview/Recap',
|
||||
'music_offtopic': 'Non-Music Section'
|
||||
'filler': 'Filler Tangent',
|
||||
'interaction': 'Interaction Reminder',
|
||||
'music_offtopic': 'Non-Music Section',
|
||||
**POI_CATEGORIES,
|
||||
}
|
||||
|
||||
def __init__(self, downloader, categories=None, api='https://sponsor.ajay.app'):
|
||||
@@ -47,6 +52,9 @@ class SponsorBlockPP(FFmpegPostProcessor):
|
||||
# Ignore milliseconds difference at the start.
|
||||
if start_end[0] <= 1:
|
||||
start_end[0] = 0
|
||||
# Make POI chapters 1 sec so that we can properly mark them
|
||||
if s['category'] in self.POI_CATEGORIES.keys():
|
||||
start_end[1] += 1
|
||||
# Ignore milliseconds difference at the end.
|
||||
# Never allow the segment to exceed the video.
|
||||
if duration and duration - start_end[1] <= 1:
|
||||
|
Reference in New Issue
Block a user