1 from __future__ import unicode_literals
6 from .common import InfoExtractor
9 compat_urllib_parse_urlparse,
19 class LivestreamIE(InfoExtractor):
20 IE_NAME = 'livestream'
21 _VALID_URL = r'http://new\.livestream\.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>\d+))?/?$'
23 'url': 'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
24 'md5': '53274c76ba7754fb0e8d072716f2292b',
28 'title': 'Live from Webster Hall NYC',
29 'upload_date': '20121012',
32 'thumbnail': 're:^http://.*\.jpg$'
36 def _extract_video_info(self, video_data):
37 video_id = compat_str(video_data['id'])
40 ('sd', 'progressive_url'),
41 ('hd', 'progressive_url_hd'),
44 'format_id': format_id,
45 'url': video_data[key],
47 } for i, (format_id, key) in enumerate(FORMAT_KEYS)
48 if video_data.get(key)]
50 smil_url = video_data.get('smil_url')
53 './/{http://www.w3.org/2001/SMIL20/Language}body/'
54 '{http://www.w3.org/2001/SMIL20/Language}switch')
55 smil_doc = self._download_xml(
56 smil_url, video_id, note='Downloading SMIL information')
58 title_node = find_xpath_attr(
59 smil_doc, './/{http://www.w3.org/2001/SMIL20/Language}meta',
61 if title_node is None:
62 self.report_warning('Cannot find SMIL id')
63 switch_node = smil_doc.find(_SWITCH_XPATH)
65 title_id = title_node.attrib['content']
66 switch_node = find_xpath_attr(
67 smil_doc, _SWITCH_XPATH, 'id', title_id)
68 if switch_node is None:
69 raise ExtractorError('Cannot find switch node')
70 video_nodes = switch_node.findall(
71 '{http://www.w3.org/2001/SMIL20/Language}video')
73 for vn in video_nodes:
74 tbr = int_or_none(vn.attrib.get('system-bitrate'))
76 'http://livestream-f.akamaihd.net/%s?v=3.0.3&fp=WIN%%2014,0,0,145&seek=%s' %
77 (vn.attrib['src'], vn.attrib['clipBegin']))
80 'format_id': 'smil_%d' % tbr,
85 self._sort_formats(formats)
90 'title': video_data['caption'],
91 'thumbnail': video_data.get('thumbnail_url'),
92 'upload_date': video_data['updated_at'].replace('-', '')[:8],
93 'like_count': video_data.get('likes', {}).get('total'),
94 'view_count': video_data.get('views'),
97 def _real_extract(self, url):
98 mobj = re.match(self._VALID_URL, url)
99 video_id = mobj.group('id')
100 event_name = mobj.group('event_name')
101 webpage = self._download_webpage(url, video_id or event_name)
104 # This is an event page:
105 config_json = self._search_regex(
106 r'window.config = ({.*?});', webpage, 'window config')
107 info = json.loads(config_json)['event']
108 videos = [self._extract_video_info(video_data['data'])
109 for video_data in info['feed']['data']
110 if video_data['type'] == 'video']
111 return self.playlist_result(videos, info['id'], info['full_name'])
113 og_video = self._og_search_video_url(webpage, 'player url')
114 query_str = compat_urllib_parse_urlparse(og_video).query
115 query = compat_urlparse.parse_qs(query_str)
116 api_url = query['play_url'][0].replace('.smil', '')
117 info = json.loads(self._download_webpage(
118 api_url, video_id, 'Downloading video info'))
119 return self._extract_video_info(info)
122 # The original version of Livestream uses a different system
123 class LivestreamOriginalIE(InfoExtractor):
124 IE_NAME = 'livestream:original'
125 _VALID_URL = r'''(?x)https?://www\.livestream\.com/
126 (?P<user>[^/]+)/(?P<type>video|folder)
127 (?:\?.*?Id=|/)(?P<id>.*?)(&|$)
130 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
132 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
134 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
138 'skip_download': True,
142 def _extract_video(self, user, video_id):
143 api_url = 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user, video_id)
145 info = self._download_xml(api_url, video_id)
146 item = info.find('channel').find('item')
147 ns = {'media': 'http://search.yahoo.com/mrss'}
148 thumbnail_url = item.find(xpath_with_ns('media:thumbnail', ns)).attrib['url']
149 # Remove the extension and number from the path (like 1.jpg)
150 path = self._search_regex(r'(user-files/.+)_.*?\.jpg$', thumbnail_url, 'path')
154 'title': item.find('title').text,
155 'url': 'rtmp://extondemand.livestream.com/ondemand',
156 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path),
158 'thumbnail': thumbnail_url,
161 def _extract_folder(self, url, folder_id):
162 webpage = self._download_webpage(url, folder_id)
163 urls = orderedSet(re.findall(r'<a href="(https?://livestre\.am/.*?)"', webpage))
171 } for video_url in urls],
174 def _real_extract(self, url):
175 mobj = re.match(self._VALID_URL, url)
176 id = mobj.group('id')
177 user = mobj.group('user')
178 url_type = mobj.group('type')
179 if url_type == 'folder':
180 return self._extract_folder(url, id)
182 return self._extract_video(user, id)
185 # The server doesn't support HEAD request, the generic extractor can't detect
187 class LivestreamShortenerIE(InfoExtractor):
188 IE_NAME = 'livestream:shortener'
189 IE_DESC = False # Do not list
190 _VALID_URL = r'https?://livestre\.am/(?P<id>.+)'
192 def _real_extract(self, url):
193 mobj = re.match(self._VALID_URL, url)
194 id = mobj.group('id')
195 webpage = self._download_webpage(url, id)
199 'url': self._og_search_url(webpage),