2 from __future__ import unicode_literals
6 from .common import InfoExtractor
14 class LimelightBaseIE(InfoExtractor):
15 _PLAYLIST_SERVICE_URL = 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
16 _API_URL = 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json'
18 def _call_playlist_service(self, item_id, method, fatal=True):
19 return self._download_json(
20 self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
21 item_id, 'Downloading PlaylistService %s JSON' % method, fatal=fatal)
23 def _call_api(self, organization_id, item_id, method):
24 return self._download_json(
25 self._API_URL % (organization_id, self._API_PATH, item_id, method),
26 item_id, 'Downloading API %s JSON' % method)
28 def _extract(self, item_id, pc_method, mobile_method, meta_method):
29 pc = self._call_playlist_service(item_id, pc_method)
30 metadata = self._call_api(pc['orgId'], item_id, meta_method)
31 mobile = self._call_playlist_service(item_id, mobile_method, fatal=False)
32 return pc, mobile, metadata
34 def _extract_info(self, streams, mobile_urls, properties):
35 video_id = properties['media_id']
38 for stream in streams:
39 stream_url = stream.get('url')
40 if not stream_url or stream.get('drmProtected'):
42 ext = determine_ext(stream_url)
44 formats.extend(self._extract_f4m_formats(
45 stream_url, video_id, f4m_id='hds', fatal=False))
49 'abr': float_or_none(stream.get('audioBitRate')),
50 'vbr': float_or_none(stream.get('videoBitRate')),
51 'fps': float_or_none(stream.get('videoFrameRate')),
52 'width': int_or_none(stream.get('videoWidthInPixels')),
53 'height': int_or_none(stream.get('videoHeightInPixels')),
56 rtmp = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', stream_url)
59 if stream.get('videoBitRate'):
60 format_id += '-%d' % int_or_none(stream['videoBitRate'])
62 'url': rtmp.group('url'),
63 'play_path': rtmp.group('playpath'),
64 'app': rtmp.group('app'),
66 'format_id': format_id,
70 for mobile_url in mobile_urls:
71 media_url = mobile_url.get('mobileUrl')
72 format_id = mobile_url.get('targetMediaPlatform')
73 if not media_url or format_id == 'Widevine':
75 ext = determine_ext(media_url)
77 formats.extend(self._extract_m3u8_formats(
78 media_url, video_id, 'mp4', 'm3u8_native',
79 m3u8_id=format_id, fatal=False))
81 formats.extend(self._extract_f4m_formats(
82 stream_url, video_id, f4m_id=format_id, fatal=False))
86 'format_id': format_id,
91 self._sort_formats(formats)
93 title = properties['title']
94 description = properties.get('description')
95 timestamp = int_or_none(properties.get('publish_date') or properties.get('create_date'))
96 duration = float_or_none(properties.get('duration_in_milliseconds'), 1000)
97 filesize = int_or_none(properties.get('total_storage_in_bytes'))
98 categories = [properties.get('category')]
99 tags = properties.get('tags', [])
101 'url': thumbnail['url'],
102 'width': int_or_none(thumbnail.get('width')),
103 'height': int_or_none(thumbnail.get('height')),
104 } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')]
107 for caption in properties.get('captions', []):
108 lang = caption.get('language_code')
109 subtitles_url = caption.get('url')
110 if lang and subtitles_url:
111 subtitles.setdefault(lang, []).append({
112 'url': subtitles_url,
114 closed_captions_url = properties.get('closed_captions_url')
115 if closed_captions_url:
116 subtitles.setdefault('en', []).append({
117 'url': closed_captions_url,
124 'description': description,
126 'timestamp': timestamp,
127 'duration': duration,
128 'filesize': filesize,
129 'categories': categories,
131 'thumbnails': thumbnails,
132 'subtitles': subtitles,
136 class LimelightMediaIE(LimelightBaseIE):
137 IE_NAME = 'limelight'
138 _VALID_URL = r'''(?x)
143 link\.videoplatform\.limelight\.com/media/|
144 assets\.delvenetworks\.com/player/loader\.swf
151 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
153 'id': '3ffd040b522b4485b6d84effc750cd86',
155 'title': 'HaP and the HB Prince Trailer',
156 'description': 'md5:8005b944181778e313d95c1237ddb640',
157 'thumbnail': 're:^https?://.*\.jpeg$',
159 'timestamp': 1244136834,
160 'upload_date': '20090604',
164 'skip_download': True,
167 # video with subtitles
168 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
170 'id': 'a3e00274d4564ec4a9b29b9466432335',
172 'title': '3Play Media Overview Video',
173 'thumbnail': 're:^https?://.*\.jpeg$',
175 'timestamp': 1338929955,
176 'upload_date': '20120605',
177 'subtitles': 'mincount:9',
181 'skip_download': True,
184 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
185 'only_matching': True,
187 _PLAYLIST_SERVICE_PATH = 'media'
190 def _real_extract(self, url):
191 video_id = self._match_id(url)
193 pc, mobile, metadata = self._extract(
194 video_id, 'getPlaylistByMediaId', 'getMobilePlaylistByMediaId', 'properties')
196 return self._extract_info(
197 pc['playlistItems'][0].get('streams', []),
198 mobile['mediaList'][0].get('mobileUrls', []) if mobile else [],
202 class LimelightChannelIE(LimelightBaseIE):
203 IE_NAME = 'limelight:channel'
204 _VALID_URL = r'''(?x)
209 link\.videoplatform\.limelight\.com/media/|
210 assets\.delvenetworks\.com/player/loader\.swf
217 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
219 'id': 'ab6a524c379342f9b23642917020c082',
220 'title': 'Javascript Sample Code',
222 'playlist_mincount': 3,
224 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
225 'only_matching': True,
227 _PLAYLIST_SERVICE_PATH = 'channel'
228 _API_PATH = 'channels'
230 def _real_extract(self, url):
231 channel_id = self._match_id(url)
233 pc, mobile, medias = self._extract(
234 channel_id, 'getPlaylistByChannelId',
235 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', 'media')
239 pc['playlistItems'][i].get('streams', []),
240 mobile['mediaList'][i].get('mobileUrls', []) if mobile else [],
241 medias['media_list'][i])
242 for i in range(len(medias['media_list']))]
244 return self.playlist_result(entries, channel_id, pc['title'])
247 class LimelightChannelListIE(LimelightBaseIE):
248 IE_NAME = 'limelight:channel_list'
249 _VALID_URL = r'''(?x)
251 limelight:channel_list:|
254 link\.videoplatform\.limelight\.com/media/|
255 assets\.delvenetworks\.com/player/loader\.swf
257 \?.*?\bchannelListId=
262 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
264 'id': '301b117890c4465c8179ede21fd92e2b',
265 'title': 'Website - Hero Player',
267 'playlist_mincount': 2,
269 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
270 'only_matching': True,
272 _PLAYLIST_SERVICE_PATH = 'channel_list'
274 def _real_extract(self, url):
275 channel_list_id = self._match_id(url)
277 channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById')
280 self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
281 for channel in channel_list['channelList']]
283 return self.playlist_result(entries, channel_list_id, channel_list['title'])