2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_HTTPError
17 class LimelightBaseIE(InfoExtractor):
18 _PLAYLIST_SERVICE_URL = 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
19 _API_URL = 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json'
21 def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
24 headers['Referer'] = referer
26 return self._download_json(
27 self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
28 item_id, 'Downloading PlaylistService %s JSON' % method, fatal=fatal, headers=headers)
29 except ExtractorError as e:
30 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
31 error = self._parse_json(e.cause.read().decode(), item_id)['detail']['contentAccessPermission']
32 if error == 'CountryDisabled':
33 self.raise_geo_restricted()
34 raise ExtractorError(error, expected=True)
37 def _call_api(self, organization_id, item_id, method):
38 return self._download_json(
39 self._API_URL % (organization_id, self._API_PATH, item_id, method),
40 item_id, 'Downloading API %s JSON' % method)
42 def _extract(self, item_id, pc_method, mobile_method, meta_method, referer=None):
43 pc = self._call_playlist_service(item_id, pc_method, referer=referer)
44 metadata = self._call_api(pc['orgId'], item_id, meta_method)
45 mobile = self._call_playlist_service(item_id, mobile_method, fatal=False, referer=referer)
46 return pc, mobile, metadata
48 def _extract_info(self, streams, mobile_urls, properties):
49 video_id = properties['media_id']
52 for stream in streams:
53 stream_url = stream.get('url')
54 if not stream_url or stream.get('drmProtected') or stream_url in urls:
56 urls.append(stream_url)
57 ext = determine_ext(stream_url)
59 formats.extend(self._extract_f4m_formats(
60 stream_url, video_id, f4m_id='hds', fatal=False))
64 'abr': float_or_none(stream.get('audioBitRate')),
65 'fps': float_or_none(stream.get('videoFrameRate')),
68 width = int_or_none(stream.get('videoWidthInPixels'))
69 height = int_or_none(stream.get('videoHeightInPixels'))
70 vbr = float_or_none(stream.get('videoBitRate'))
71 if width or height or vbr:
78 fmt['vcodec'] = 'none'
79 rtmp = re.search(r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', stream_url)
82 if stream.get('videoBitRate'):
83 format_id += '-%d' % int_or_none(stream['videoBitRate'])
84 http_format_id = format_id.replace('rtmp', 'http')
87 ('delvenetworks.com', 'cpl.delvenetworks.com'),
88 ('video.llnw.net', 's2.content.video.llnw.net'),
90 for cdn_host, http_host in CDN_HOSTS:
91 if cdn_host not in rtmp.group('host').lower():
93 http_url = 'http://%s/%s' % (http_host, rtmp.group('playpath')[4:])
95 if self._is_valid_url(http_url, video_id, http_format_id):
99 'format_id': http_format_id,
101 formats.append(http_fmt)
105 'url': rtmp.group('url'),
106 'play_path': rtmp.group('playpath'),
107 'app': rtmp.group('app'),
109 'format_id': format_id,
113 for mobile_url in mobile_urls:
114 media_url = mobile_url.get('mobileUrl')
115 format_id = mobile_url.get('targetMediaPlatform')
116 if not media_url or format_id in ('Widevine', 'SmoothStreaming') or media_url in urls:
118 urls.append(media_url)
119 ext = determine_ext(media_url)
121 formats.extend(self._extract_m3u8_formats(
122 media_url, video_id, 'mp4', 'm3u8_native',
123 m3u8_id=format_id, fatal=False))
125 formats.extend(self._extract_f4m_formats(
126 stream_url, video_id, f4m_id=format_id, fatal=False))
130 'format_id': format_id,
135 self._sort_formats(formats)
137 title = properties['title']
138 description = properties.get('description')
139 timestamp = int_or_none(properties.get('publish_date') or properties.get('create_date'))
140 duration = float_or_none(properties.get('duration_in_milliseconds'), 1000)
141 filesize = int_or_none(properties.get('total_storage_in_bytes'))
142 categories = [properties.get('category')]
143 tags = properties.get('tags', [])
145 'url': thumbnail['url'],
146 'width': int_or_none(thumbnail.get('width')),
147 'height': int_or_none(thumbnail.get('height')),
148 } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')]
151 for caption in properties.get('captions', []):
152 lang = caption.get('language_code')
153 subtitles_url = caption.get('url')
154 if lang and subtitles_url:
155 subtitles.setdefault(lang, []).append({
156 'url': subtitles_url,
158 closed_captions_url = properties.get('closed_captions_url')
159 if closed_captions_url:
160 subtitles.setdefault('en', []).append({
161 'url': closed_captions_url,
168 'description': description,
170 'timestamp': timestamp,
171 'duration': duration,
172 'filesize': filesize,
173 'categories': categories,
175 'thumbnails': thumbnails,
176 'subtitles': subtitles,
180 class LimelightMediaIE(LimelightBaseIE):
181 IE_NAME = 'limelight'
182 _VALID_URL = r'''(?x)
187 link\.videoplatform\.limelight\.com/media/|
188 assets\.delvenetworks\.com/player/loader\.swf
195 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
197 'id': '3ffd040b522b4485b6d84effc750cd86',
199 'title': 'HaP and the HB Prince Trailer',
200 'description': 'md5:8005b944181778e313d95c1237ddb640',
201 'thumbnail': r're:^https?://.*\.jpeg$',
203 'timestamp': 1244136834,
204 'upload_date': '20090604',
208 'skip_download': True,
211 # video with subtitles
212 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
213 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
215 'id': 'a3e00274d4564ec4a9b29b9466432335',
217 'title': '3Play Media Overview Video',
218 'thumbnail': r're:^https?://.*\.jpeg$',
220 'timestamp': 1338929955,
221 'upload_date': '20120605',
222 'subtitles': 'mincount:9',
225 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
226 'only_matching': True,
228 _PLAYLIST_SERVICE_PATH = 'media'
231 def _real_extract(self, url):
232 url, smuggled_data = unsmuggle_url(url, {})
233 video_id = self._match_id(url)
234 self._initialize_geo_bypass(smuggled_data.get('geo_countries'))
236 pc, mobile, metadata = self._extract(
237 video_id, 'getPlaylistByMediaId',
238 'getMobilePlaylistByMediaId', 'properties',
239 smuggled_data.get('source_url'))
241 return self._extract_info(
242 pc['playlistItems'][0].get('streams', []),
243 mobile['mediaList'][0].get('mobileUrls', []) if mobile else [],
247 class LimelightChannelIE(LimelightBaseIE):
248 IE_NAME = 'limelight:channel'
249 _VALID_URL = r'''(?x)
254 link\.videoplatform\.limelight\.com/media/|
255 assets\.delvenetworks\.com/player/loader\.swf
262 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
264 'id': 'ab6a524c379342f9b23642917020c082',
265 'title': 'Javascript Sample Code',
267 'playlist_mincount': 3,
269 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
270 'only_matching': True,
272 _PLAYLIST_SERVICE_PATH = 'channel'
273 _API_PATH = 'channels'
275 def _real_extract(self, url):
276 url, smuggled_data = unsmuggle_url(url, {})
277 channel_id = self._match_id(url)
279 pc, mobile, medias = self._extract(
280 channel_id, 'getPlaylistByChannelId',
281 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1',
282 'media', smuggled_data.get('source_url'))
286 pc['playlistItems'][i].get('streams', []),
287 mobile['mediaList'][i].get('mobileUrls', []) if mobile else [],
288 medias['media_list'][i])
289 for i in range(len(medias['media_list']))]
291 return self.playlist_result(entries, channel_id, pc['title'])
294 class LimelightChannelListIE(LimelightBaseIE):
295 IE_NAME = 'limelight:channel_list'
296 _VALID_URL = r'''(?x)
298 limelight:channel_list:|
301 link\.videoplatform\.limelight\.com/media/|
302 assets\.delvenetworks\.com/player/loader\.swf
304 \?.*?\bchannelListId=
309 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
311 'id': '301b117890c4465c8179ede21fd92e2b',
312 'title': 'Website - Hero Player',
314 'playlist_mincount': 2,
316 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
317 'only_matching': True,
319 _PLAYLIST_SERVICE_PATH = 'channel_list'
321 def _real_extract(self, url):
322 channel_list_id = self._match_id(url)
324 channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById')
327 self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
328 for channel in channel_list['channelList']]
330 return self.playlist_result(entries, channel_list_id, channel_list['title'])