0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-26 02:55:17 +00:00

Allow extractors to specify section_start/end for clips

This commit is contained in:
pukkandan 2022-06-22 02:32:14 +05:30
parent 230d5c8239
commit 3975b4d2e8
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
2 changed files with 17 additions and 5 deletions

View file

@ -1596,9 +1596,13 @@ def process_ie_result(self, ie_result, download=True, extra_info=None):
if not info:
return info
exempted_fields = {'_type', 'url', 'ie_key'}
if not ie_result.get('section_end') and ie_result.get('section_start') is None:
# For video clips, the id etc of the clip extractor should be used
exempted_fields |= {'id', 'extractor', 'extractor_key'}
new_result = info.copy()
new_result.update(filter_dict(ie_result, lambda k, v: (
v is not None and k not in {'_type', 'url', 'id', 'extractor', 'extractor_key', 'ie_key'})))
new_result.update(filter_dict(ie_result, lambda k, v: v is not None and k not in exempted_fields))
# Extracted info may not be a video result (i.e.
# info.get('_type', 'video') != video) but rather an url or
@ -2369,6 +2373,8 @@ def sanitize_numeric_fields(info):
sanitize_string_field(info_dict, 'id')
sanitize_numeric_fields(info_dict)
if info_dict.get('section_end') and info_dict.get('section_start') is not None:
info_dict['duration'] = round(info_dict['section_end'] - info_dict['section_start'], 3)
if (info_dict.get('duration') or 0) <= 0 and info_dict.pop('duration', None):
self.report_warning('"duration" field is negative, there is an error in extractor')
@ -2604,10 +2610,11 @@ def to_screen(*msg):
for fmt, chapter in itertools.product(formats_to_download, requested_ranges or [{}]):
new_info = self._copy_infodict(info_dict)
new_info.update(fmt)
if chapter:
offset, duration = info_dict.get('section_start') or 0, info_dict.get('duration') or float('inf')
if chapter or offset:
new_info.update({
'section_start': chapter.get('start_time'),
'section_end': chapter.get('end_time', 0),
'section_start': offset + chapter.get('start_time', 0),
'section_end': offset + min(chapter.get('end_time', 0), duration),
'section_title': chapter.get('title'),
'section_number': chapter.get('index'),
})

View file

@ -385,6 +385,11 @@ class InfoExtractor:
release_year: Year (YYYY) when the album was released.
composer: Composer of the piece
The following fields should only be set for clips that should be cut from the original video:
section_start: Start time of the section in seconds
section_end: End time of the section in seconds
Unless mentioned otherwise, the fields should be Unicode strings.
Unless mentioned otherwise, None is equivalent to absence of information.