From 1dcc4c0cad886457c0fa5f874c38f95f0510ea4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Fri, 22 Nov 2013 14:57:53 +0100 Subject: [PATCH 1/2] Add --load-info option (#972) It just calls the 'YoutubeDL.process_ie_result' with the dictionary from the json file --- youtube_dl/YoutubeDL.py | 6 ++++++ youtube_dl/__init__.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index b68b110a46..80c056dc82 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -812,6 +812,12 @@ class YoutubeDL(object): return self._download_retcode + def download_with_info_file(self, info_filename): + with open(info_filename, 'r') as f: + # TODO: Check for errors + info = json.load(f) + self.process_ie_result(info, download=True) + def post_process(self, filename, ie_info): """Run all the postprocessors on the given file.""" info = dict(ie_info) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index d2446b6706..b0d9a67630 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -360,6 +360,9 @@ def parseOpts(overrideArguments=None): help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames', default=False) filesystem.add_option('-a', '--batch-file', dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)') + filesystem.add_option('--load-info', + dest='load_info_filename', metavar='FILE', + help='json file containing the video information (created with the "--write-json" option') filesystem.add_option('-w', '--no-overwrites', action='store_true', dest='nooverwrites', help='do not overwrite files', default=False) filesystem.add_option('-c', '--continue', @@ -706,14 +709,17 @@ def _real_main(argv=None): update_self(ydl.to_screen, opts.verbose) # Maybe do nothing - if len(all_urls) < 1: + if (len(all_urls) < 1) and (opts.load_info_filename is None): if not opts.update_self: parser.error(u'you must provide at least one URL') else: sys.exit() try: - retcode = ydl.download(all_urls) + if opts.load_info_filename is not None: + retcode = ydl.download_with_info_file(opts.load_info_filename) + else: + retcode = ydl.download(all_urls) except MaxDownloadsReached: ydl.to_screen(u'--max-download limit reached, aborting.') retcode = 101 From d494389821de832874dc78abc2fe16365b5fe815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Tue, 3 Dec 2013 20:16:52 +0100 Subject: [PATCH 2/2] Option '--load-info': if the download fails, try extracting the info with the 'webpage_url' field of the info dict The video url may have expired. --- youtube_dl/YoutubeDL.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 80c056dc82..77339dddfd 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -816,7 +816,16 @@ class YoutubeDL(object): with open(info_filename, 'r') as f: # TODO: Check for errors info = json.load(f) - self.process_ie_result(info, download=True) + try: + self.process_ie_result(info, download=True) + except DownloadError: + webpage_url = info.get('webpage_url') + if webpage_url is not None: + self.report_warning(u'The info failed to download, trying with "%s"' % webpage_url) + return self.download([webpage_url]) + else: + raise + return self._download_retcode def post_process(self, filename, ie_info): """Run all the postprocessors on the given file."""