mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-09-03 16:45:17 +00:00
Improve --download-sections
* Support negative time-ranges * Add `*from-url` to obey time-ranges in URL Closes #7248
This commit is contained in:
@ -3753,11 +3753,11 @@ def match_filter_func(filters, breaking_filters=None):
|
||||
|
||||
|
||||
class download_range_func:
|
||||
def __init__(self, chapters, ranges):
|
||||
self.chapters, self.ranges = chapters, ranges
|
||||
def __init__(self, chapters, ranges, from_info=False):
|
||||
self.chapters, self.ranges, self.from_info = chapters, ranges, from_info
|
||||
|
||||
def __call__(self, info_dict, ydl):
|
||||
if not self.ranges and not self.chapters:
|
||||
if not any((self.ranges, self.chapters, self.from_info)):
|
||||
yield {}
|
||||
|
||||
warning = ('There are no chapters matching the regex' if info_dict.get('chapters')
|
||||
@ -3770,7 +3770,21 @@ class download_range_func:
|
||||
if self.chapters and warning:
|
||||
ydl.to_screen(f'[info] {info_dict["id"]}: {warning}')
|
||||
|
||||
yield from ({'start_time': start, 'end_time': end} for start, end in self.ranges or [])
|
||||
for start, end in self.ranges or []:
|
||||
yield {
|
||||
'start_time': self._handle_negative_timestamp(start, info_dict),
|
||||
'end_time': self._handle_negative_timestamp(end, info_dict),
|
||||
}
|
||||
|
||||
if self.from_info and (info_dict.get('start_time') or info_dict.get('end_time')):
|
||||
yield {
|
||||
'start_time': info_dict.get('start_time'),
|
||||
'end_time': info_dict.get('end_time'),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _handle_negative_timestamp(time, info):
|
||||
return max(info['duration'] + time, 0) if info.get('duration') and time < 0 else time
|
||||
|
||||
def __eq__(self, other):
|
||||
return (isinstance(other, download_range_func)
|
||||
|
Reference in New Issue
Block a user