]>
Commit | Line | Data |
---|---|---|
ef5acfe3 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
3444844b | 7 | from ..compat import compat_HTTPError |
ef5acfe3 | 8 | from ..utils import ( |
ef5acfe3 | 9 | determine_ext, |
d7fc5631 S |
10 | float_or_none, |
11 | int_or_none, | |
e5d39886 | 12 | smuggle_url, |
2b4e1ace | 13 | try_get, |
454e5cdb | 14 | unsmuggle_url, |
3444844b | 15 | ExtractorError, |
ef5acfe3 | 16 | ) |
17 | ||
18 | ||
d7fc5631 S |
19 | class LimelightBaseIE(InfoExtractor): |
20 | _PLAYLIST_SERVICE_URL = 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s' | |
21 | _API_URL = 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json' | |
ef5acfe3 | 22 | |
e5d39886 S |
23 | @classmethod |
24 | def _extract_urls(cls, webpage, source_url): | |
25 | lm = { | |
26 | 'Media': 'media', | |
27 | 'Channel': 'channel', | |
28 | 'ChannelList': 'channel_list', | |
29 | } | |
4ef91524 S |
30 | |
31 | def smuggle(url): | |
32 | return smuggle_url(url, {'source_url': source_url}) | |
33 | ||
e5d39886 S |
34 | entries = [] |
35 | for kind, video_id in re.findall( | |
36 | r'LimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P<id>[a-z0-9]{32})', | |
37 | webpage): | |
e5d39886 | 38 | entries.append(cls.url_result( |
4ef91524 | 39 | smuggle('limelight:%s:%s' % (lm[kind], video_id)), |
e5d39886 S |
40 | 'Limelight%s' % kind, video_id)) |
41 | for mobj in re.finditer( | |
42 | # As per [1] class attribute should be exactly equal to | |
43 | # LimelightEmbeddedPlayerFlash but numerous examples seen | |
44 | # that don't exactly match it (e.g. [2]). | |
45 | # 1. http://support.3playmedia.com/hc/en-us/articles/227732408-Limelight-Embedding-the-Captions-Plugin-with-the-Limelight-Player-on-Your-Webpage | |
46 | # 2. http://www.sedona.com/FacilitatorTraining2017 | |
47 | r'''(?sx) | |
48 | <object[^>]+class=(["\'])(?:(?!\1).)*\bLimelightEmbeddedPlayerFlash\b(?:(?!\1).)*\1[^>]*>.*? | |
49 | <param[^>]+ | |
50 | name=(["\'])flashVars\2[^>]+ | |
91bc57e4 | 51 | value=(["\'])(?:(?!\3).)*(?P<kind>media|channel(?:List)?)Id=(?P<id>[a-z0-9]{32}) |
e5d39886 | 52 | ''', webpage): |
91bc57e4 | 53 | kind, video_id = mobj.group('kind'), mobj.group('id') |
e5d39886 | 54 | entries.append(cls.url_result( |
4ef91524 | 55 | smuggle('limelight:%s:%s' % (kind, video_id)), |
91bc57e4 | 56 | 'Limelight%s' % kind.capitalize(), video_id)) |
4ef91524 S |
57 | # http://support.3playmedia.com/hc/en-us/articles/115009517327-Limelight-Embedding-the-Audio-Description-Plugin-with-the-Limelight-Player-on-Your-Web-Page) |
58 | for video_id in re.findall( | |
59 | r'(?s)LimelightPlayerUtil\.embed\s*\(\s*{.*?\bmediaId["\']\s*:\s*["\'](?P<id>[a-z0-9]{32})', | |
60 | webpage): | |
61 | entries.append(cls.url_result( | |
62 | smuggle('limelight:media:%s' % video_id), | |
63 | LimelightMediaIE.ie_key(), video_id)) | |
e5d39886 S |
64 | return entries |
65 | ||
454e5cdb RA |
66 | def _call_playlist_service(self, item_id, method, fatal=True, referer=None): |
67 | headers = {} | |
68 | if referer: | |
69 | headers['Referer'] = referer | |
3444844b RA |
70 | try: |
71 | return self._download_json( | |
72 | self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method), | |
73 | item_id, 'Downloading PlaylistService %s JSON' % method, fatal=fatal, headers=headers) | |
74 | except ExtractorError as e: | |
75 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
76 | error = self._parse_json(e.cause.read().decode(), item_id)['detail']['contentAccessPermission'] | |
77 | if error == 'CountryDisabled': | |
78 | self.raise_geo_restricted() | |
79 | raise ExtractorError(error, expected=True) | |
80 | raise | |
ef5acfe3 | 81 | |
d7fc5631 S |
82 | def _call_api(self, organization_id, item_id, method): |
83 | return self._download_json( | |
84 | self._API_URL % (organization_id, self._API_PATH, item_id, method), | |
85 | item_id, 'Downloading API %s JSON' % method) | |
ef5acfe3 | 86 | |
454e5cdb RA |
87 | def _extract(self, item_id, pc_method, mobile_method, meta_method, referer=None): |
88 | pc = self._call_playlist_service(item_id, pc_method, referer=referer) | |
d7fc5631 | 89 | metadata = self._call_api(pc['orgId'], item_id, meta_method) |
454e5cdb | 90 | mobile = self._call_playlist_service(item_id, mobile_method, fatal=False, referer=referer) |
d7fc5631 S |
91 | return pc, mobile, metadata |
92 | ||
93 | def _extract_info(self, streams, mobile_urls, properties): | |
ef5acfe3 | 94 | video_id = properties['media_id'] |
95 | formats = [] | |
f8fd510e | 96 | urls = [] |
ef5acfe3 | 97 | for stream in streams: |
d7fc5631 | 98 | stream_url = stream.get('url') |
f8fd510e | 99 | if not stream_url or stream.get('drmProtected') or stream_url in urls: |
d7fc5631 | 100 | continue |
f8fd510e | 101 | urls.append(stream_url) |
e382b953 RA |
102 | ext = determine_ext(stream_url) |
103 | if ext == 'f4m': | |
8f1fddc8 | 104 | formats.extend(self._extract_f4m_formats( |
e382b953 | 105 | stream_url, video_id, f4m_id='hds', fatal=False)) |
ef5acfe3 | 106 | else: |
107 | fmt = { | |
d7fc5631 S |
108 | 'url': stream_url, |
109 | 'abr': float_or_none(stream.get('audioBitRate')), | |
d7fc5631 | 110 | 'fps': float_or_none(stream.get('videoFrameRate')), |
e382b953 | 111 | 'ext': ext, |
ef5acfe3 | 112 | } |
a6f3a162 RA |
113 | width = int_or_none(stream.get('videoWidthInPixels')) |
114 | height = int_or_none(stream.get('videoHeightInPixels')) | |
115 | vbr = float_or_none(stream.get('videoBitRate')) | |
116 | if width or height or vbr: | |
117 | fmt.update({ | |
118 | 'width': width, | |
119 | 'height': height, | |
120 | 'vbr': vbr, | |
121 | }) | |
122 | else: | |
123 | fmt['vcodec'] = 'none' | |
124 | rtmp = re.search(r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', stream_url) | |
ef5acfe3 | 125 | if rtmp: |
d7fc5631 S |
126 | format_id = 'rtmp' |
127 | if stream.get('videoBitRate'): | |
128 | format_id += '-%d' % int_or_none(stream['videoBitRate']) | |
906420ca S |
129 | http_format_id = format_id.replace('rtmp', 'http') |
130 | ||
131 | CDN_HOSTS = ( | |
132 | ('delvenetworks.com', 'cpl.delvenetworks.com'), | |
133 | ('video.llnw.net', 's2.content.video.llnw.net'), | |
134 | ) | |
135 | for cdn_host, http_host in CDN_HOSTS: | |
136 | if cdn_host not in rtmp.group('host').lower(): | |
137 | continue | |
138 | http_url = 'http://%s/%s' % (http_host, rtmp.group('playpath')[4:]) | |
139 | urls.append(http_url) | |
140 | if self._is_valid_url(http_url, video_id, http_format_id): | |
141 | http_fmt = fmt.copy() | |
142 | http_fmt.update({ | |
143 | 'url': http_url, | |
144 | 'format_id': http_format_id, | |
145 | }) | |
146 | formats.append(http_fmt) | |
147 | break | |
148 | ||
ef5acfe3 | 149 | fmt.update({ |
150 | 'url': rtmp.group('url'), | |
151 | 'play_path': rtmp.group('playpath'), | |
152 | 'app': rtmp.group('app'), | |
d7fc5631 S |
153 | 'ext': 'flv', |
154 | 'format_id': format_id, | |
ef5acfe3 | 155 | }) |
156 | formats.append(fmt) | |
157 | ||
d7fc5631 S |
158 | for mobile_url in mobile_urls: |
159 | media_url = mobile_url.get('mobileUrl') | |
d7fc5631 | 160 | format_id = mobile_url.get('targetMediaPlatform') |
f8fd510e | 161 | if not media_url or format_id in ('Widevine', 'SmoothStreaming') or media_url in urls: |
e382b953 | 162 | continue |
f8fd510e | 163 | urls.append(media_url) |
e382b953 RA |
164 | ext = determine_ext(media_url) |
165 | if ext == 'm3u8': | |
d7fc5631 | 166 | formats.extend(self._extract_m3u8_formats( |
8f1fddc8 | 167 | media_url, video_id, 'mp4', 'm3u8_native', |
168 | m3u8_id=format_id, fatal=False)) | |
e382b953 RA |
169 | elif ext == 'f4m': |
170 | formats.extend(self._extract_f4m_formats( | |
171 | stream_url, video_id, f4m_id=format_id, fatal=False)) | |
d7fc5631 S |
172 | else: |
173 | formats.append({ | |
174 | 'url': media_url, | |
175 | 'format_id': format_id, | |
176 | 'preference': -1, | |
e382b953 | 177 | 'ext': ext, |
d7fc5631 S |
178 | }) |
179 | ||
ef5acfe3 | 180 | self._sort_formats(formats) |
181 | ||
182 | title = properties['title'] | |
183 | description = properties.get('description') | |
d7fc5631 S |
184 | timestamp = int_or_none(properties.get('publish_date') or properties.get('create_date')) |
185 | duration = float_or_none(properties.get('duration_in_milliseconds'), 1000) | |
186 | filesize = int_or_none(properties.get('total_storage_in_bytes')) | |
ef5acfe3 | 187 | categories = [properties.get('category')] |
d7fc5631 | 188 | tags = properties.get('tags', []) |
ef5acfe3 | 189 | thumbnails = [{ |
d7fc5631 | 190 | 'url': thumbnail['url'], |
ef5acfe3 | 191 | 'width': int_or_none(thumbnail.get('width')), |
192 | 'height': int_or_none(thumbnail.get('height')), | |
d7fc5631 S |
193 | } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')] |
194 | ||
195 | subtitles = {} | |
21ac1a8a | 196 | for caption in properties.get('captions', []): |
d7fc5631 S |
197 | lang = caption.get('language_code') |
198 | subtitles_url = caption.get('url') | |
199 | if lang and subtitles_url: | |
fe458b65 | 200 | subtitles.setdefault(lang, []).append({ |
d7fc5631 | 201 | 'url': subtitles_url, |
fe458b65 S |
202 | }) |
203 | closed_captions_url = properties.get('closed_captions_url') | |
204 | if closed_captions_url: | |
205 | subtitles.setdefault('en', []).append({ | |
206 | 'url': closed_captions_url, | |
207 | 'ext': 'ttml', | |
208 | }) | |
ef5acfe3 | 209 | |
210 | return { | |
211 | 'id': video_id, | |
212 | 'title': title, | |
213 | 'description': description, | |
214 | 'formats': formats, | |
215 | 'timestamp': timestamp, | |
216 | 'duration': duration, | |
217 | 'filesize': filesize, | |
218 | 'categories': categories, | |
d7fc5631 | 219 | 'tags': tags, |
ef5acfe3 | 220 | 'thumbnails': thumbnails, |
221 | 'subtitles': subtitles, | |
222 | } | |
223 | ||
2b4e1ace S |
224 | def _extract_info_helper(self, pc, mobile, i, metadata): |
225 | return self._extract_info( | |
226 | try_get(pc, lambda x: x['playlistItems'][i]['streams'], list) or [], | |
227 | try_get(mobile, lambda x: x['mediaList'][i]['mobileUrls'], list) or [], | |
228 | metadata) | |
229 | ||
ef5acfe3 | 230 | |
d7fc5631 | 231 | class LimelightMediaIE(LimelightBaseIE): |
ef5acfe3 | 232 | IE_NAME = 'limelight' |
79027c0e S |
233 | _VALID_URL = r'''(?x) |
234 | (?: | |
235 | limelight:media:| | |
236 | https?:// | |
237 | (?: | |
238 | link\.videoplatform\.limelight\.com/media/| | |
239 | assets\.delvenetworks\.com/player/loader\.swf | |
240 | ) | |
241 | \?.*?\bmediaId= | |
242 | ) | |
243 | (?P<id>[a-z0-9]{32}) | |
244 | ''' | |
9c544e25 | 245 | _TESTS = [{ |
ef5acfe3 | 246 | 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86', |
ef5acfe3 | 247 | 'info_dict': { |
248 | 'id': '3ffd040b522b4485b6d84effc750cd86', | |
e382b953 | 249 | 'ext': 'mp4', |
ef5acfe3 | 250 | 'title': 'HaP and the HB Prince Trailer', |
9c544e25 | 251 | 'description': 'md5:8005b944181778e313d95c1237ddb640', |
ec85ded8 | 252 | 'thumbnail': r're:^https?://.*\.jpeg$', |
d7fc5631 | 253 | 'duration': 144.23, |
ef5acfe3 | 254 | 'timestamp': 1244136834, |
d7fc5631 S |
255 | 'upload_date': '20090604', |
256 | }, | |
257 | 'params': { | |
e382b953 | 258 | # m3u8 download |
d7fc5631 S |
259 | 'skip_download': True, |
260 | }, | |
9c544e25 S |
261 | }, { |
262 | # video with subtitles | |
263 | 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335', | |
42b7a5af | 264 | 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d', |
9c544e25 S |
265 | 'info_dict': { |
266 | 'id': 'a3e00274d4564ec4a9b29b9466432335', | |
42b7a5af | 267 | 'ext': 'mp4', |
9c544e25 | 268 | 'title': '3Play Media Overview Video', |
ec85ded8 | 269 | 'thumbnail': r're:^https?://.*\.jpeg$', |
9c544e25 S |
270 | 'duration': 78.101, |
271 | 'timestamp': 1338929955, | |
272 | 'upload_date': '20120605', | |
273 | 'subtitles': 'mincount:9', | |
274 | }, | |
79027c0e S |
275 | }, { |
276 | 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452', | |
277 | 'only_matching': True, | |
9c544e25 | 278 | }] |
d7fc5631 S |
279 | _PLAYLIST_SERVICE_PATH = 'media' |
280 | _API_PATH = 'media' | |
ef5acfe3 | 281 | |
282 | def _real_extract(self, url): | |
454e5cdb | 283 | url, smuggled_data = unsmuggle_url(url, {}) |
ef5acfe3 | 284 | video_id = self._match_id(url) |
5f95927a S |
285 | self._initialize_geo_bypass({ |
286 | 'countries': smuggled_data.get('geo_countries'), | |
287 | }) | |
ef5acfe3 | 288 | |
d7fc5631 | 289 | pc, mobile, metadata = self._extract( |
454e5cdb RA |
290 | video_id, 'getPlaylistByMediaId', |
291 | 'getMobilePlaylistByMediaId', 'properties', | |
292 | smuggled_data.get('source_url')) | |
ef5acfe3 | 293 | |
2b4e1ace | 294 | return self._extract_info_helper(pc, mobile, 0, metadata) |
ef5acfe3 | 295 | |
296 | ||
d7fc5631 | 297 | class LimelightChannelIE(LimelightBaseIE): |
ef5acfe3 | 298 | IE_NAME = 'limelight:channel' |
79027c0e S |
299 | _VALID_URL = r'''(?x) |
300 | (?: | |
301 | limelight:channel:| | |
302 | https?:// | |
303 | (?: | |
304 | link\.videoplatform\.limelight\.com/media/| | |
305 | assets\.delvenetworks\.com/player/loader\.swf | |
306 | ) | |
307 | \?.*?\bchannelId= | |
308 | ) | |
309 | (?P<id>[a-z0-9]{32}) | |
310 | ''' | |
311 | _TESTS = [{ | |
ef5acfe3 | 312 | 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082', |
313 | 'info_dict': { | |
314 | 'id': 'ab6a524c379342f9b23642917020c082', | |
315 | 'title': 'Javascript Sample Code', | |
316 | }, | |
317 | 'playlist_mincount': 3, | |
79027c0e S |
318 | }, { |
319 | 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082', | |
320 | 'only_matching': True, | |
321 | }] | |
d7fc5631 S |
322 | _PLAYLIST_SERVICE_PATH = 'channel' |
323 | _API_PATH = 'channels' | |
ef5acfe3 | 324 | |
325 | def _real_extract(self, url): | |
454e5cdb | 326 | url, smuggled_data = unsmuggle_url(url, {}) |
ef5acfe3 | 327 | channel_id = self._match_id(url) |
328 | ||
d7fc5631 S |
329 | pc, mobile, medias = self._extract( |
330 | channel_id, 'getPlaylistByChannelId', | |
454e5cdb RA |
331 | 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', |
332 | 'media', smuggled_data.get('source_url')) | |
ef5acfe3 | 333 | |
d7fc5631 | 334 | entries = [ |
2b4e1ace | 335 | self._extract_info_helper(pc, mobile, i, medias['media_list'][i]) |
d7fc5631 | 336 | for i in range(len(medias['media_list']))] |
ef5acfe3 | 337 | |
d7fc5631 | 338 | return self.playlist_result(entries, channel_id, pc['title']) |
ef5acfe3 | 339 | |
340 | ||
d7fc5631 | 341 | class LimelightChannelListIE(LimelightBaseIE): |
ef5acfe3 | 342 | IE_NAME = 'limelight:channel_list' |
79027c0e S |
343 | _VALID_URL = r'''(?x) |
344 | (?: | |
345 | limelight:channel_list:| | |
346 | https?:// | |
347 | (?: | |
348 | link\.videoplatform\.limelight\.com/media/| | |
349 | assets\.delvenetworks\.com/player/loader\.swf | |
350 | ) | |
351 | \?.*?\bchannelListId= | |
352 | ) | |
353 | (?P<id>[a-z0-9]{32}) | |
354 | ''' | |
355 | _TESTS = [{ | |
ef5acfe3 | 356 | 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b', |
357 | 'info_dict': { | |
358 | 'id': '301b117890c4465c8179ede21fd92e2b', | |
359 | 'title': 'Website - Hero Player', | |
360 | }, | |
361 | 'playlist_mincount': 2, | |
79027c0e S |
362 | }, { |
363 | 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b', | |
364 | 'only_matching': True, | |
365 | }] | |
d7fc5631 | 366 | _PLAYLIST_SERVICE_PATH = 'channel_list' |
ef5acfe3 | 367 | |
368 | def _real_extract(self, url): | |
369 | channel_list_id = self._match_id(url) | |
370 | ||
d7fc5631 | 371 | channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById') |
ef5acfe3 | 372 | |
d7fc5631 S |
373 | entries = [ |
374 | self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel') | |
375 | for channel in channel_list['channelList']] | |
ef5acfe3 | 376 | |
d7fc5631 | 377 | return self.playlist_result(entries, channel_list_id, channel_list['title']) |