3 from .common
import InfoExtractor
4 from ..networking
.exceptions
import HTTPError
16 class LimelightBaseIE(InfoExtractor
):
17 _PLAYLIST_SERVICE_URL
= 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
20 def _extract_embed_urls(cls
, url
, webpage
):
24 'ChannelList': 'channel_list',
28 return smuggle_url(url
, {'source_url': url
})
31 for kind
, video_id
in re
.findall(
32 r
'LimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P
<id>[a
-z0
-9]{32}
)',
34 entries.append(cls.url_result(
35 smuggle(f'limelight
:{lm
[kind
]}:{video_id}
'),
36 f'Limelight{kind}
', video_id))
37 for mobj in re.finditer(
38 # As per [1] class attribute should be exactly equal to
39 # LimelightEmbeddedPlayerFlash but numerous examples seen
40 # that don't exactly match
it (e
.g
. [2]).
41 # 1. http://support.3playmedia.com/hc/en-us/articles/227732408-Limelight-Embedding-the-Captions-Plugin-with-the-Limelight-Player-on-Your-Webpage
42 # 2. http://www.sedona.com/FacilitatorTraining2017
44 <object[^>]+class=(["\'])(?
:(?
!\
1).)*\bLimelightEmbeddedPlayerFlash
\b(?
:(?
!\
1).)*\
1[^
>]*>.*?
46 name
=(["\'])flashVars\2[^>]+
47 value=(["\'])(?
:(?
!\
3).)*(?P
<kind
>media|
channel(?
:List
)?
)Id
=(?P
<id>[a
-z0
-9]{32}
)
49 kind, video_id = mobj.group('kind'), mobj.group('id')
50 entries.append(cls.url_result(
51 smuggle(f'limelight:{kind}:{video_id}'),
52 f'Limelight{kind.capitalize()}', video_id))
53 # http://support.3playmedia.com/hc/en-us/articles/115009517327-Limelight-Embedding-the-Audio-Description-Plugin-with-the-Limelight-Player-on-Your-Web-Page)
54 for video_id in re.findall(
55 r'(?s)LimelightPlayerUtil\.embed\s*\(\s*{.*?\bmediaId["\']\s*:\s*["\'](?P<id>[a-z0-9]{32})',
57 entries.append(cls.url_result(
58 smuggle(f'limelight:media:{video_id}'),
59 LimelightMediaIE.ie_key(), video_id))
62 def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
65 headers['Referer'] = referer
67 return self._download_json(
68 self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
69 item_id, f'Downloading PlaylistService {method} JSON',
70 fatal=fatal, headers=headers)
71 except ExtractorError as e:
72 if isinstance(e.cause, HTTPError) and e.cause.status == 403:
73 error = self._parse_json(e.cause.response.read().decode(), item_id)['detail']['contentAccessPermission']
74 if error == 'CountryDisabled':
75 self.raise_geo_restricted()
76 raise ExtractorError(error, expected=True)
79 def _extract(self, item_id, pc_method, mobile_method, referer=None):
80 pc = self._call_playlist_service(item_id, pc_method, referer=referer)
81 mobile = self._call_playlist_service(
82 item_id, mobile_method, fatal=False, referer=referer)
85 def _extract_info(self, pc, mobile, i, referer):
86 get_item = lambda x, y: try_get(x, lambda x: x[y][i], dict) or {}
87 pc_item = get_item(pc, 'playlistItems')
88 mobile_item = get_item(mobile, 'mediaList')
89 video_id = pc_item.get('mediaId') or mobile_item['mediaId']
90 title = pc_item.get('title') or mobile_item['title']
94 for stream in pc_item.get('streams', []):
95 stream_url = stream.get('url')
96 if not stream_url or stream_url in urls:
98 if not self.get_param('allow_unplayable_formats') and stream.get('drmProtected'):
100 urls.append(stream_url)
101 ext = determine_ext(stream_url)
103 formats.extend(self._extract_f4m_formats(
104 stream_url, video_id, f4m_id='hds', fatal=False))
108 'abr': float_or_none(stream.get('audioBitRate')),
109 'fps': float_or_none(stream.get('videoFrameRate')),
112 width = int_or_none(stream.get('videoWidthInPixels'))
113 height = int_or_none(stream.get('videoHeightInPixels'))
114 vbr = float_or_none(stream.get('videoBitRate'))
115 if width or height or vbr:
122 fmt['vcodec'] = 'none'
123 rtmp = re.search(r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', stream_url)
126 if stream.get('videoBitRate'):
127 format_id += '-%d' % int_or_none(stream['videoBitRate'])
128 http_format_id = format_id.replace('rtmp', 'http')
131 ('delvenetworks.com', 'cpl.delvenetworks.com'),
132 ('video.llnw.net', 's2.content.video.llnw.net'),
134 for cdn_host, http_host in CDN_HOSTS:
135 if cdn_host not in rtmp.group('host').lower():
137 http_url = 'http://{}/{}'.format(http_host, rtmp.group('playpath')[4:])
138 urls.append(http_url)
139 if self._is_valid_url(http_url, video_id, http_format_id):
140 http_fmt = fmt.copy()
143 'format_id': http_format_id,
145 formats.append(http_fmt)
149 'url': rtmp.group('url'),
150 'play_path': rtmp.group('playpath'),
151 'app': rtmp.group('app'),
153 'format_id': format_id,
157 for mobile_url in mobile_item.get('mobileUrls', []):
158 media_url = mobile_url.get('mobileUrl')
159 format_id = mobile_url.get('targetMediaPlatform')
160 if not media_url or media_url in urls:
162 if (format_id in ('Widevine', 'SmoothStreaming')
163 and not self.get_param('allow_unplayable_formats', False)):
165 urls.append(media_url)
166 ext = determine_ext(media_url)
168 formats.extend(self._extract_m3u8_formats(
169 media_url, video_id, 'mp4', 'm3u8_native',
170 m3u8_id=format_id, fatal=False))
172 formats.extend(self._extract_f4m_formats(
173 stream_url, video_id, f4m_id=format_id, fatal=False))
177 'format_id': format_id,
183 for flag in mobile_item.get('flags'):
184 if flag == 'ClosedCaptions':
185 closed_captions = self._call_playlist_service(
186 video_id, 'getClosedCaptionsDetailsByMediaId',
187 False, referer) or []
188 for cc in closed_captions:
189 cc_url = cc.get('webvttFileUrl')
192 lang = cc.get('languageCode') or self._search_regex(r'/([a-z]{2})\.vtt', cc_url, 'lang', default='en')
193 subtitles.setdefault(lang, []).append({
198 get_meta = lambda x: pc_item.get(x) or mobile_item.get(x)
203 'description': get_meta('description'),
205 'duration': float_or_none(get_meta('durationInMilliseconds'), 1000),
206 'thumbnail': get_meta('previewImageUrl') or get_meta('thumbnailImageUrl'),
207 'subtitles': subtitles,
211 class LimelightMediaIE(LimelightBaseIE):
212 IE_NAME = 'limelight'
213 _VALID_URL = r'''(?x
)
218 link\
.videoplatform\
.limelight\
.com
/media
/|
219 assets\
.delvenetworks\
.com
/player
/loader\
.swf
226 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
228 'id': '3ffd040b522b4485b6d84effc750cd86',
230 'title': 'HaP and the HB Prince Trailer',
231 'description': 'md5:8005b944181778e313d95c1237ddb640',
232 'thumbnail': r're:^https?://.*\.jpeg$',
237 'skip_download': True,
240 # video with subtitles
241 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
242 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
244 'id': 'a3e00274d4564ec4a9b29b9466432335',
246 'title': '3Play Media Overview Video',
247 'thumbnail': r're:^https?://.*\.jpeg$',
249 # TODO: extract all languages that were accessible via API
250 # 'subtitles': 'mincount:9',
251 'subtitles': 'mincount:1',
254 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
255 'only_matching': True,
257 _PLAYLIST_SERVICE_PATH = 'media'
259 def _real_extract(self, url):
260 url, smuggled_data = unsmuggle_url(url, {})
261 video_id = self._match_id(url)
262 source_url = smuggled_data.get('source_url')
263 self._initialize_geo_bypass({
264 'countries': smuggled_data.get('geo_countries'),
267 pc, mobile = self._extract(
268 video_id, 'getPlaylistByMediaId',
269 'getMobilePlaylistByMediaId', source_url)
271 return self._extract_info(pc, mobile, 0, source_url)
274 class LimelightChannelIE(LimelightBaseIE):
275 IE_NAME = 'limelight:channel'
276 _VALID_URL = r'''(?x
)
281 link\
.videoplatform\
.limelight\
.com
/media
/|
282 assets\
.delvenetworks\
.com
/player
/loader\
.swf
289 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
291 'id': 'ab6a524c379342f9b23642917020c082',
292 'title': 'Javascript Sample Code',
293 'description': 'Javascript Sample Code - http://www.delvenetworks.com/sample-code/playerCode-demo.html',
295 'playlist_mincount': 3,
297 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
298 'only_matching': True,
300 _PLAYLIST_SERVICE_PATH = 'channel'
302 def _real_extract(self, url):
303 url, smuggled_data = unsmuggle_url(url, {})
304 channel_id = self._match_id(url)
305 source_url = smuggled_data.get('source_url')
307 pc, mobile = self._extract(
308 channel_id, 'getPlaylistByChannelId',
309 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1',
313 self._extract_info(pc, mobile, i, source_url)
314 for i in range(len(pc['playlistItems']))]
316 return self.playlist_result(
317 entries, channel_id, pc.get('title'), mobile.get('description'))
320 class LimelightChannelListIE(LimelightBaseIE):
321 IE_NAME = 'limelight:channel_list'
322 _VALID_URL = r'''(?x
)
324 limelight
:channel_list
:|
327 link\
.videoplatform\
.limelight\
.com
/media
/|
328 assets\
.delvenetworks\
.com
/player
/loader\
.swf
330 \?.*?
\bchannelListId
=
335 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
337 'id': '301b117890c4465c8179ede21fd92e2b',
338 'title': 'Website - Hero Player',
340 'playlist_mincount': 2,
342 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
343 'only_matching': True,
345 _PLAYLIST_SERVICE_PATH = 'channel_list'
347 def _real_extract(self, url):
348 channel_list_id = self._match_id(url)
350 channel_list = self._call_playlist_service(
351 channel_list_id, 'getMobileChannelListById')
354 self.url_result('limelight:channel:{}'.format(channel['id']), 'LimelightChannel')
355 for channel in channel_list['channelList']]
357 return self.playlist_result(
358 entries, channel_list_id, channel_list['title'])