1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_urlparse
,
21 class LivestreamIE(InfoExtractor
):
22 IE_NAME
= 'livestream'
23 _VALID_URL
= r
'https?://new\.livestream\.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>[0-9]+)(?:/player)?)?/?(?:$|[?#])'
25 'url': 'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
26 'md5': '53274c76ba7754fb0e8d072716f2292b',
30 'title': 'Live from Webster Hall NYC',
31 'upload_date': '20121012',
34 'thumbnail': 're:^http://.*\.jpg$'
37 'url': 'http://new.livestream.com/tedx/cityenglish',
39 'title': 'TEDCity2.0 (English)',
41 'playlist_mincount': 4,
43 'url': 'https://new.livestream.com/accounts/362/events/3557232/videos/67864563/player?autoPlay=false&height=360&mute=false&width=640',
44 'only_matching': True,
47 def _parse_smil(self
, video_id
, smil_url
):
50 './/{http://www.w3.org/2001/SMIL20/Language}body/'
51 '{http://www.w3.org/2001/SMIL20/Language}switch')
52 smil_doc
= self
._download
_xml
(
54 note
='Downloading SMIL information',
55 errnote
='Unable to download SMIL information',
57 if smil_doc
is False: # Download failed
59 title_node
= find_xpath_attr(
60 smil_doc
, './/{http://www.w3.org/2001/SMIL20/Language}meta',
62 if title_node
is None:
63 self
.report_warning('Cannot find SMIL id')
64 switch_node
= smil_doc
.find(_SWITCH_XPATH
)
66 title_id
= title_node
.attrib
['content']
67 switch_node
= find_xpath_attr(
68 smil_doc
, _SWITCH_XPATH
, 'id', title_id
)
69 if switch_node
is None:
70 raise ExtractorError('Cannot find switch node')
71 video_nodes
= switch_node
.findall(
72 '{http://www.w3.org/2001/SMIL20/Language}video')
74 for vn
in video_nodes
:
75 tbr
= int_or_none(vn
.attrib
.get('system-bitrate'))
77 'http://livestream-f.akamaihd.net/%s?v=3.0.3&fp=WIN%%2014,0,0,145' %
79 if 'clipBegin' in vn
.attrib
:
80 furl
+= '&ssek=' + vn
.attrib
['clipBegin']
83 'format_id': 'smil_%d' % tbr
,
90 def _extract_video_info(self
, video_data
):
91 video_id
= compat_str(video_data
['id'])
94 ('sd', 'progressive_url'),
95 ('hd', 'progressive_url_hd'),
98 'format_id': format_id
,
99 'url': video_data
[key
],
101 } for i
, (format_id
, key
) in enumerate(FORMAT_KEYS
)
102 if video_data
.get(key
)]
104 smil_url
= video_data
.get('smil_url')
106 formats
.extend(self
._parse
_smil
(video_id
, smil_url
))
107 self
._sort
_formats
(formats
)
112 'title': video_data
['caption'],
113 'thumbnail': video_data
.get('thumbnail_url'),
114 'upload_date': video_data
['updated_at'].replace('-', '')[:8],
115 'like_count': video_data
.get('likes', {}).get('total'),
116 'view_count': video_data
.get('views'),
119 def _real_extract(self
, url
):
120 mobj
= re
.match(self
._VALID
_URL
, url
)
121 video_id
= mobj
.group('id')
122 event_name
= mobj
.group('event_name')
123 webpage
= self
._download
_webpage
(url
, video_id
or event_name
)
125 og_video
= self
._og
_search
_video
_url
(
126 webpage
, 'player url', fatal
=False, default
=None)
127 if og_video
is not None:
128 query_str
= compat_urllib_parse_urlparse(og_video
).query
129 query
= compat_urlparse
.parse_qs(query_str
)
130 if 'play_url' in query
:
131 api_url
= query
['play_url'][0].replace('.smil', '')
132 info
= json
.loads(self
._download
_webpage
(
133 api_url
, video_id
, 'Downloading video info'))
134 return self
._extract
_video
_info
(info
)
136 config_json
= self
._search
_regex
(
137 r
'window.config = ({.*?});', webpage
, 'window config')
138 info
= json
.loads(config_json
)['event']
140 def is_relevant(vdata
, vid
):
141 result
= vdata
['type'] == 'video'
142 if video_id
is not None:
143 result
= result
and compat_str(vdata
['data']['id']) == vid
146 videos
= [self
._extract
_video
_info
(video_data
['data'])
147 for video_data
in info
['feed']['data']
148 if is_relevant(video_data
, video_id
)]
150 # This is an event page:
151 return self
.playlist_result(videos
, info
['id'], info
['full_name'])
154 raise ExtractorError('Cannot find video %s' % video_id
)
158 # The original version of Livestream uses a different system
159 class LivestreamOriginalIE(InfoExtractor
):
160 IE_NAME
= 'livestream:original'
161 _VALID_URL
= r
'''(?x)https?://www\.livestream\.com/
162 (?P<user>[^/]+)/(?P<type>video|folder)
163 (?:\?.*?Id=|/)(?P<id>.*?)(&|$)
166 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
168 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
170 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
174 'skip_download': True,
177 'url': 'https://www.livestream.com/newplay/folder?dirId=a07bf706-d0e4-4e75-a747-b021d84f2fd3',
179 'id': 'a07bf706-d0e4-4e75-a747-b021d84f2fd3',
181 'playlist_mincount': 4,
184 def _extract_video(self
, user
, video_id
):
185 api_url
= 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user
, video_id
)
187 info
= self
._download
_xml
(api_url
, video_id
)
188 item
= info
.find('channel').find('item')
189 ns
= {'media': 'http://search.yahoo.com/mrss'}
190 thumbnail_url
= item
.find(xpath_with_ns('media:thumbnail', ns
)).attrib
['url']
191 # Remove the extension and number from the path (like 1.jpg)
192 path
= self
._search
_regex
(r
'(user-files/.+)_.*?\.jpg$', thumbnail_url
, 'path')
196 'title': item
.find('title').text
,
197 'url': 'rtmp://extondemand.livestream.com/ondemand',
198 'play_path': 'trans/dv15/mogulus-{0}'.format(path
),
199 'player_url': 'http://static.livestream.com/chromelessPlayer/v21/playerapi.swf?hash=5uetk&v=0803&classid=D27CDB6E-AE6D-11cf-96B8-444553540000&jsEnabled=false&wmode=opaque',
201 'thumbnail': thumbnail_url
,
204 def _extract_folder(self
, url
, folder_id
):
205 webpage
= self
._download
_webpage
(url
, folder_id
)
206 paths
= orderedSet(re
.findall(
208 <li\s+class="folder">\s*<a\s+href="|
209 <a\s+href="(?=https?://livestre\.am/)
210 )([^"]+)"''', webpage
))
217 'url': compat_urlparse
.urljoin(url
, p
),
221 def _real_extract(self
, url
):
222 mobj
= re
.match(self
._VALID
_URL
, url
)
223 id = mobj
.group('id')
224 user
= mobj
.group('user')
225 url_type
= mobj
.group('type')
226 if url_type
== 'folder':
227 return self
._extract
_folder
(url
, id)
229 return self
._extract
_video
(user
, id)
232 # The server doesn't support HEAD request, the generic extractor can't detect
234 class LivestreamShortenerIE(InfoExtractor
):
235 IE_NAME
= 'livestream:shortener'
236 IE_DESC
= False # Do not list
237 _VALID_URL
= r
'https?://livestre\.am/(?P<id>.+)'
239 def _real_extract(self
, url
):
240 mobj
= re
.match(self
._VALID
_URL
, url
)
241 id = mobj
.group('id')
242 webpage
= self
._download
_webpage
(url
, id)
246 'url': self
._og
_search
_url
(webpage
),