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