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' %
78 if 'clipBegin' in vn.attrib:
79 furl += '&ssek=' + vn.attrib['clipBegin']
82 'format_id': 'smil_%d' % tbr,
87 self._sort_formats(formats)
92 'title': video_data['caption'],
93 'thumbnail': video_data.get('thumbnail_url'),
94 'upload_date': video_data['updated_at'].replace('-', '')[:8],
95 'like_count': video_data.get('likes', {}).get('total'),
96 'view_count': video_data.get('views'),
99 def _real_extract(self, url):
100 mobj = re.match(self._VALID_URL, url)
101 video_id = mobj.group('id')
102 event_name = mobj.group('event_name')
103 webpage = self._download_webpage(url, video_id or event_name)
106 # This is an event page:
107 config_json = self._search_regex(
108 r'window.config = ({.*?});', webpage, 'window config')
109 info = json.loads(config_json)['event']
110 videos = [self._extract_video_info(video_data['data'])
111 for video_data in info['feed']['data']
112 if video_data['type'] == 'video']
113 return self.playlist_result(videos, info['id'], info['full_name'])
115 og_video = self._og_search_video_url(webpage, 'player url')
116 query_str = compat_urllib_parse_urlparse(og_video).query
117 query = compat_urlparse.parse_qs(query_str)
118 api_url = query['play_url'][0].replace('.smil', '')
119 info = json.loads(self._download_webpage(
120 api_url, video_id, 'Downloading video info'))
121 return self._extract_video_info(info)
124 # The original version of Livestream uses a different system
125 class LivestreamOriginalIE(InfoExtractor):
126 IE_NAME = 'livestream:original'
127 _VALID_URL = r'''(?x)https?://www\.livestream\.com/
128 (?P<user>[^/]+)/(?P<type>video|folder)
129 (?:\?.*?Id=|/)(?P<id>.*?)(&|$)
132 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
134 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
136 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
140 'skip_download': True,
144 def _extract_video(self, user, video_id):
145 api_url = 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user, video_id)
147 info = self._download_xml(api_url, video_id)
148 item = info.find('channel').find('item')
149 ns = {'media': 'http://search.yahoo.com/mrss'}
150 thumbnail_url = item.find(xpath_with_ns('media:thumbnail', ns)).attrib['url']
151 # Remove the extension and number from the path (like 1.jpg)
152 path = self._search_regex(r'(user-files/.+)_.*?\.jpg$', thumbnail_url, 'path')
156 'title': item.find('title').text,
157 'url': 'rtmp://extondemand.livestream.com/ondemand',
158 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path),
160 'thumbnail': thumbnail_url,
163 def _extract_folder(self, url, folder_id):
164 webpage = self._download_webpage(url, folder_id)
165 urls = orderedSet(re.findall(r'<a href="(https?://livestre\.am/.*?)"', webpage))
173 } for video_url in urls],
176 def _real_extract(self, url):
177 mobj = re.match(self._VALID_URL, url)
178 id = mobj.group('id')
179 user = mobj.group('user')
180 url_type = mobj.group('type')
181 if url_type == 'folder':
182 return self._extract_folder(url, id)
184 return self._extract_video(user, id)
187 # The server doesn't support HEAD request, the generic extractor can't detect
189 class LivestreamShortenerIE(InfoExtractor):
190 IE_NAME = 'livestream:shortener'
191 IE_DESC = False # Do not list
192 _VALID_URL = r'https?://livestre\.am/(?P<id>.+)'
194 def _real_extract(self, url):
195 mobj = re.match(self._VALID_URL, url)
196 id = mobj.group('id')
197 webpage = self._download_webpage(url, id)
201 'url': self._og_search_url(webpage),