]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/livestream.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
25 class LivestreamIE(InfoExtractor
):
26 IE_NAME
= 'livestream'
27 _VALID_URL
= r
'https?://(?:new\.)?livestream\.com/(?:accounts/(?P<account_id>\d+)|(?P<account_name>[^/]+))/(?:events/(?P<event_id>\d+)|(?P<event_name>[^/]+))(?:/videos/(?P<id>\d+))?'
29 'url': 'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
30 'md5': '53274c76ba7754fb0e8d072716f2292b',
34 'title': 'Live from Webster Hall NYC',
35 'timestamp': 1350008072,
36 'upload_date': '20121012',
40 'thumbnail': r
're:^http://.*\.jpg$'
43 'url': 'http://new.livestream.com/tedx/cityenglish',
45 'title': 'TEDCity2.0 (English)',
48 'playlist_mincount': 4,
50 'url': 'http://new.livestream.com/chess24/tatasteelchess',
52 'title': 'Tata Steel Chess',
55 'playlist_mincount': 60,
57 'url': 'https://new.livestream.com/accounts/362/events/3557232/videos/67864563/player?autoPlay=false&height=360&mute=false&width=640',
58 'only_matching': True,
60 'url': 'http://livestream.com/bsww/concacafbeachsoccercampeonato2015',
61 'only_matching': True,
63 _API_URL_TEMPLATE
= 'http://livestream.com/api/accounts/%s/events/%s'
65 def _parse_smil_formats(self
, smil
, smil_url
, video_id
, namespace
=None, f4m_params
=None, transform_rtmp_url
=None):
66 base_ele
= find_xpath_attr(
67 smil
, self
._xpath
_ns
('.//meta', namespace
), 'name', 'httpBase')
68 base
= base_ele
.get('content') if base_ele
is not None else 'http://livestreamvod-f.akamaihd.net/'
71 video_nodes
= smil
.findall(self
._xpath
_ns
('.//video', namespace
))
73 for vn
in video_nodes
:
74 tbr
= int_or_none(vn
.attrib
.get('system-bitrate'), 1000)
76 update_url_query(compat_urlparse
.urljoin(base
, vn
.attrib
['src']), {
78 'fp': 'WIN% 14,0,0,145',
80 if 'clipBegin' in vn
.attrib
:
81 furl
+= '&ssek=' + vn
.attrib
['clipBegin']
84 'format_id': 'smil_%d' % tbr
,
91 def _extract_video_info(self
, video_data
):
92 video_id
= compat_str(video_data
['id'])
95 ('sd', 'progressive_url'),
96 ('hd', 'progressive_url_hd'),
100 for format_id
, key
in FORMAT_KEYS
:
101 video_url
= video_data
.get(key
)
103 ext
= determine_ext(video_url
)
106 bitrate
= int_or_none(self
._search
_regex
(
107 r
'(\d+)\.%s' % ext
, video_url
, 'bitrate', default
=None))
110 'format_id': format_id
,
115 smil_url
= video_data
.get('smil_url')
117 formats
.extend(self
._extract
_smil
_formats
(smil_url
, video_id
, fatal
=False))
119 m3u8_url
= video_data
.get('m3u8_url')
121 formats
.extend(self
._extract
_m
3u8_formats
(
122 m3u8_url
, video_id
, 'mp4', 'm3u8_native',
123 m3u8_id
='hls', fatal
=False))
125 f4m_url
= video_data
.get('f4m_url')
127 formats
.extend(self
._extract
_f
4m
_formats
(
128 f4m_url
, video_id
, f4m_id
='hds', fatal
=False))
129 self
._sort
_formats
(formats
)
132 'author_id': comment
.get('author_id'),
133 'author': comment
.get('author', {}).get('full_name'),
134 'id': comment
.get('id'),
135 'text': comment
['text'],
136 'timestamp': parse_iso8601(comment
.get('created_at')),
137 } for comment
in video_data
.get('comments', {}).get('data', [])]
142 'title': video_data
['caption'],
143 'description': video_data
.get('description'),
144 'thumbnail': video_data
.get('thumbnail_url'),
145 'duration': float_or_none(video_data
.get('duration'), 1000),
146 'timestamp': parse_iso8601(video_data
.get('publish_at')),
147 'like_count': video_data
.get('likes', {}).get('total'),
148 'comment_count': video_data
.get('comments', {}).get('total'),
149 'view_count': video_data
.get('views'),
150 'comments': comments
,
153 def _extract_stream_info(self
, stream_info
):
154 broadcast_id
= compat_str(stream_info
['broadcast_id'])
155 is_live
= stream_info
.get('is_live')
158 smil_url
= stream_info
.get('play_url')
160 formats
.extend(self
._extract
_smil
_formats
(smil_url
, broadcast_id
))
162 m3u8_url
= stream_info
.get('m3u8_url')
164 formats
.extend(self
._extract
_m
3u8_formats
(
165 m3u8_url
, broadcast_id
, 'mp4', 'm3u8_native',
166 m3u8_id
='hls', fatal
=False))
168 rtsp_url
= stream_info
.get('rtsp_url')
174 self
._sort
_formats
(formats
)
179 'title': self
._live
_title
(stream_info
['stream_title']) if is_live
else stream_info
['stream_title'],
180 'thumbnail': stream_info
.get('thumbnail_url'),
184 def _extract_event(self
, event_data
):
185 event_id
= compat_str(event_data
['id'])
186 account_id
= compat_str(event_data
['owner_account_id'])
187 feed_root_url
= self
._API
_URL
_TEMPLATE
% (account_id
, event_id
) + '/feed.json'
189 stream_info
= event_data
.get('stream_info')
191 return self
._extract
_stream
_info
(stream_info
)
195 for i
in itertools
.count(1):
196 if last_video
is None:
197 info_url
= feed_root_url
199 info_url
= '{root}?&id={id}&newer=-1&type=video'.format(
200 root
=feed_root_url
, id=last_video
)
201 videos_info
= self
._download
_json
(
202 info_url
, event_id
, 'Downloading page {0}'.format(i
))['data']
203 videos_info
= [v
['data'] for v
in videos_info
if v
['type'] == 'video']
206 for v
in videos_info
:
207 v_id
= compat_str(v
['id'])
208 entries
.append(self
.url_result(
209 'http://livestream.com/accounts/%s/events/%s/videos/%s' % (account_id
, event_id
, v_id
),
210 'Livestream', v_id
, v
.get('caption')))
211 last_video
= videos_info
[-1]['id']
212 return self
.playlist_result(entries
, event_id
, event_data
['full_name'])
214 def _real_extract(self
, url
):
215 mobj
= re
.match(self
._VALID
_URL
, url
)
216 video_id
= mobj
.group('id')
217 event
= mobj
.group('event_id') or mobj
.group('event_name')
218 account
= mobj
.group('account_id') or mobj
.group('account_name')
219 api_url
= self
._API
_URL
_TEMPLATE
% (account
, event
)
221 video_data
= self
._download
_json
(
222 api_url
+ '/videos/%s' % video_id
, video_id
)
223 return self
._extract
_video
_info
(video_data
)
225 event_data
= self
._download
_json
(api_url
, video_id
)
226 return self
._extract
_event
(event_data
)
229 # The original version of Livestream uses a different system
230 class LivestreamOriginalIE(InfoExtractor
):
231 IE_NAME
= 'livestream:original'
232 _VALID_URL
= r
'''(?x)https?://original\.livestream\.com/
233 (?P<user>[^/\?#]+)(?:/(?P<type>video|folder)
234 (?:(?:\?.*?Id=|/)(?P<id>.*?)(&|$))?)?
237 'url': 'http://original.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
239 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
241 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
246 'url': 'https://original.livestream.com/newplay/folder?dirId=a07bf706-d0e4-4e75-a747-b021d84f2fd3',
248 'id': 'a07bf706-d0e4-4e75-a747-b021d84f2fd3',
250 'playlist_mincount': 4,
253 'url': 'http://original.livestream.com/znsbahamas',
254 'only_matching': True,
257 def _extract_video_info(self
, user
, video_id
):
258 api_url
= 'http://x%sx.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id=%s' % (user
, video_id
)
259 info
= self
._download
_xml
(api_url
, video_id
)
261 item
= info
.find('channel').find('item')
262 title
= xpath_text(item
, 'title')
263 media_ns
= {'media': 'http://search.yahoo.com/mrss'}
264 thumbnail_url
= xpath_attr(
265 item
, xpath_with_ns('media:thumbnail', media_ns
), 'url')
266 duration
= float_or_none(xpath_attr(
267 item
, xpath_with_ns('media:content', media_ns
), 'duration'))
268 ls_ns
= {'ls': 'http://api.channel.livestream.com/2.0'}
269 view_count
= int_or_none(xpath_text(
270 item
, xpath_with_ns('ls:viewsCount', ls_ns
)))
275 'thumbnail': thumbnail_url
,
276 'duration': duration
,
277 'view_count': view_count
,
280 def _extract_video_formats(self
, video_data
, video_id
):
283 progressive_url
= video_data
.get('progressiveUrl')
286 'url': progressive_url
,
290 m3u8_url
= video_data
.get('httpUrl')
292 formats
.extend(self
._extract
_m
3u8_formats
(
293 m3u8_url
, video_id
, 'mp4', 'm3u8_native',
294 m3u8_id
='hls', fatal
=False))
296 rtsp_url
= video_data
.get('rtspUrl')
303 self
._sort
_formats
(formats
)
306 def _extract_folder(self
, url
, folder_id
):
307 webpage
= self
._download
_webpage
(url
, folder_id
)
308 paths
= orderedSet(re
.findall(
310 <li\s+class="folder">\s*<a\s+href="|
311 <a\s+href="(?=https?://livestre\.am/)
312 )([^"]+)"''', webpage
))
316 'url': compat_urlparse
.urljoin(url
, p
),
319 return self
.playlist_result(entries
, folder_id
)
321 def _real_extract(self
, url
):
322 mobj
= re
.match(self
._VALID
_URL
, url
)
323 user
= mobj
.group('user')
324 url_type
= mobj
.group('type')
325 content_id
= mobj
.group('id')
326 if url_type
== 'folder':
327 return self
._extract
_folder
(url
, content_id
)
329 # this url is used on mobile devices
330 stream_url
= 'http://x%sx.api.channel.livestream.com/3.0/getstream.json' % user
333 stream_url
+= '?id=%s' % content_id
334 info
= self
._extract
_video
_info
(user
, content_id
)
337 webpage
= self
._download
_webpage
(url
, content_id
)
339 'title': self
._og
_search
_title
(webpage
),
340 'description': self
._og
_search
_description
(webpage
),
341 'thumbnail': self
._search
_regex
(r
'channelLogo\.src\s*=\s*"([^"]+)"', webpage
, 'thumbnail', None),
343 video_data
= self
._download
_json
(stream_url
, content_id
)
344 is_live
= video_data
.get('isLive')
347 'title': self
._live
_title
(info
['title']) if is_live
else info
['title'],
348 'formats': self
._extract
_video
_formats
(video_data
, content_id
),
354 # The server doesn't support HEAD request, the generic extractor can't detect
356 class LivestreamShortenerIE(InfoExtractor
):
357 IE_NAME
= 'livestream:shortener'
358 IE_DESC
= False # Do not list
359 _VALID_URL
= r
'https?://livestre\.am/(?P<id>.+)'
361 def _real_extract(self
, url
):
362 mobj
= re
.match(self
._VALID
_URL
, url
)
363 id = mobj
.group('id')
364 webpage
= self
._download
_webpage
(url
, id)
368 'url': self
._og
_search
_url
(webpage
),