Merge pull request #8718 from remitamine/m3u8-fixup
authorremitamine <remitamine@gmail.com>
Sat, 5 Mar 2016 17:37:28 +0000 (18:37 +0100)
committerremitamine <remitamine@gmail.com>
Sat, 5 Mar 2016 17:37:28 +0000 (18:37 +0100)
Add fixup for media files produced by HlsNative downloader(fixes #4776)

1  2 
youtube_dl/YoutubeDL.py

diff --combined youtube_dl/YoutubeDL.py
index f91851df91ee2a7bf49910ac2d8ec12f2bf94469,97cf31eb2cfc4c5f59bb16a0a7b90ec04f0806a8..94e4ea43200efe8fefae1e4db1c5149902f0d007
@@@ -24,6 -24,9 +24,6 @@@ import tim
  import tokenize
  import traceback
  
 -if os.name == 'nt':
 -    import ctypes
 -
  from .compat import (
      compat_basestring,
      compat_cookiejar,
@@@ -31,7 -34,6 +31,7 @@@
      compat_get_terminal_size,
      compat_http_client,
      compat_kwargs,
 +    compat_os_name,
      compat_str,
      compat_tokenize_tokenize,
      compat_urllib_error,
@@@ -85,6 -87,7 +85,7 @@@ from .extractor import get_info_extract
  from .downloader import get_suitable_downloader
  from .downloader.rtmp import rtmpdump_version
  from .postprocessor import (
+     FFmpegFixupM3u8PP,
      FFmpegFixupM4aPP,
      FFmpegFixupStretchedPP,
      FFmpegMergerPP,
@@@ -93,9 -96,6 +94,9 @@@
  )
  from .version import __version__
  
 +if compat_os_name == 'nt':
 +    import ctypes
 +
  
  class YoutubeDL(object):
      """YoutubeDL class.
      def to_console_title(self, message):
          if not self.params.get('consoletitle', False):
              return
 -        if os.name == 'nt' and ctypes.windll.kernel32.GetConsoleWindow():
 +        if compat_os_name == 'nt' and ctypes.windll.kernel32.GetConsoleWindow():
              # c_wchar_p() might not be necessary if `message` is
              # already of type unicode()
              ctypes.windll.kernel32.SetConsoleTitleW(ctypes.c_wchar_p(message))
          else:
              if self.params.get('no_warnings'):
                  return
 -            if not self.params.get('no_color') and self._err_file.isatty() and os.name != 'nt':
 +            if not self.params.get('no_color') and self._err_file.isatty() and compat_os_name != 'nt':
                  _msg_header = '\033[0;33mWARNING:\033[0m'
              else:
                  _msg_header = 'WARNING:'
          Do the same as trouble, but prefixes the message with 'ERROR:', colored
          in red if stderr is a tty file.
          '''
 -        if not self.params.get('no_color') and self._err_file.isatty() and os.name != 'nt':
 +        if not self.params.get('no_color') and self._err_file.isatty() and compat_os_name != 'nt':
              _msg_header = '\033[0;31mERROR:\033[0m'
          else:
              _msg_header = 'ERROR:'
                  elif template_dict.get('height'):
                      template_dict['resolution'] = '%sp' % template_dict['height']
                  elif template_dict.get('width'):
 -                    template_dict['resolution'] = '?x%d' % template_dict['width']
 +                    template_dict['resolution'] = '%dx?' % template_dict['width']
  
              sanitize = lambda k, v: sanitize_filename(
                  compat_str(v),
                  self.report_error('content too short (expected %s bytes and served %s)' % (err.expected, err.downloaded))
                  return
  
 -            if success:
 +            if success and filename != '-':
                  # Fixup content
                  fixup_policy = self.params.get('fixup')
                  if fixup_policy is None:
                      else:
                          assert fixup_policy in ('ignore', 'never')
  
+                 if info_dict.get('protocol') == 'm3u8_native' or info_dict.get('protocol') == 'm3u8' and self._downloader.params.get('hls_prefer_native', False):
+                     if fixup_policy == 'warn':
+                         self.report_warning('%s: malformated aac bitstream.' % (
+                             info_dict['id']))
+                     elif fixup_policy == 'detect_or_warn':
+                         fixup_pp = FFmpegFixupM3u8PP(self)
+                         if fixup_pp.available:
+                             info_dict.setdefault('__postprocessors', [])
+                             info_dict['__postprocessors'].append(fixup_pp)
+                         else:
+                             self.report_warning(
+                                 '%s: malformated aac bitstream. Install ffmpeg or avconv to fix this automatically.' % (
+                                     info_dict['id']))
+                     else:
+                         assert fixup_policy in ('ignore', 'never')
                  try:
                      self.post_process(filename, info_dict)
                  except (PostProcessingError) as err: