Merge remote-tracking branch 'jaimeMF/merge-formats'
authorPhilipp Hagemeister <phihag@phihag.de>
Sun, 5 Jan 2014 01:06:48 +0000 (02:06 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Sun, 5 Jan 2014 01:06:48 +0000 (02:06 +0100)
1  2 
youtube_dl/YoutubeDL.py

index f70c356c07bacea38de21956d4d4fac8c232af2c,8731279c114923a3ab91173ee2f75d0734a8244a..3786799da7967ca8522462758ee81318f1e06214
@@@ -880,12 -892,29 +892,29 @@@ class YoutubeDL(object)
                  success = True
              else:
                  try:
-                     fd = get_suitable_downloader(info_dict)(self, self.params)
-                     for ph in self._progress_hooks:
-                         fd.add_progress_hook(ph)
-                     success = fd.download(filename, info_dict)
+                     def dl(name, info):
+                         fd = get_suitable_downloader(info)(self, self.params)
+                         for ph in self._progress_hooks:
+                             fd.add_progress_hook(ph)
+                         return fd.download(name, info)
+                     if info_dict.get('requested_formats') is not None:
+                         downloaded = []
+                         success = True
+                         for f in info_dict['requested_formats']:
+                             new_info = dict(info_dict)
+                             new_info.update(f)
+                             fname = self.prepare_filename(new_info)
+                             fname = prepend_extension(fname, 'f%s' % f['format_id'])
+                             downloaded.append(fname)
+                             partial_success = dl(fname, new_info)
+                             success = success and partial_success
+                         info_dict['__postprocessors'] = [FFmpegMergerPP(self)]
+                         info_dict['__files_to_merge'] = downloaded
+                     else:
+                         # Just a single file
+                         success = dl(filename, info_dict)
                  except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
 -                    self.report_error(u'unable to download video data: %s' % str(err))
 +                    self.report_error('unable to download video data: %s' % str(err))
                      return
                  except (OSError, IOError) as err:
                      raise UnavailableVideoError(err)