Merge remote-tracking branch 'dstftw/escape-non-ascii-in-urls'
[youtube-dl] / youtube_dl / extractor / adultswim.py
index ca1bfbdc2225b4d79aaac19eafaaa86808dd103e..b4b40f2d4f21432f6b12a883513ae00827af00e5 100644 (file)
@@ -57,8 +57,6 @@ class AdultSwimIE(InfoExtractor):
         ]
     }
 
-    _available_formats = ['150', '640', '3500']
-
     _video_extensions = {
         '3500': 'flv',
         '640': 'mp4',
@@ -77,8 +75,10 @@ class AdultSwimIE(InfoExtractor):
         video_path = mobj.group('path')
 
         webpage = self._download_webpage(url, video_path)
-        episode_id = self._html_search_regex(r'<link rel="video_src" href="http://i\.adultswim\.com/adultswim/adultswimtv/tools/swf/viralplayer.swf\?id=([0-9a-f]+?)"\s*/?\s*>', webpage, 'episode_id')
-        title = self._html_search_regex(r'<meta property="og:title" content="\s*(.*?)\s*"\s*/?\s*>', webpage, 'title')
+        episode_id = self._html_search_regex(
+            r'<link rel="video_src" href="http://i\.adultswim\.com/adultswim/adultswimtv/tools/swf/viralplayer.swf\?id=([0-9a-f]+?)"\s*/?\s*>',
+            webpage, 'episode_id')
+        title = self._og_search_title(webpage)
 
         index_url = 'http://asfix.adultswim.com/asfix-svc/episodeSearch/getEpisodesByIDs?networkName=AS&ids=%s' % episode_id
         idoc = self._download_xml(index_url, title, 'Downloading episode index', 'Unable to download episode index')
@@ -99,7 +99,9 @@ class AdultSwimIE(InfoExtractor):
             duration = segment_el.attrib.get('duration')
 
             segment_url = 'http://asfix.adultswim.com/asfix-svc/episodeservices/getCvpPlaylist?networkName=AS&id=%s' % segment_id
-            idoc = self._download_xml(segment_url, segment_title, 'Downloading segment information', 'Unable to download segment information')
+            idoc = self._download_xml(
+                segment_url, segment_title,
+                'Downloading segment information', 'Unable to download segment information')
 
             formats = []
             file_els = idoc.findall('.//files/file')
@@ -112,7 +114,8 @@ class AdultSwimIE(InfoExtractor):
                     'format_id': '%s-%s' % (bitrate, type),
                     'url': file_el.text,
                     'ext': self._video_extensions.get(bitrate, 'mp4'),
-                    'tbr': bitrate,
+                    # The bitrate may not be a number (for example: 'iphone')
+                    'tbr': int(bitrate) if bitrate.isdigit() else None,
                     'height': height,
                     'width': width
                 })