mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-02-01 08:10:10 +09:00
Moving protocol to download subtitles back to the subtitle_info and keep the download logic in YoutubeDl
This commit is contained in:
parent
d0774569c1
commit
5fb593d50a
@ -1771,7 +1771,7 @@ class YoutubeDL(object):
|
|||||||
self.to_stdout(formatSeconds(info_dict['duration']))
|
self.to_stdout(formatSeconds(info_dict['duration']))
|
||||||
print_mandatory('format')
|
print_mandatory('format')
|
||||||
if self.params.get('forcejson', False):
|
if self.params.get('forcejson', False):
|
||||||
self.to_stdout(json.dumps(info_dict, default=lambda _:'<not serialized>'))
|
self.to_stdout(json.dumps(info_dict))
|
||||||
|
|
||||||
def process_info(self, info_dict):
|
def process_info(self, info_dict):
|
||||||
"""Process a single resolved IE result."""
|
"""Process a single resolved IE result."""
|
||||||
@ -1879,15 +1879,16 @@ class YoutubeDL(object):
|
|||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
self.report_error('Cannot write subtitles file ' + sub_filename)
|
self.report_error('Cannot write subtitles file ' + sub_filename)
|
||||||
return
|
return
|
||||||
elif callable(sub_info.get('downloader')):
|
|
||||||
sub_info.get('downloader')(self, encodeFilename(sub_filename))
|
|
||||||
else:
|
else:
|
||||||
|
fd = get_suitable_downloader(sub_info, self.params)(self, self.params)
|
||||||
try:
|
try:
|
||||||
sub_data = ie._request_webpage(
|
if self.params.get('verbose'):
|
||||||
sub_info['url'], info_dict['id'], note=False).read()
|
self.to_screen('[debug] Invoking subtitle downloader on %r' % sub_info.get('url'))
|
||||||
with io.open(encodeFilename(sub_filename), 'wb') as subfile:
|
# The FD is supposed to encodeFilename()
|
||||||
subfile.write(sub_data)
|
if not fd.download(sub_filename, sub_info):
|
||||||
except (ExtractorError, IOError, OSError, ValueError) as err:
|
# depending on the FD, it may catch errors and return False, or not
|
||||||
|
raise DownloadError('Subtitle download failed')
|
||||||
|
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error, OSError, IOError, YoutubeDLError) 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)))
|
||||||
continue
|
continue
|
||||||
@ -2076,7 +2077,7 @@ class YoutubeDL(object):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
if self.params.get('dump_single_json', False):
|
if self.params.get('dump_single_json', False):
|
||||||
self.to_stdout(json.dumps(res, default=lambda _:'<not serialized>'))
|
self.to_stdout(json.dumps(res))
|
||||||
|
|
||||||
return self._download_retcode
|
return self._download_retcode
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ def get_suitable_downloader(info_dict, params={}):
|
|||||||
"""Get the downloader class that can handle the info dict."""
|
"""Get the downloader class that can handle the info dict."""
|
||||||
protocol = determine_protocol(info_dict)
|
protocol = determine_protocol(info_dict)
|
||||||
info_dict['protocol'] = protocol
|
info_dict['protocol'] = protocol
|
||||||
|
print('SACHA> ', protocol)
|
||||||
|
|
||||||
# if (info_dict.get('start_time') or info_dict.get('end_time')) and not info_dict.get('requested_formats') and FFmpegFD.can_download(info_dict):
|
# if (info_dict.get('start_time') or info_dict.get('end_time')) and not info_dict.get('requested_formats') and FFmpegFD.can_download(info_dict):
|
||||||
# return FFmpegFD
|
# return FFmpegFD
|
||||||
|
@ -1708,6 +1708,7 @@ class InfoExtractor(object):
|
|||||||
subtitles[media['LANGUAGE']] = [{
|
subtitles[media['LANGUAGE']] = [{
|
||||||
'url': format_url(media['URI']),
|
'url': format_url(media['URI']),
|
||||||
'ext': media.get('SUBFORMAT', 'webtt'),
|
'ext': media.get('SUBFORMAT', 'webtt'),
|
||||||
|
'protocol': 'm3u8_native',
|
||||||
}]
|
}]
|
||||||
return
|
return
|
||||||
if media_type not in ('VIDEO', 'AUDIO'):
|
if media_type not in ('VIDEO', 'AUDIO'):
|
||||||
|
@ -206,10 +206,6 @@ class FranceTVIE(InfoExtractor):
|
|||||||
info['title'] += ' - %s' % info['subtitle']
|
info['title'] += ' - %s' % info['subtitle']
|
||||||
info['title'] = info['title'].strip()
|
info['title'] = info['title'].strip()
|
||||||
|
|
||||||
for lang, sts in info['subtitles'].items():
|
|
||||||
for st in sts:
|
|
||||||
st['downloader'] = lambda ydl, filename: PROTOCOL_MAP['m3u8_native'](ydl, ydl.params).download(filename, st)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': self._live_title(info['title']) if is_live else info['title'],
|
'title': self._live_title(info['title']) if is_live else info['title'],
|
||||||
|
@ -1830,7 +1830,7 @@ def write_json_file(obj, fn):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with tf:
|
with tf:
|
||||||
json.dump(obj, tf, default=lambda _:'<not serialized>')
|
json.dump(obj)
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# Need to remove existing file on Windows, else os.rename raises
|
# Need to remove existing file on Windows, else os.rename raises
|
||||||
# WindowsError or FileExistsError.
|
# WindowsError or FileExistsError.
|
||||||
|
Loading…
Reference in New Issue
Block a user