2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_HTTPError
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'
24 def _extract_urls(cls
, webpage
, source_url
):
28 'ChannelList': 'channel_list',
32 return smuggle_url(url
, {'source_url': source_url
})
35 for kind
, video_id
in re
.findall(
36 r
'LimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P
<id>[a
-z0
-9]{32}
)',
38 entries.append(cls.url_result(
39 smuggle('limelight
:%s:%s' % (lm[kind], video_id)),
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
48 <object[^>]+class=(["\'])(?
:(?
!\
1).)*\bLimelightEmbeddedPlayerFlash
\b(?
:(?
!\
1).)*\
1[^
>]*>.*?
50 name
=(["\'])flashVars\2[^>]+
51 value=(["\'])(?
:(?
!\
3).)*(?P
<kind
>media|
channel(?
:List
)?
)Id
=(?P
<id>[a
-z0
-9]{32}
)
53 kind, video_id = mobj.group('kind'), mobj.group('id')
54 entries.append(cls.url_result(
55 smuggle('limelight:%s:%s' % (kind, video_id)),
56 'Limelight%s' % kind.capitalize(), video_id))
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})',
61 entries.append(cls.url_result(
62 smuggle('limelight:media:%s' % video_id),
63 LimelightMediaIE.ie_key(), video_id))
66 def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
69 headers['Referer'] = referer
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)
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)
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)
89 metadata = self._call_api(pc['orgId'], item_id, meta_method)
90 mobile = self._call_playlist_service(item_id, mobile_method, fatal=False, referer=referer)
91 return pc, mobile, metadata
93 def _extract_info(self, streams, mobile_urls, properties):
94 video_id = properties['media_id']
97 for stream in streams:
98 stream_url = stream.get('url')
99 if not stream_url or stream.get('drmProtected') or stream_url in urls:
101 urls.append(stream_url)
102 ext = determine_ext(stream_url)
104 formats.extend(self._extract_f4m_formats(
105 stream_url, video_id, f4m_id='hds', fatal=False))
109 'abr': float_or_none(stream.get('audioBitRate')),
110 'fps': float_or_none(stream.get('videoFrameRate')),
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:
123 fmt['vcodec'] = 'none'
124 rtmp = re.search(r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', stream_url)
127 if stream.get('videoBitRate'):
128 format_id += '-%d' % int_or_none(stream['videoBitRate'])
129 http_format_id = format_id.replace('rtmp', 'http')
132 ('delvenetworks.com', 'cpl.delvenetworks.com'),
133 ('video.llnw.net', 's2.content.video.llnw.net'),
135 for cdn_host, http_host in CDN_HOSTS:
136 if cdn_host not in rtmp.group('host').lower():
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()
144 'format_id': http_format_id,
146 formats.append(http_fmt)
150 'url': rtmp.group('url'),
151 'play_path': rtmp.group('playpath'),
152 'app': rtmp.group('app'),
154 'format_id': format_id,
158 for mobile_url in mobile_urls:
159 media_url = mobile_url.get('mobileUrl')
160 format_id = mobile_url.get('targetMediaPlatform')
161 if not media_url or format_id in ('Widevine', 'SmoothStreaming') or media_url in urls:
163 urls.append(media_url)
164 ext = determine_ext(media_url)
166 formats.extend(self._extract_m3u8_formats(
167 media_url, video_id, 'mp4', 'm3u8_native',
168 m3u8_id=format_id, fatal=False))
170 formats.extend(self._extract_f4m_formats(
171 stream_url, video_id, f4m_id=format_id, fatal=False))
175 'format_id': format_id,
180 self._sort_formats(formats)
182 title = properties['title']
183 description = properties.get('description')
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'))
187 categories = [properties.get('category')]
188 tags = properties.get('tags', [])
190 'url': thumbnail['url'],
191 'width': int_or_none(thumbnail.get('width')),
192 'height': int_or_none(thumbnail.get('height')),
193 } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')]
196 for caption in properties.get('captions', []):
197 lang = caption.get('language_code')
198 subtitles_url = caption.get('url')
199 if lang and subtitles_url:
200 subtitles.setdefault(lang, []).append({
201 'url': subtitles_url,
203 closed_captions_url = properties.get('closed_captions_url')
204 if closed_captions_url:
205 subtitles.setdefault('en', []).append({
206 'url': closed_captions_url,
213 'description': description,
215 'timestamp': timestamp,
216 'duration': duration,
217 'filesize': filesize,
218 'categories': categories,
220 'thumbnails': thumbnails,
221 'subtitles': subtitles,
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 [],
231 class LimelightMediaIE(LimelightBaseIE):
232 IE_NAME = 'limelight'
233 _VALID_URL = r'''(?x
)
238 link\
.videoplatform\
.limelight\
.com
/media
/|
239 assets\
.delvenetworks\
.com
/player
/loader\
.swf
246 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
248 'id': '3ffd040b522b4485b6d84effc750cd86',
250 'title': 'HaP and the HB Prince Trailer',
251 'description': 'md5:8005b944181778e313d95c1237ddb640',
252 'thumbnail': r're:^https?://.*\.jpeg$',
254 'timestamp': 1244136834,
255 'upload_date': '20090604',
259 'skip_download': True,
262 # video with subtitles
263 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
264 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
266 'id': 'a3e00274d4564ec4a9b29b9466432335',
268 'title': '3Play Media Overview Video',
269 'thumbnail': r're:^https?://.*\.jpeg$',
271 'timestamp': 1338929955,
272 'upload_date': '20120605',
273 'subtitles': 'mincount:9',
276 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
277 'only_matching': True,
279 _PLAYLIST_SERVICE_PATH = 'media'
282 def _real_extract(self, url):
283 url, smuggled_data = unsmuggle_url(url, {})
284 video_id = self._match_id(url)
285 self._initialize_geo_bypass(smuggled_data.get('geo_countries'))
287 pc, mobile, metadata = self._extract(
288 video_id, 'getPlaylistByMediaId',
289 'getMobilePlaylistByMediaId', 'properties',
290 smuggled_data.get('source_url'))
292 return self._extract_info_helper(pc, mobile, 0, metadata)
295 class LimelightChannelIE(LimelightBaseIE):
296 IE_NAME = 'limelight:channel'
297 _VALID_URL = r'''(?x
)
302 link\
.videoplatform\
.limelight\
.com
/media
/|
303 assets\
.delvenetworks\
.com
/player
/loader\
.swf
310 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
312 'id': 'ab6a524c379342f9b23642917020c082',
313 'title': 'Javascript Sample Code',
315 'playlist_mincount': 3,
317 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
318 'only_matching': True,
320 _PLAYLIST_SERVICE_PATH = 'channel'
321 _API_PATH = 'channels'
323 def _real_extract(self, url):
324 url, smuggled_data = unsmuggle_url(url, {})
325 channel_id = self._match_id(url)
327 pc, mobile, medias = self._extract(
328 channel_id, 'getPlaylistByChannelId',
329 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1',
330 'media', smuggled_data.get('source_url'))
333 self._extract_info_helper(pc, mobile, i, medias['media_list'][i])
334 for i in range(len(medias['media_list']))]
336 return self.playlist_result(entries, channel_id, pc['title'])
339 class LimelightChannelListIE(LimelightBaseIE):
340 IE_NAME = 'limelight:channel_list'
341 _VALID_URL = r'''(?x
)
343 limelight
:channel_list
:|
346 link\
.videoplatform\
.limelight\
.com
/media
/|
347 assets\
.delvenetworks\
.com
/player
/loader\
.swf
349 \?.*?
\bchannelListId
=
354 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
356 'id': '301b117890c4465c8179ede21fd92e2b',
357 'title': 'Website - Hero Player',
359 'playlist_mincount': 2,
361 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
362 'only_matching': True,
364 _PLAYLIST_SERVICE_PATH = 'channel_list'
366 def _real_extract(self, url):
367 channel_list_id = self._match_id(url)
369 channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById')
372 self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
373 for channel in channel_list['channelList']]
375 return self.playlist_result(entries, channel_list_id, channel_list['title'])