mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-23 09:01:43 +00:00
[core/yt_live_chat] live_chat is back. dl() new parameter
This commit is contained in:
parent
4932ba4aec
commit
9f448fcb26
@ -1857,13 +1857,13 @@ def ensure_dir_exists(path):
|
|||||||
self.report_error('Cannot write annotations file: ' + annofn)
|
self.report_error('Cannot write annotations file: ' + annofn)
|
||||||
return
|
return
|
||||||
|
|
||||||
def dl(name, info):
|
def dl(name, info, subtitle=False):
|
||||||
fd = get_suitable_downloader(info, self.params)(self, self.params)
|
fd = get_suitable_downloader(info, self.params)(self, self.params)
|
||||||
for ph in self._progress_hooks:
|
for ph in self._progress_hooks:
|
||||||
fd.add_progress_hook(ph)
|
fd.add_progress_hook(ph)
|
||||||
if self.params.get('verbose'):
|
if self.params.get('verbose'):
|
||||||
self.to_stdout('[debug] Invoking downloader on %r' % info.get('url'))
|
self.to_stdout('[debug] Invoking downloader on %r' % info.get('url'))
|
||||||
return fd.download(name, info)
|
return fd.download(name, info, subtitle)
|
||||||
|
|
||||||
subtitles_are_requested = any([self.params.get('writesubtitles', False),
|
subtitles_are_requested = any([self.params.get('writesubtitles', False),
|
||||||
self.params.get('writeautomaticsub')])
|
self.params.get('writeautomaticsub')])
|
||||||
@ -1891,6 +1891,8 @@ def dl(name, info):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
dl(sub_filename, sub_info, subtitle=True)
|
||||||
|
'''
|
||||||
if self.params.get('sleep_interval_subtitles', False):
|
if self.params.get('sleep_interval_subtitles', False):
|
||||||
dl(sub_filename, sub_info)
|
dl(sub_filename, sub_info)
|
||||||
else:
|
else:
|
||||||
@ -1898,6 +1900,7 @@ def dl(name, info):
|
|||||||
sub_info['url'], info_dict['id'], note=False).read()
|
sub_info['url'], info_dict['id'], note=False).read()
|
||||||
with io.open(encodeFilename(sub_filename), 'wb') as subfile:
|
with io.open(encodeFilename(sub_filename), 'wb') as subfile:
|
||||||
subfile.write(sub_data)
|
subfile.write(sub_data)
|
||||||
|
'''
|
||||||
except (ExtractorError, IOError, OSError, ValueError, compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
except (ExtractorError, IOError, OSError, ValueError, compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||||
self.report_warning('Unable to download subtitle for "%s": %s' %
|
self.report_warning('Unable to download subtitle for "%s": %s' %
|
||||||
(sub_lang, error_to_compat_str(err)))
|
(sub_lang, error_to_compat_str(err)))
|
||||||
|
@ -326,7 +326,7 @@ def report_unable_to_resume(self):
|
|||||||
"""Report it was impossible to resume download."""
|
"""Report it was impossible to resume download."""
|
||||||
self.to_screen('[download] Unable to resume')
|
self.to_screen('[download] Unable to resume')
|
||||||
|
|
||||||
def download(self, filename, info_dict):
|
def download(self, filename, info_dict, subtitle=False):
|
||||||
"""Download to a filename using the info from info_dict
|
"""Download to a filename using the info from info_dict
|
||||||
Return True on success and False otherwise
|
Return True on success and False otherwise
|
||||||
"""
|
"""
|
||||||
@ -353,15 +353,23 @@ def download(self, filename, info_dict):
|
|||||||
})
|
})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
min_sleep_interval = self.params.get('sleep_interval')
|
if subtitle is False:
|
||||||
if min_sleep_interval:
|
min_sleep_interval = self.params.get('sleep_interval')
|
||||||
max_sleep_interval = self.params.get('max_sleep_interval', min_sleep_interval)
|
if min_sleep_interval:
|
||||||
sleep_interval = random.uniform(min_sleep_interval, max_sleep_interval)
|
max_sleep_interval = self.params.get('max_sleep_interval', min_sleep_interval)
|
||||||
|
sleep_interval = random.uniform(min_sleep_interval, max_sleep_interval)
|
||||||
|
self.to_screen(
|
||||||
|
'[download] Sleeping %s seconds...' % (
|
||||||
|
int(sleep_interval) if sleep_interval.is_integer()
|
||||||
|
else '%.2f' % sleep_interval))
|
||||||
|
time.sleep(sleep_interval)
|
||||||
|
else:
|
||||||
|
sleep_interval_sub = self.params.get('sleep_interval_subtitles')
|
||||||
self.to_screen(
|
self.to_screen(
|
||||||
'[download] Sleeping %s seconds...' % (
|
'[download] Sleeping %s seconds...' % (
|
||||||
int(sleep_interval) if sleep_interval.is_integer()
|
int(sleep_interval_sub)))
|
||||||
else '%.2f' % sleep_interval))
|
time.sleep(sleep_interval_sub)
|
||||||
time.sleep(sleep_interval)
|
|
||||||
|
|
||||||
return self.real_download(filename, info_dict)
|
return self.real_download(filename, info_dict)
|
||||||
|
|
||||||
|
@ -1366,14 +1366,14 @@ def _get_subtitles(self, video_id, webpage, has_live_chat_replay):
|
|||||||
'ext': ext,
|
'ext': ext,
|
||||||
})
|
})
|
||||||
sub_lang_list[lang] = sub_formats
|
sub_lang_list[lang] = sub_formats
|
||||||
""" if has_live_chat_replay:
|
if has_live_chat_replay:
|
||||||
sub_lang_list['live_chat'] = [
|
sub_lang_list['live_chat'] = [
|
||||||
{
|
{
|
||||||
'video_id': video_id,
|
'video_id': video_id,
|
||||||
'ext': 'json',
|
'ext': 'json',
|
||||||
'protocol': 'youtube_live_chat_replay',
|
'protocol': 'youtube_live_chat_replay',
|
||||||
},
|
},
|
||||||
] """
|
]
|
||||||
if not sub_lang_list:
|
if not sub_lang_list:
|
||||||
self._downloader.report_warning('video doesn\'t have subtitles')
|
self._downloader.report_warning('video doesn\'t have subtitles')
|
||||||
return {}
|
return {}
|
||||||
|
@ -582,7 +582,7 @@ def _comma_separated_values_options_callback(option, opt_str, value, parser):
|
|||||||
'along with --min-sleep-interval.'))
|
'along with --min-sleep-interval.'))
|
||||||
workarounds.add_option(
|
workarounds.add_option(
|
||||||
'--sleep-subtitles',
|
'--sleep-subtitles',
|
||||||
dest='sleep_interval_subtitles', action='store_true', default=False,
|
dest='sleep_interval_subtitles', action='store_true', default=0,
|
||||||
help='Enforce sleep interval on subtitles as well')
|
help='Enforce sleep interval on subtitles as well')
|
||||||
|
|
||||||
verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
|
verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
|
||||||
|
Loading…
Reference in New Issue
Block a user