Merge remote-tracking branch 'upstream/master'
authorAllan Zhou <allanzp@gmail.com>
Sat, 31 Aug 2013 00:51:59 +0000 (17:51 -0700)
committerAllan Zhou <allanzp@gmail.com>
Sat, 31 Aug 2013 00:51:59 +0000 (17:51 -0700)
1  2 
youtube_dl/extractor/youtube.py

index bd2b986ce1adec9eec6c1776485256720f08ac75,810ce6f5d7cfeac181cb8554ba17b53977b4732d..d331aa01b09e9a08cb01126b0fceda59d35a02a3
@@@ -153,9 -153,8 +153,9 @@@ class YoutubeIE(YoutubeBaseInfoExtracto
                       $"""
      _NEXT_URL_RE = r'[\?&]next_url=([^&]+)'
      # Listed in order of quality
 -    _available_formats = ['38', '37', '46', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13',
 -                          '95', '94', '93', '92', '132', '151',
 +    _available_formats = ['38', '37', '46', '22', '45', '35', '44', '34', '18', '43', '6', '5', '36', '17', '13',
 +                          # AHLS
 +                          '96', '95', '94', '93', '92', '132', '151',
                            # 3D
                            '85', '84', '102', '83', '101', '82', '100',
                            # Dash video
                            # Dash audio
                            '141', '172', '140', '171', '139',
                            ]
 -    _available_formats_prefer_free = ['38', '46', '37', '45', '22', '44', '35', '43', '34', '18', '6', '5', '17', '13',
 -                                      '95', '94', '93', '92', '132', '151',
 +    _available_formats_prefer_free = ['38', '46', '37', '45', '22', '44', '35', '43', '34', '18', '6', '5', '36', '17', '13',
 +                                      # AHLS
 +                                      '96', '95', '94', '93', '92', '132', '151',
 +                                      # 3D
                                        '85', '102', '84', '101', '83', '100', '82',
                                        # Dash video
                                        '138', '248', '137', '247', '136', '246', '245',
                                        # Dash audio
                                        '172', '141', '171', '140', '139',
                                        ]
 +    _video_formats_map = {
 +        'flv': ['35', '34', '6', '5'],
 +        '3gp': ['36', '17', '13'],
 +        'mp4': ['38', '37', '22', '18'],
 +        'webm': ['46', '45', '44', '43'],
 +    }
      _video_extensions = {
          '13': '3gp',
 -        '17': 'mp4',
 +        '17': '3gp',
          '18': 'mp4',
          '22': 'mp4',
 +        '36': '3gp',
          '37': 'mp4',
          '38': 'mp4',
          '43': 'webm',
          '101': 'webm',
          '102': 'webm',
  
 -        # videos that use m3u8
 +        # AHLS
          '92': 'mp4',
          '93': 'mp4',
          '94': 'mp4',
          '22': '720x1280',
          '34': '360x640',
          '35': '480x854',
 +        '36': '240x320',
          '37': '1080x1920',
          '38': '3072x4096',
          '43': '360x640',
              u"info_dict": {
                  u"upload_date": u"20120506",
                  u"title": u"Icona Pop - I Love It (feat. Charli XCX) [OFFICIAL VIDEO]",
-                 u"description": u"md5:b085c9804f5ab69f4adea963a2dceb3c",
+                 u"description": u"md5:3e2666e0a55044490499ea45fe9037b7",
                  u"uploader": u"Icona Pop",
                  u"uploader_id": u"IconaPop"
              }
          elif len(s) == 87:
              return s[6:27] + s[4] + s[28:39] + s[27] + s[40:59] + s[2] + s[60:]
          elif len(s) == 86:
-             return s[5:40] + s[3] + s[41:48] + s[0] + s[49:86]
+             return s[81:73:-1] + s[84] + s[72:58:-1] + s[0] + s[57:35:-1] + s[85] + s[34:0:-1]
          elif len(s) == 85:
              return s[83:34:-1] + s[0] + s[33:27:-1] + s[3] + s[26:19:-1] + s[34] + s[18:3:-1] + s[27]
          elif len(s) == 84:
-             return s[5:40] + s[3] + s[41:48] + s[0] + s[49:84]
+             return s[81:36:-1] + s[0] + s[35:2:-1]
          elif len(s) == 83:
              return s[81:64:-1] + s[82] + s[63:52:-1] + s[45] + s[51:45:-1] + s[1] + s[44:1:-1] + s[0]
          elif len(s) == 82:
              video_url_list = [(f, url_map[f]) for f in existing_formats] # All formats
          else:
              # Specific formats. We pick the first in a slash-delimeted sequence.
 -            # For example, if '1/2/3/4' is requested and '2' and '4' are available, we pick '2'.
 +            # Format can be specified as itag or 'mp4' or 'flv' etc. We pick the highest quality
 +            # available in the specified format. For example,
 +            # if '1/2/3/4' is requested and '2' and '4' are available, we pick '2'.
 +            # if '1/mp4/3/4' is requested and '1' and '5' (is a mp4) are available, we pick '1'.
 +            # if '1/mp4/3/4' is requested and '4' and '5' (is a mp4) are available, we pick '5'.
              req_formats = req_format.split('/')
              video_url_list = None
              for rf in req_formats:
                  if rf in url_map:
                      video_url_list = [(rf, url_map[rf])]
                      break
 +                if rf in self._video_formats_map:
 +                    for srf in self._video_formats_map[rf]:
 +                        if srf in url_map:
 +                            video_url_list = [(srf, url_map[srf])]
 +                            break
 +                    else:
 +                        continue
 +                    break
              if video_url_list is None:
                  raise ExtractorError(u'requested format not available')
          return video_url_list
@@@ -1184,7 -1161,7 +1184,7 @@@ class YoutubeWatchLaterIE(YoutubeFeedsI
  class YoutubeFavouritesIE(YoutubeBaseInfoExtractor):
      IE_NAME = u'youtube:favorites'
      IE_DESC = u'YouTube.com favourite videos, "ytfav" keyword (requires authentication)'
-     _VALID_URL = r'https?://www\.youtube\.com/my_favorites|:ytfav(?:o?rites)?'
+     _VALID_URL = r'https?://www\.youtube\.com/my_favorites|:ytfav(?:ou?rites)?'
      _LOGIN_REQUIRED = True
  
      def _real_extract(self, url):