[core/yt_live_chat] live_chat is back. dl() new parameter

This commit is contained in:
Unknown 2020-10-31 05:46:51 +01:00
parent 4932ba4aec
commit 9f448fcb26
4 changed files with 24 additions and 13 deletions

View File

@ -1857,13 +1857,13 @@ def ensure_dir_exists(path):
self.report_error('Cannot write annotations file: ' + annofn)
return
def dl(name, info):
def dl(name, info, subtitle=False):
fd = get_suitable_downloader(info, self.params)(self, self.params)
for ph in self._progress_hooks:
fd.add_progress_hook(ph)
if self.params.get('verbose'):
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),
self.params.get('writeautomaticsub')])
@ -1891,6 +1891,8 @@ def dl(name, info):
return
else:
try:
dl(sub_filename, sub_info, subtitle=True)
'''
if self.params.get('sleep_interval_subtitles', False):
dl(sub_filename, sub_info)
else:
@ -1898,6 +1900,7 @@ def dl(name, info):
sub_info['url'], info_dict['id'], note=False).read()
with io.open(encodeFilename(sub_filename), 'wb') as subfile:
subfile.write(sub_data)
'''
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' %
(sub_lang, error_to_compat_str(err)))

View File

@ -326,7 +326,7 @@ def report_unable_to_resume(self):
"""Report it was impossible to resume download."""
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
Return True on success and False otherwise
"""
@ -353,6 +353,7 @@ def download(self, filename, info_dict):
})
return True
if subtitle is False:
min_sleep_interval = self.params.get('sleep_interval')
if min_sleep_interval:
max_sleep_interval = self.params.get('max_sleep_interval', min_sleep_interval)
@ -362,6 +363,13 @@ def download(self, filename, info_dict):
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(
'[download] Sleeping %s seconds...' % (
int(sleep_interval_sub)))
time.sleep(sleep_interval_sub)
return self.real_download(filename, info_dict)

View File

@ -1366,14 +1366,14 @@ def _get_subtitles(self, video_id, webpage, has_live_chat_replay):
'ext': ext,
})
sub_lang_list[lang] = sub_formats
""" if has_live_chat_replay:
if has_live_chat_replay:
sub_lang_list['live_chat'] = [
{
'video_id': video_id,
'ext': 'json',
'protocol': 'youtube_live_chat_replay',
},
] """
]
if not sub_lang_list:
self._downloader.report_warning('video doesn\'t have subtitles')
return {}

View File

@ -582,7 +582,7 @@ def _comma_separated_values_options_callback(option, opt_str, value, parser):
'along with --min-sleep-interval.'))
workarounds.add_option(
'--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')
verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')