6 from .common import InfoExtractor
12 compat_urllib_parse_urlparse,
13 compat_urllib_request,
20 class BlipTVIE(InfoExtractor):
21 """Information extractor for blip.tv"""
23 _VALID_URL = r'^(?:https?://)?(?:\w+\.)?blip\.tv/((.+/)|(play/)|(api\.swf#))(.+)$'
24 _URL_EXT = r'^.*\.([a-z0-9]+)$'
27 u'url': u'http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352',
28 u'file': u'5779306.m4v',
29 u'md5': u'80baf1ec5c3d2019037c1c707d676b9f',
31 u"upload_date": u"20111205",
32 u"description": u"md5:9bc31f227219cde65e47eeec8d2dc596",
33 u"uploader": u"Comic Book Resources - CBR TV",
34 u"title": u"CBR EXCLUSIVE: \"Gotham City Imposters\" Bats VS Jokerz Short 3"
38 def report_direct_download(self, title):
39 """Report information extraction."""
40 self.to_screen(u'%s: Direct download detected' % title)
42 def _real_extract(self, url):
43 mobj = re.match(self._VALID_URL, url)
45 raise ExtractorError(u'Invalid URL: %s' % url)
47 # See https://github.com/rg3/youtube-dl/issues/857
48 embed_mobj = re.search(r'^(?:https?://)?(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)([a-zA-Z0-9]+)', url)
50 info_url = 'http://blip.tv/play/%s.x?p=1' % embed_mobj.group(1)
51 info_page = self._download_webpage(info_url, embed_mobj.group(1))
52 video_id = self._search_regex(r'data-episode-id="(\d+)', info_page, u'video_id')
53 return self.url_result('http://blip.tv/a/a-'+video_id, 'BlipTV')
59 json_url = url + cchar + 'skin=json&version=2&no_wrap=1'
60 request = compat_urllib_request.Request(json_url)
61 request.add_header('User-Agent', 'iTunes/10.6.1')
62 self.report_extraction(mobj.group(1))
63 urlh = self._request_webpage(request, None, False,
64 u'unable to download video info webpage')
67 json_code_bytes = urlh.read()
68 json_code = json_code_bytes.decode('utf-8')
69 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
70 raise ExtractorError(u'Unable to read video info webpage: %s' % compat_str(err))
73 json_data = json.loads(json_code)
74 if 'Post' in json_data:
75 data = json_data['Post']
79 upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d')
80 if 'additionalMedia' in data:
81 formats = sorted(data['additionalMedia'], key=lambda f: int(f['media_height']))
82 best_format = formats[-1]
83 video_url = best_format['url']
85 video_url = data['media']['url']
86 umobj = re.match(self._URL_EXT, video_url)
88 raise ValueError('Can not determine filename extension')
92 'id': compat_str(data['item_id']),
94 'uploader': data['display_name'],
95 'upload_date': upload_date,
96 'title': data['title'],
98 'format': data['media']['mimeType'],
99 'thumbnail': data['thumbnailUrl'],
100 'description': data['description'],
101 'player_url': data['embedUrl'],
102 'user_agent': 'iTunes/10.6.1',
104 except (ValueError, KeyError) as err:
105 raise ExtractorError(u'Unable to parse video information: %s' % repr(err))
108 class BlipTVUserIE(InfoExtractor):
109 """Information Extractor for blip.tv users."""
111 _VALID_URL = r'(?:(?:(?:https?://)?(?:\w+\.)?blip\.tv/)|bliptvuser:)([^/]+)/*$'
113 IE_NAME = u'blip.tv:user'
115 def _real_extract(self, url):
117 mobj = re.match(self._VALID_URL, url)
119 raise ExtractorError(u'Invalid URL: %s' % url)
121 username = mobj.group(1)
123 page_base = 'http://m.blip.tv/pr/show_get_full_episode_list?users_id=%s&lite=0&esi=1'
125 page = self._download_webpage(url, username, u'Downloading user page')
126 mobj = re.search(r'data-users-id="([^"]+)"', page)
127 page_base = page_base % mobj.group(1)
130 # Download video ids using BlipTV Ajax calls. Result size per
131 # query is limited (currently to 12 videos) so we need to query
132 # page by page until there are no video ids - it means we got
139 url = page_base + "&page=" + str(pagenum)
140 page = self._download_webpage(url, username,
141 u'Downloading video ids from page %d' % pagenum)
143 # Extract video identifiers
146 for mobj in re.finditer(r'href="/([^"]+)"', page):
147 if mobj.group(1) not in ids_in_page:
148 ids_in_page.append(unescapeHTML(mobj.group(1)))
150 video_ids.extend(ids_in_page)
152 # A little optimization - if current page is not
153 # "full", ie. does not contain PAGE_SIZE video ids then
154 # we can assume that this page is the last one - there
155 # are no more ids on further pages - no need to query
158 if len(ids_in_page) < self._PAGE_SIZE:
163 urls = [u'http://blip.tv/%s' % video_id for video_id in video_ids]
164 url_entries = [self.url_result(vurl, 'BlipTV') for vurl in urls]
165 return [self.playlist_result(url_entries, playlist_title = username)]