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
)
115 # This is an event page:
116 config_json
= self
._search
_regex
(
117 r
'window.config = ({.*?});', webpage
, 'window config')
118 info
= json
.loads(config_json
)['event']
119 videos
= [self
._extract
_video
_info
(video_data
['data'])
120 for video_data
in info
['feed']['data']
121 if video_data
['type'] == 'video']
122 return self
.playlist_result(videos
, info
['id'], info
['full_name'])
124 og_video
= self
._og
_search
_video
_url
(webpage
, 'player url')
125 query_str
= compat_urllib_parse_urlparse(og_video
).query
126 query
= compat_urlparse
.parse_qs(query_str
)
127 api_url
= query
['play_url'][0].replace('.smil', '')
128 info
= json
.loads(self
._download
_webpage
(
129 api_url
, video_id
, 'Downloading video info'))
130 return self
._extract
_video
_info
(info
)
133 # The original version of Livestream uses a different system
134 class LivestreamOriginalIE(InfoExtractor
):
135 IE_NAME
= 'livestream:original'
136 _VALID_URL
= r
'''(?x)https?://www\.livestream\.com/
137 (?P<user>[^/]+)/(?P<type>video|folder)
138 (?:\?.*?Id=|/)(?P<id>.*?)(&|$)
141 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
143 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
145 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
149 'skip_download': True,
153 def _extract_video(self
, user
, video_id
):
154 api_url
= 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user
, video_id
)
156 info
= self
._download
_xml
(api_url
, video_id
)
157 item
= info
.find('channel').find('item')
158 ns
= {'media': 'http://search.yahoo.com/mrss'}
159 thumbnail_url
= item
.find(xpath_with_ns('media:thumbnail', ns
)).attrib
['url']
160 # Remove the extension and number from the path (like 1.jpg)
161 path
= self
._search
_regex
(r
'(user-files/.+)_.*?\.jpg$', thumbnail_url
, 'path')
165 'title': item
.find('title').text
,
166 'url': 'rtmp://extondemand.livestream.com/ondemand',
167 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path
),
169 'thumbnail': thumbnail_url
,
172 def _extract_folder(self
, url
, folder_id
):
173 webpage
= self
._download
_webpage
(url
, folder_id
)
174 urls
= orderedSet(re
.findall(r
'<a href="(https?://livestre\.am/.*?)"', webpage
))
182 } for video_url
in urls
],
185 def _real_extract(self
, url
):
186 mobj
= re
.match(self
._VALID
_URL
, url
)
187 id = mobj
.group('id')
188 user
= mobj
.group('user')
189 url_type
= mobj
.group('type')
190 if url_type
== 'folder':
191 return self
._extract
_folder
(url
, id)
193 return self
._extract
_video
(user
, id)
196 # The server doesn't support HEAD request, the generic extractor can't detect
198 class LivestreamShortenerIE(InfoExtractor
):
199 IE_NAME
= 'livestream:shortener'
200 IE_DESC
= False # Do not list
201 _VALID_URL
= r
'https?://livestre\.am/(?P<id>.+)'
203 def _real_extract(self
, url
):
204 mobj
= re
.match(self
._VALID
_URL
, url
)
205 id = mobj
.group('id')
206 webpage
= self
._download
_webpage
(url
, id)
210 'url': self
._og
_search
_url
(webpage
),