mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-02 16:32:51 +01:00
[utils] Add hackish 'now' support for --download-sections
This commit is contained in:
parent
9b7a48abd1
commit
2fbd6de957
|
@ -42,6 +42,7 @@
|
||||||
GeoUtils,
|
GeoUtils,
|
||||||
PlaylistEntries,
|
PlaylistEntries,
|
||||||
SameFileError,
|
SameFileError,
|
||||||
|
datetime_from_str,
|
||||||
decodeOption,
|
decodeOption,
|
||||||
download_range_func,
|
download_range_func,
|
||||||
expand_path,
|
expand_path,
|
||||||
|
@ -320,12 +321,23 @@ def validate_outtmpl(tmpl, msg):
|
||||||
del opts.outtmpl['default']
|
del opts.outtmpl['default']
|
||||||
|
|
||||||
def parse_chapters(name, value):
|
def parse_chapters(name, value):
|
||||||
|
def parse_timestamp(x):
|
||||||
|
# FIXME: This should be smarter, e.g. 'inf-1day'?
|
||||||
|
x = x.replace('(', '').replace(')', '')
|
||||||
|
|
||||||
|
if x in ('inf', 'infinite'):
|
||||||
|
return float('inf')
|
||||||
|
|
||||||
|
if re.match(r'[\d:]+', x):
|
||||||
|
return parse_duration(x)
|
||||||
|
|
||||||
|
return datetime_from_str(x, precision='second').timestamp()
|
||||||
|
|
||||||
chapters, ranges = [], []
|
chapters, ranges = [], []
|
||||||
parse_timestamp = lambda x: float('inf') if x in ('inf', 'infinite') else parse_duration(x)
|
|
||||||
for regex in value or []:
|
for regex in value or []:
|
||||||
if regex.startswith('*'):
|
if regex.startswith('*'):
|
||||||
for range_ in map(str.strip, regex[1:].split(',')):
|
for range_ in map(str.strip, regex[1:].split(',')):
|
||||||
mobj = range_ != '-' and re.fullmatch(r'([^-]+)?\s*-\s*([^-]+)?', range_)
|
mobj = range_ != '-' and re.fullmatch(r'(.+)?\s*-\s*(.+)?', range_)
|
||||||
dur = mobj and (parse_timestamp(mobj.group(1) or '0'), parse_timestamp(mobj.group(2) or 'inf'))
|
dur = mobj and (parse_timestamp(mobj.group(1) or '0'), parse_timestamp(mobj.group(2) or 'inf'))
|
||||||
if None in (dur or [None]):
|
if None in (dur or [None]):
|
||||||
raise ValueError(f'invalid {name} time range "{regex}". Must be of the form "*start-end"')
|
raise ValueError(f'invalid {name} time range "{regex}". Must be of the form "*start-end"')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user