2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_HTTPError
18 class LimelightBaseIE(InfoExtractor
):
19 _PLAYLIST_SERVICE_URL
= 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
20 _API_URL
= 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json'
23 def _extract_urls(cls
, webpage
, source_url
):
27 'ChannelList': 'channel_list',
31 return smuggle_url(url
, {'source_url': source_url
})
34 for kind
, video_id
in re
.findall(
35 r
'LimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P
<id>[a
-z0
-9]{32}
)',
37 entries.append(cls.url_result(
38 smuggle('limelight
:%s:%s' % (lm[kind], video_id)),
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
47 <object[^>]+class=(["\'])(?
:(?
!\
1).)*\bLimelightEmbeddedPlayerFlash
\b(?
:(?
!\
1).)*\
1[^
>]*>.*?
49 name
=(["\'])flashVars\2[^>]+
50 value=(["\'])(?
:(?
!\
3).)*(?P
<kind
>media|
channel(?
:List
)?
)Id
=(?P
<id>[a
-z0
-9]{32}
)
52 kind, video_id = mobj.group('kind'), mobj.group('id')
53 entries.append(cls.url_result(
54 smuggle('limelight:%s:%s' % (kind, video_id)),
55 'Limelight%s' % kind.capitalize(), video_id))
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})',
60 entries.append(cls.url_result(
61 smuggle('limelight:media:%s' % video_id),
62 LimelightMediaIE.ie_key(), video_id))
65 def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
68 headers['Referer'] = referer
70 return self._download_json(
71 self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
72 item_id, 'Downloading PlaylistService %s JSON' % method, fatal=fatal, headers=headers)
73 except ExtractorError as e:
74 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
75 error = self._parse_json(e.cause.read().decode(), item_id)['detail']['contentAccessPermission']
76 if error == 'CountryDisabled':
77 self.raise_geo_restricted()
78 raise ExtractorError(error, expected=True)
81 def _call_api(self, organization_id, item_id, method):
82 return self._download_json(
83 self._API_URL % (organization_id, self._API_PATH, item_id, method),
84 item_id, 'Downloading API %s JSON' % method)
86 def _extract(self, item_id, pc_method, mobile_method, meta_method, referer=None):
87 pc = self._call_playlist_service(item_id, pc_method, referer=referer)
88 metadata = self._call_api(pc['orgId'], item_id, meta_method)
89 mobile = self._call_playlist_service(item_id, mobile_method, fatal=False, referer=referer)
90 return pc, mobile, metadata
92 def _extract_info(self, streams, mobile_urls, properties):
93 video_id = properties['media_id']
96 for stream in streams:
97 stream_url = stream.get('url')
98 if not stream_url or stream.get('drmProtected') or stream_url in urls:
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://%s/%s' % (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_urls:
158 media_url = mobile_url.get('mobileUrl')
159 format_id = mobile_url.get('targetMediaPlatform')
160 if not media_url or format_id in ('Widevine', 'SmoothStreaming') or media_url in urls:
162 urls.append(media_url)
163 ext = determine_ext(media_url)
165 formats.extend(self._extract_m3u8_formats(
166 media_url, video_id, 'mp4', 'm3u8_native',
167 m3u8_id=format_id, fatal=False))
169 formats.extend(self._extract_f4m_formats(
170 stream_url, video_id, f4m_id=format_id, fatal=False))
174 'format_id': format_id,
179 self._sort_formats(formats)
181 title = properties['title']
182 description = properties.get('description')
183 timestamp = int_or_none(properties.get('publish_date') or properties.get('create_date'))
184 duration = float_or_none(properties.get('duration_in_milliseconds'), 1000)
185 filesize = int_or_none(properties.get('total_storage_in_bytes'))
186 categories = [properties.get('category')]
187 tags = properties.get('tags', [])
189 'url': thumbnail['url'],
190 'width': int_or_none(thumbnail.get('width')),
191 'height': int_or_none(thumbnail.get('height')),
192 } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')]
195 for caption in properties.get('captions', []):
196 lang = caption.get('language_code')
197 subtitles_url = caption.get('url')
198 if lang and subtitles_url:
199 subtitles.setdefault(lang, []).append({
200 'url': subtitles_url,
202 closed_captions_url = properties.get('closed_captions_url')
203 if closed_captions_url:
204 subtitles.setdefault('en', []).append({
205 'url': closed_captions_url,
212 'description': description,
214 'timestamp': timestamp,
215 'duration': duration,
216 'filesize': filesize,
217 'categories': categories,
219 'thumbnails': thumbnails,
220 'subtitles': subtitles,
224 class LimelightMediaIE(LimelightBaseIE):
225 IE_NAME = 'limelight'
226 _VALID_URL = r'''(?x
)
231 link\
.videoplatform\
.limelight\
.com
/media
/|
232 assets\
.delvenetworks\
.com
/player
/loader\
.swf
239 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
241 'id': '3ffd040b522b4485b6d84effc750cd86',
243 'title': 'HaP and the HB Prince Trailer',
244 'description': 'md5:8005b944181778e313d95c1237ddb640',
245 'thumbnail': r're:^https?://.*\.jpeg$',
247 'timestamp': 1244136834,
248 'upload_date': '20090604',
252 'skip_download': True,
255 # video with subtitles
256 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
257 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
259 'id': 'a3e00274d4564ec4a9b29b9466432335',
261 'title': '3Play Media Overview Video',
262 'thumbnail': r're:^https?://.*\.jpeg$',
264 'timestamp': 1338929955,
265 'upload_date': '20120605',
266 'subtitles': 'mincount:9',
269 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
270 'only_matching': True,
272 _PLAYLIST_SERVICE_PATH = 'media'
275 def _real_extract(self, url):
276 url, smuggled_data = unsmuggle_url(url, {})
277 video_id = self._match_id(url)
278 self._initialize_geo_bypass(smuggled_data.get('geo_countries'))
280 pc, mobile, metadata = self._extract(
281 video_id, 'getPlaylistByMediaId',
282 'getMobilePlaylistByMediaId', 'properties',
283 smuggled_data.get('source_url'))
285 return self._extract_info(
286 pc['playlistItems'][0].get('streams', []),
287 mobile['mediaList'][0].get('mobileUrls', []) if mobile else [],
291 class LimelightChannelIE(LimelightBaseIE):
292 IE_NAME = 'limelight:channel'
293 _VALID_URL = r'''(?x
)
298 link\
.videoplatform\
.limelight\
.com
/media
/|
299 assets\
.delvenetworks\
.com
/player
/loader\
.swf
306 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
308 'id': 'ab6a524c379342f9b23642917020c082',
309 'title': 'Javascript Sample Code',
311 'playlist_mincount': 3,
313 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
314 'only_matching': True,
316 _PLAYLIST_SERVICE_PATH = 'channel'
317 _API_PATH = 'channels'
319 def _real_extract(self, url):
320 url, smuggled_data = unsmuggle_url(url, {})
321 channel_id = self._match_id(url)
323 pc, mobile, medias = self._extract(
324 channel_id, 'getPlaylistByChannelId',
325 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1',
326 'media', smuggled_data.get('source_url'))
330 pc['playlistItems'][i].get('streams', []),
331 mobile['mediaList'][i].get('mobileUrls', []) if mobile else [],
332 medias['media_list'][i])
333 for i in range(len(medias['media_list']))]
335 return self.playlist_result(entries, channel_id, pc['title'])
338 class LimelightChannelListIE(LimelightBaseIE):
339 IE_NAME = 'limelight:channel_list'
340 _VALID_URL = r'''(?x
)
342 limelight
:channel_list
:|
345 link\
.videoplatform\
.limelight\
.com
/media
/|
346 assets\
.delvenetworks\
.com
/player
/loader\
.swf
348 \?.*?
\bchannelListId
=
353 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
355 'id': '301b117890c4465c8179ede21fd92e2b',
356 'title': 'Website - Hero Player',
358 'playlist_mincount': 2,
360 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
361 'only_matching': True,
363 _PLAYLIST_SERVICE_PATH = 'channel_list'
365 def _real_extract(self, url):
366 channel_list_id = self._match_id(url)
368 channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById')
371 self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
372 for channel in channel_list['channelList']]
374 return self.playlist_result(entries, channel_list_id, channel_list['title'])