[BlipTVIE] Fix and simplify extraction of embedded videos
[youtube-dl] / youtube_dl / extractor / bliptv.py
index 0e63208dfbe5a68b758a683a77bf0e09911ba282..8a8c2e7a88583ec49bc87000712aa3cd8d5fed1a 100644 (file)
@@ -1,6 +1,5 @@
 import datetime
 import json
-import os
 import re
 import socket
 
@@ -46,18 +45,12 @@ class BlipTVIE(InfoExtractor):
             raise ExtractorError(u'Invalid URL: %s' % url)
 
         # See https://github.com/rg3/youtube-dl/issues/857
-        api_mobj = re.match(r'http://a\.blip\.tv/api\.swf#(?P<video_id>[\d\w]+)', url)
-        if api_mobj is not None:
-            url = 'http://blip.tv/play/g_%s' % api_mobj.group('video_id')
-        urlp = compat_urllib_parse_urlparse(url)
-        if urlp.path.startswith('/play/'):
-            response = self._request_webpage(url, None, False)
-            redirecturl = response.geturl()
-            rurlp = compat_urllib_parse_urlparse(redirecturl)
-            file_id = compat_parse_qs(rurlp.fragment)['file'][0].rpartition('/')[2]
-            url = 'http://blip.tv/a/a-' + file_id
-            return self._real_extract(url)
-
+        embed_mobj = re.search(r'^(?:https?://)?(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)([a-zA-Z0-9]+)', url)
+        if embed_mobj:
+            info_url = 'http://blip.tv/play/%s.x?p=1' % embed_mobj.group(1)
+            info_page = self._download_webpage(info_url, embed_mobj.group(1))
+            video_id = self._search_regex(r'data-episode-id="(\d+)', info_page, u'video_id')
+            return self.url_result('http://blip.tv/a/a-'+video_id, 'BlipTV')
 
         if '?' in url:
             cchar = '&'
@@ -67,26 +60,9 @@ class BlipTVIE(InfoExtractor):
         request = compat_urllib_request.Request(json_url)
         request.add_header('User-Agent', 'iTunes/10.6.1')
         self.report_extraction(mobj.group(1))
-        info = None
         urlh = self._request_webpage(request, None, False,
             u'unable to download video info webpage')
 
-        if urlh.headers.get('Content-Type', '').startswith('video/'): # Direct download
-            basename = url.split('/')[-1]
-            title,ext = os.path.splitext(basename)
-            title = title.decode('UTF-8')
-            ext = ext.replace('.', '')
-            self.report_direct_download(title)
-            return {
-                'id': title,
-                'url': url,
-                'uploader': None,
-                'upload_date': None,
-                'title': title,
-                'ext': ext,
-                'urlhandle': urlh
-            }
-
         try:
             json_code_bytes = urlh.read()
             json_code = json_code_bytes.decode('utf-8')