2 from __future__ import unicode_literals
6 from .common import InfoExtractor
15 class LimelightBaseIE(InfoExtractor):
16 _PLAYLIST_SERVICE_URL = 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
17 _API_URL = 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json'
19 def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
22 headers['Referer'] = referer
23 return self._download_json(
24 self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
25 item_id, 'Downloading PlaylistService %s JSON' % method, fatal=fatal, headers=headers)
27 def _call_api(self, organization_id, item_id, method):
28 return self._download_json(
29 self._API_URL % (organization_id, self._API_PATH, item_id, method),
30 item_id, 'Downloading API %s JSON' % method)
32 def _extract(self, item_id, pc_method, mobile_method, meta_method, referer=None):
33 pc = self._call_playlist_service(item_id, pc_method, referer=referer)
34 metadata = self._call_api(pc['orgId'], item_id, meta_method)
35 mobile = self._call_playlist_service(item_id, mobile_method, fatal=False, referer=referer)
36 return pc, mobile, metadata
38 def _extract_info(self, streams, mobile_urls, properties):
39 video_id = properties['media_id']
42 for stream in streams:
43 stream_url = stream.get('url')
44 if not stream_url or stream.get('drmProtected') or stream_url in urls:
46 urls.append(stream_url)
47 ext = determine_ext(stream_url)
49 formats.extend(self._extract_f4m_formats(
50 stream_url, video_id, f4m_id='hds', fatal=False))
54 'abr': float_or_none(stream.get('audioBitRate')),
55 'vbr': float_or_none(stream.get('videoBitRate')),
56 'fps': float_or_none(stream.get('videoFrameRate')),
57 'width': int_or_none(stream.get('videoWidthInPixels')),
58 'height': int_or_none(stream.get('videoHeightInPixels')),
61 rtmp = re.search(r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp4:.+)$', stream_url)
64 if stream.get('videoBitRate'):
65 format_id += '-%d' % int_or_none(stream['videoBitRate'])
66 http_format_id = format_id.replace('rtmp', 'http')
69 ('delvenetworks.com', 'cpl.delvenetworks.com'),
70 ('video.llnw.net', 's2.content.video.llnw.net'),
72 for cdn_host, http_host in CDN_HOSTS:
73 if cdn_host not in rtmp.group('host').lower():
75 http_url = 'http://%s/%s' % (http_host, rtmp.group('playpath')[4:])
77 if self._is_valid_url(http_url, video_id, http_format_id):
81 'format_id': http_format_id,
83 formats.append(http_fmt)
87 'url': rtmp.group('url'),
88 'play_path': rtmp.group('playpath'),
89 'app': rtmp.group('app'),
91 'format_id': format_id,
95 for mobile_url in mobile_urls:
96 media_url = mobile_url.get('mobileUrl')
97 format_id = mobile_url.get('targetMediaPlatform')
98 if not media_url or format_id in ('Widevine', 'SmoothStreaming') or media_url in urls:
100 urls.append(media_url)
101 ext = determine_ext(media_url)
103 formats.extend(self._extract_m3u8_formats(
104 media_url, video_id, 'mp4', 'm3u8_native',
105 m3u8_id=format_id, fatal=False))
107 formats.extend(self._extract_f4m_formats(
108 stream_url, video_id, f4m_id=format_id, fatal=False))
112 'format_id': format_id,
117 self._sort_formats(formats)
119 title = properties['title']
120 description = properties.get('description')
121 timestamp = int_or_none(properties.get('publish_date') or properties.get('create_date'))
122 duration = float_or_none(properties.get('duration_in_milliseconds'), 1000)
123 filesize = int_or_none(properties.get('total_storage_in_bytes'))
124 categories = [properties.get('category')]
125 tags = properties.get('tags', [])
127 'url': thumbnail['url'],
128 'width': int_or_none(thumbnail.get('width')),
129 'height': int_or_none(thumbnail.get('height')),
130 } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')]
133 for caption in properties.get('captions', []):
134 lang = caption.get('language_code')
135 subtitles_url = caption.get('url')
136 if lang and subtitles_url:
137 subtitles.setdefault(lang, []).append({
138 'url': subtitles_url,
140 closed_captions_url = properties.get('closed_captions_url')
141 if closed_captions_url:
142 subtitles.setdefault('en', []).append({
143 'url': closed_captions_url,
150 'description': description,
152 'timestamp': timestamp,
153 'duration': duration,
154 'filesize': filesize,
155 'categories': categories,
157 'thumbnails': thumbnails,
158 'subtitles': subtitles,
162 class LimelightMediaIE(LimelightBaseIE):
163 IE_NAME = 'limelight'
164 _VALID_URL = r'''(?x)
169 link\.videoplatform\.limelight\.com/media/|
170 assets\.delvenetworks\.com/player/loader\.swf
177 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
179 'id': '3ffd040b522b4485b6d84effc750cd86',
181 'title': 'HaP and the HB Prince Trailer',
182 'description': 'md5:8005b944181778e313d95c1237ddb640',
183 'thumbnail': r're:^https?://.*\.jpeg$',
185 'timestamp': 1244136834,
186 'upload_date': '20090604',
190 'skip_download': True,
193 # video with subtitles
194 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
195 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
197 'id': 'a3e00274d4564ec4a9b29b9466432335',
199 'title': '3Play Media Overview Video',
200 'thumbnail': r're:^https?://.*\.jpeg$',
202 'timestamp': 1338929955,
203 'upload_date': '20120605',
204 'subtitles': 'mincount:9',
207 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
208 'only_matching': True,
210 _PLAYLIST_SERVICE_PATH = 'media'
213 def _real_extract(self, url):
214 url, smuggled_data = unsmuggle_url(url, {})
215 video_id = self._match_id(url)
217 pc, mobile, metadata = self._extract(
218 video_id, 'getPlaylistByMediaId',
219 'getMobilePlaylistByMediaId', 'properties',
220 smuggled_data.get('source_url'))
222 return self._extract_info(
223 pc['playlistItems'][0].get('streams', []),
224 mobile['mediaList'][0].get('mobileUrls', []) if mobile else [],
228 class LimelightChannelIE(LimelightBaseIE):
229 IE_NAME = 'limelight:channel'
230 _VALID_URL = r'''(?x)
235 link\.videoplatform\.limelight\.com/media/|
236 assets\.delvenetworks\.com/player/loader\.swf
243 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
245 'id': 'ab6a524c379342f9b23642917020c082',
246 'title': 'Javascript Sample Code',
248 'playlist_mincount': 3,
250 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
251 'only_matching': True,
253 _PLAYLIST_SERVICE_PATH = 'channel'
254 _API_PATH = 'channels'
256 def _real_extract(self, url):
257 url, smuggled_data = unsmuggle_url(url, {})
258 channel_id = self._match_id(url)
260 pc, mobile, medias = self._extract(
261 channel_id, 'getPlaylistByChannelId',
262 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1',
263 'media', smuggled_data.get('source_url'))
267 pc['playlistItems'][i].get('streams', []),
268 mobile['mediaList'][i].get('mobileUrls', []) if mobile else [],
269 medias['media_list'][i])
270 for i in range(len(medias['media_list']))]
272 return self.playlist_result(entries, channel_id, pc['title'])
275 class LimelightChannelListIE(LimelightBaseIE):
276 IE_NAME = 'limelight:channel_list'
277 _VALID_URL = r'''(?x)
279 limelight:channel_list:|
282 link\.videoplatform\.limelight\.com/media/|
283 assets\.delvenetworks\.com/player/loader\.swf
285 \?.*?\bchannelListId=
290 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
292 'id': '301b117890c4465c8179ede21fd92e2b',
293 'title': 'Website - Hero Player',
295 'playlist_mincount': 2,
297 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
298 'only_matching': True,
300 _PLAYLIST_SERVICE_PATH = 'channel_list'
302 def _real_extract(self, url):
303 channel_list_id = self._match_id(url)
305 channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById')
308 self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
309 for channel in channel_list['channelList']]
311 return self.playlist_result(entries, channel_list_id, channel_list['title'])