+ def blip(s):
+ return '{http://blip.tv/dtd/blip/1.0}%s' % s
+
+ def media(s):
+ return '{http://search.yahoo.com/mrss/}%s' % s
+
+ def itunes(s):
+ return '{http://www.itunes.com/dtds/podcast-1.0.dtd}%s' % s
+
+ item = rss.find('channel/item')
+
+ video_id = item.find(blip('item_id')).text
+ title = item.find('./title').text
+ description = clean_html(compat_str(item.find(blip('puredescription')).text))
+ timestamp = parse_iso8601(item.find(blip('datestamp')).text)
+ uploader = item.find(blip('user')).text
+ uploader_id = item.find(blip('userid')).text
+ duration = int(item.find(blip('runtime')).text)
+ media_thumbnail = item.find(media('thumbnail'))
+ thumbnail = media_thumbnail.get('url') if media_thumbnail is not None else item.find(itunes('image')).text
+ categories = [category.text for category in item.findall('category')]
+
+ formats = []
+ subtitles_urls = {}
+
+ media_group = item.find(media('group'))
+ for media_content in media_group.findall(media('content')):
+ url = media_content.get('url')
+ role = media_content.get(blip('role'))
+ msg = self._download_webpage(
+ url + '?showplayer=20140425131715&referrer=http://blip.tv&mask=7&skin=flashvars&view=url',
+ video_id, 'Resolving URL for %s' % role)
+ real_url = compat_urlparse.parse_qs(msg.strip())['message'][0]
+
+ media_type = media_content.get('type')
+ if media_type == 'text/srt' or url.endswith('.srt'):
+ LANGS = {
+ 'english': 'en',
+ }
+ lang = role.rpartition('-')[-1].strip().lower()
+ langcode = LANGS.get(lang, lang)
+ subtitles_urls[langcode] = url
+ elif media_type.startswith('video/'):
+ formats.append({
+ 'url': real_url,
+ 'format_id': role,
+ 'format_note': media_type,
+ 'vcodec': media_content.get(blip('vcodec')) or 'none',
+ 'acodec': media_content.get(blip('acodec')),
+ 'filesize': media_content.get('filesize'),
+ 'width': int_or_none(media_content.get('width')),
+ 'height': int_or_none(media_content.get('height')),
+ })
+ self._sort_formats(formats)
+
+ subtitles = self.extract_subtitles(video_id, subtitles_urls)
+
+ return {
+ 'id': video_id,
+ 'title': title,
+ 'description': description,
+ 'timestamp': timestamp,
+ 'uploader': uploader,
+ 'uploader_id': uploader_id,
+ 'duration': duration,
+ 'thumbnail': thumbnail,
+ 'categories': categories,
+ 'formats': formats,
+ 'subtitles': subtitles,
+ }
+
+ def _get_subtitles(self, video_id, subtitles_urls):
+ subtitles = {}
+ for lang, url in subtitles_urls.items():
+ # For some weird reason, blip.tv serves a video instead of subtitles
+ # when we request with a common UA
+ req = compat_urllib_request.Request(url)
+ req.add_header('User-Agent', 'youtube-dl')
+ subtitles[lang] = [{
+ # The extension is 'srt' but it's actually an 'ass' file
+ 'ext': 'ass',
+ 'data': self._download_webpage(req, None, note=False),
+ }]
+ return subtitles
+
+
+class BlipTVUserIE(InfoExtractor):
+ _VALID_URL = r'(?:(?:https?://(?:\w+\.)?blip\.tv/)|bliptvuser:)(?!api\.swf)([^/]+)/*$'