diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index dc4005a18..018d585ee 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1771,7 +1771,7 @@ class YoutubeDL(object): self.to_stdout(formatSeconds(info_dict['duration'])) print_mandatory('format') if self.params.get('forcejson', False): - self.to_stdout(json.dumps(info_dict, default=lambda _:'')) + self.to_stdout(json.dumps(info_dict)) def process_info(self, info_dict): """Process a single resolved IE result.""" @@ -1879,15 +1879,16 @@ class YoutubeDL(object): except (OSError, IOError): self.report_error('Cannot write subtitles file ' + sub_filename) return - elif callable(sub_info.get('downloader')): - sub_info.get('downloader')(self, encodeFilename(sub_filename)) else: + fd = get_suitable_downloader(sub_info, self.params)(self, self.params) try: - sub_data = ie._request_webpage( - 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) as err: + if self.params.get('verbose'): + self.to_screen('[debug] Invoking subtitle downloader on %r' % sub_info.get('url')) + # The FD is supposed to encodeFilename() + if not fd.download(sub_filename, sub_info): + # 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' % (sub_lang, error_to_compat_str(err))) continue @@ -2076,7 +2077,7 @@ class YoutubeDL(object): raise else: if self.params.get('dump_single_json', False): - self.to_stdout(json.dumps(res, default=lambda _:'')) + self.to_stdout(json.dumps(res)) return self._download_retcode diff --git a/youtube_dl/downloader/__init__.py b/youtube_dl/downloader/__init__.py index 2e485df9d..f3200566e 100644 --- a/youtube_dl/downloader/__init__.py +++ b/youtube_dl/downloader/__init__.py @@ -33,7 +33,8 @@ def get_suitable_downloader(info_dict, params={}): """Get the downloader class that can handle the info dict.""" protocol = determine_protocol(info_dict) 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): # return FFmpegFD diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 058e224d4..e45c67f94 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -1708,6 +1708,7 @@ class InfoExtractor(object): subtitles[media['LANGUAGE']] = [{ 'url': format_url(media['URI']), 'ext': media.get('SUBFORMAT', 'webtt'), + 'protocol': 'm3u8_native', }] return if media_type not in ('VIDEO', 'AUDIO'): diff --git a/youtube_dl/extractor/francetv.py b/youtube_dl/extractor/francetv.py index 2d12e6dfb..95ef0bf6c 100644 --- a/youtube_dl/extractor/francetv.py +++ b/youtube_dl/extractor/francetv.py @@ -206,10 +206,6 @@ class FranceTVIE(InfoExtractor): info['title'] += ' - %s' % info['subtitle'] 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 { 'id': video_id, 'title': self._live_title(info['title']) if is_live else info['title'], diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index ecf744041..ef0afd686 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1830,7 +1830,7 @@ def write_json_file(obj, fn): try: with tf: - json.dump(obj, tf, default=lambda _:'') + json.dump(obj) if sys.platform == 'win32': # Need to remove existing file on Windows, else os.rename raises # WindowsError or FileExistsError.