Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yt-dlp/yt-dlp into ytdlp
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/yt-dlp/yt-dlp:
  Use `parse_duration` for `--wait-for-video` and some minor fix
  Allow `--no-write-thumbnail` to override `--write-all-thumbnail` Closes #1900
  bugfix for 63ccf4f
  • Loading branch information
Lesmiscore committed Dec 6, 2021
2 parents 761bac6 + 38d79fd commit af3db08
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions yt_dlp/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,11 +1424,11 @@ def progress(msg):
min_wait, max_wait = self.params.get('wait_for_video')
diff = try_get(ie_result, lambda x: x['release_timestamp'] - time.time())
if diff is None and ie_result.get('live_status') == 'is_upcoming':
diff = random.randrange(min_wait or 0, max_wait) if max_wait else min_wait
diff = random.randrange(min_wait, max_wait) if (max_wait and min_wait) else (max_wait or min_wait)
self.report_warning('Release time of video is not known')
elif (diff or 0) <= 0:
self.report_warning('Video should already be available according to extracted info')
diff = min(max(diff, min_wait or 0), max_wait or float('inf'))
diff = min(max(diff or 0, min_wait or 0), max_wait or float('inf'))
self.to_screen(f'[wait] Waiting for {format_dur(diff)} - Press Ctrl+C to try now')

wait_till = time.time() + diff
Expand Down
18 changes: 8 additions & 10 deletions yt_dlp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,11 @@ def _real_main(argv=None):
if opts.concurrent_fragment_downloads <= 0:
parser.error('Concurrent fragments must be positive')
if opts.wait_for_video is not None:
mobj = re.match(r'(?P<min>\d+)(?:-(?P<max>\d+))?$', opts.wait_for_video)
if not mobj:
parser.error('Invalid time range to wait')
min_wait, max_wait = map(int_or_none, mobj.group('min', 'max'))
if max_wait is not None and max_wait < min_wait:
min_wait, max_wait, *_ = map(parse_duration, opts.wait_for_video.split('-', 1) + [None])
if min_wait is None or (max_wait is None and '-' in opts.wait_for_video):
parser.error('Invalid time range to wait')
elif max_wait is not None and max_wait < min_wait:
parser.error('Minimum time range to wait must not be longer than the maximum')
opts.wait_for_video = (min_wait, max_wait)

def parse_retries(retries, name=''):
Expand Down Expand Up @@ -578,13 +577,12 @@ def report_unplayable_conflict(opt_name, arg, default=False, allowed=None):
'_from_cli': True,
})
if opts.embedthumbnail:
already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails
postprocessors.append({
'key': 'EmbedThumbnail',
# already_have_thumbnail = True prevents the file from being deleted after embedding
'already_have_thumbnail': already_have_thumbnail
'already_have_thumbnail': opts.writethumbnail
})
if not already_have_thumbnail:
if not opts.writethumbnail:
opts.writethumbnail = True
opts.outtmpl['pl_thumbnail'] = ''
if opts.split_chapters:
Expand Down Expand Up @@ -714,8 +712,8 @@ def report_deprecation(val, old, new=None):
'allow_playlist_files': opts.allow_playlist_files,
'clean_infojson': opts.clean_infojson,
'getcomments': opts.getcomments,
'writethumbnail': opts.writethumbnail,
'write_all_thumbnails': opts.write_all_thumbnails,
'writethumbnail': opts.writethumbnail is True,
'write_all_thumbnails': opts.writethumbnail == 'all',
'writelink': opts.writelink,
'writeurllink': opts.writeurllink,
'writewebloclink': opts.writewebloclink,
Expand Down
8 changes: 4 additions & 4 deletions yt_dlp/extractor/niconico.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,16 +896,16 @@ def _entries(self, url, item_id, query=None, note='Downloading page %(page)s'):
if not results:
break

def _search_results(self, query):
return self._entries(
self._proto_relative_url(f'//www.nicovideo.jp/search/{query}'), query)


class NicovideoSearchIE(NicovideoSearchBaseIE, SearchInfoExtractor):
IE_DESC = 'Nico video search'
IE_NAME = 'nicovideo:search'
_SEARCH_KEY = 'nicosearch'

def _search_results(self, query):
return self._entries(
self._proto_relative_url(f'//www.nicovideo.jp/search/{query}'), query)


class NicovideoSearchURLIE(NicovideoSearchBaseIE):
IE_NAME = f'{NicovideoSearchIE.IE_NAME}_url'
Expand Down
7 changes: 5 additions & 2 deletions yt_dlp/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,15 +1281,18 @@ def _dict_from_options_callback(
thumbnail = optparse.OptionGroup(parser, 'Thumbnail Options')
thumbnail.add_option(
'--write-thumbnail',
action='store_true', dest='writethumbnail', default=False,
action='callback', dest='writethumbnail', default=False,
# Should override --no-write-thumbnail, but not --write-all-thumbnail
callback=lambda option, _, __, parser: setattr(
parser.values, option.dest, getattr(parser.values, option.dest) or True),
help='Write thumbnail image to disk')
thumbnail.add_option(
'--no-write-thumbnail',
action='store_false', dest='writethumbnail',
help='Do not write thumbnail image to disk (default)')
thumbnail.add_option(
'--write-all-thumbnails',
action='store_true', dest='write_all_thumbnails', default=False,
action='store_const', dest='writethumbnail', const='all',
help='Write all thumbnail image formats to disk')
thumbnail.add_option(
'--list-thumbnails',
Expand Down
3 changes: 2 additions & 1 deletion yt_dlp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2447,8 +2447,9 @@ def strftime_or_none(timestamp, date_format, default=None):
def parse_duration(s):
if not isinstance(s, compat_basestring):
return None

s = s.strip()
if not s:
return None

days, hours, mins, secs, ms = [None] * 5
m = re.match(r'(?:(?:(?:(?P<days>[0-9]+):)?(?P<hours>[0-9]+):)?(?P<mins>[0-9]+):)?(?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?Z?$', s)
Expand Down

0 comments on commit af3db08

Please sign in to comment.