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 _parse_smil(self, video_id, smil_url):
39 './/{http://www.w3.org/2001/SMIL20/Language}body/'
40 '{http://www.w3.org/2001/SMIL20/Language}switch')
41 smil_doc = self._download_xml(
43 note='Downloading SMIL information',
44 errnote='Unable to download SMIL information',
46 if smil_doc is False: # Download failed
48 title_node = find_xpath_attr(
49 smil_doc, './/{http://www.w3.org/2001/SMIL20/Language}meta',
51 if title_node is None:
52 self.report_warning('Cannot find SMIL id')
53 switch_node = smil_doc.find(_SWITCH_XPATH)
55 title_id = title_node.attrib['content']
56 switch_node = find_xpath_attr(
57 smil_doc, _SWITCH_XPATH, 'id', title_id)
58 if switch_node is None:
59 raise ExtractorError('Cannot find switch node')
60 video_nodes = switch_node.findall(
61 '{http://www.w3.org/2001/SMIL20/Language}video')
63 for vn in video_nodes:
64 tbr = int_or_none(vn.attrib.get('system-bitrate'))
66 'http://livestream-f.akamaihd.net/%s?v=3.0.3&fp=WIN%%2014,0,0,145' %
68 if 'clipBegin' in vn.attrib:
69 furl += '&ssek=' + vn.attrib['clipBegin']
72 'format_id': 'smil_%d' % tbr,
79 def _extract_video_info(self, video_data):
80 video_id = compat_str(video_data['id'])
83 ('sd', 'progressive_url'),
84 ('hd', 'progressive_url_hd'),
87 'format_id': format_id,
88 'url': video_data[key],
90 } for i, (format_id, key) in enumerate(FORMAT_KEYS)
91 if video_data.get(key)]
93 smil_url = video_data.get('smil_url')
95 formats.extend(self._parse_smil(video_id, smil_url))
96 self._sort_formats(formats)
101 'title': video_data['caption'],
102 'thumbnail': video_data.get('thumbnail_url'),
103 'upload_date': video_data['updated_at'].replace('-', '')[:8],
104 'like_count': video_data.get('likes', {}).get('total'),
105 'view_count': video_data.get('views'),
108 def _real_extract(self, url):
109 mobj = re.match(self._VALID_URL, url)
110 video_id = mobj.group('id')
111 event_name = mobj.group('event_name')
112 webpage = self._download_webpage(url, video_id or event_name)
114 og_video = self._og_search_video_url(webpage, 'player url', fatal=False, default=None)
116 config_json = self._search_regex(
117 r'window.config = ({.*?});', webpage, 'window config')
118 info = json.loads(config_json)['event']
120 def is_relevant(vdata, vid):
121 result = vdata['type'] == 'video'
122 if video_id is not None:
123 result = result and compat_str(vdata['data']['id']) == vid
126 videos = [self._extract_video_info(video_data['data'])
127 for video_data in info['feed']['data']
128 if is_relevant(video_data, video_id)]
130 # This is an event page:
131 return self.playlist_result(videos, info['id'], info['full_name'])
136 query_str = compat_urllib_parse_urlparse(og_video).query
137 query = compat_urlparse.parse_qs(query_str)
138 api_url = query['play_url'][0].replace('.smil', '')
139 info = json.loads(self._download_webpage(
140 api_url, video_id, 'Downloading video info'))
141 return self._extract_video_info(info)
144 # The original version of Livestream uses a different system
145 class LivestreamOriginalIE(InfoExtractor):
146 IE_NAME = 'livestream:original'
147 _VALID_URL = r'''(?x)https?://www\.livestream\.com/
148 (?P<user>[^/]+)/(?P<type>video|folder)
149 (?:\?.*?Id=|/)(?P<id>.*?)(&|$)
152 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
154 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
156 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
160 'skip_download': True,
164 def _extract_video(self, user, video_id):
165 api_url = 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user, video_id)
167 info = self._download_xml(api_url, video_id)
168 item = info.find('channel').find('item')
169 ns = {'media': 'http://search.yahoo.com/mrss'}
170 thumbnail_url = item.find(xpath_with_ns('media:thumbnail', ns)).attrib['url']
171 # Remove the extension and number from the path (like 1.jpg)
172 path = self._search_regex(r'(user-files/.+)_.*?\.jpg$', thumbnail_url, 'path')
176 'title': item.find('title').text,
177 'url': 'rtmp://extondemand.livestream.com/ondemand',
178 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path),
180 'thumbnail': thumbnail_url,
183 def _extract_folder(self, url, folder_id):
184 webpage = self._download_webpage(url, folder_id)
185 urls = orderedSet(re.findall(r'<a href="(https?://livestre\.am/.*?)"', webpage))
193 } for video_url in urls],
196 def _real_extract(self, url):
197 mobj = re.match(self._VALID_URL, url)
198 id = mobj.group('id')
199 user = mobj.group('user')
200 url_type = mobj.group('type')
201 if url_type == 'folder':
202 return self._extract_folder(url, id)
204 return self._extract_video(user, id)
207 # The server doesn't support HEAD request, the generic extractor can't detect
209 class LivestreamShortenerIE(InfoExtractor):
210 IE_NAME = 'livestream:shortener'
211 IE_DESC = False # Do not list
212 _VALID_URL = r'https?://livestre\.am/(?P<id>.+)'
214 def _real_extract(self, url):
215 mobj = re.match(self._VALID_URL, url)
216 id = mobj.group('id')
217 webpage = self._download_webpage(url, id)
221 'url': self._og_search_url(webpage),