]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/limelight.py
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') or stream_url
in urls
:
42 urls
.append(stream_url
)
43 ext
= determine_ext(stream_url
)
45 formats
.extend(self
._extract
_f
4m
_formats
(
46 stream_url
, video_id
, f4m_id
='hds', fatal
=False))
50 'abr': float_or_none(stream
.get('audioBitRate')),
51 'vbr': float_or_none(stream
.get('videoBitRate')),
52 'fps': float_or_none(stream
.get('videoFrameRate')),
53 'width': int_or_none(stream
.get('videoWidthInPixels')),
54 'height': int_or_none(stream
.get('videoHeightInPixels')),
57 rtmp
= re
.search(r
'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp4:.+)$', stream_url
)
60 if stream
.get('videoBitRate'):
61 format_id
+= '-%d' % int_or_none(stream
['videoBitRate'])
62 http_format_id
= format_id
.replace('rtmp', 'http')
65 ('delvenetworks.com', 'cpl.delvenetworks.com'),
66 ('video.llnw.net', 's2.content.video.llnw.net'),
68 for cdn_host
, http_host
in CDN_HOSTS
:
69 if cdn_host
not in rtmp
.group('host').lower():
71 http_url
= 'http://%s/%s' % (http_host
, rtmp
.group('playpath')[4:])
73 if self
._is
_valid
_url
(http_url
, video_id
, http_format_id
):
77 'format_id': http_format_id
,
79 formats
.append(http_fmt
)
83 'url': rtmp
.group('url'),
84 'play_path': rtmp
.group('playpath'),
85 'app': rtmp
.group('app'),
87 'format_id': format_id
,
91 for mobile_url
in mobile_urls
:
92 media_url
= mobile_url
.get('mobileUrl')
93 format_id
= mobile_url
.get('targetMediaPlatform')
94 if not media_url
or format_id
in ('Widevine', 'SmoothStreaming') or media_url
in urls
:
96 urls
.append(media_url
)
97 ext
= determine_ext(media_url
)
99 formats
.extend(self
._extract
_m
3u8_formats
(
100 media_url
, video_id
, 'mp4', 'm3u8_native',
101 m3u8_id
=format_id
, fatal
=False))
103 formats
.extend(self
._extract
_f
4m
_formats
(
104 stream_url
, video_id
, f4m_id
=format_id
, fatal
=False))
108 'format_id': format_id
,
113 self
._sort
_formats
(formats
)
115 title
= properties
['title']
116 description
= properties
.get('description')
117 timestamp
= int_or_none(properties
.get('publish_date') or properties
.get('create_date'))
118 duration
= float_or_none(properties
.get('duration_in_milliseconds'), 1000)
119 filesize
= int_or_none(properties
.get('total_storage_in_bytes'))
120 categories
= [properties
.get('category')]
121 tags
= properties
.get('tags', [])
123 'url': thumbnail
['url'],
124 'width': int_or_none(thumbnail
.get('width')),
125 'height': int_or_none(thumbnail
.get('height')),
126 } for thumbnail
in properties
.get('thumbnails', []) if thumbnail
.get('url')]
129 for caption
in properties
.get('captions', []):
130 lang
= caption
.get('language_code')
131 subtitles_url
= caption
.get('url')
132 if lang
and subtitles_url
:
133 subtitles
.setdefault(lang
, []).append({
134 'url': subtitles_url
,
136 closed_captions_url
= properties
.get('closed_captions_url')
137 if closed_captions_url
:
138 subtitles
.setdefault('en', []).append({
139 'url': closed_captions_url
,
146 'description': description
,
148 'timestamp': timestamp
,
149 'duration': duration
,
150 'filesize': filesize
,
151 'categories': categories
,
153 'thumbnails': thumbnails
,
154 'subtitles': subtitles
,
158 class LimelightMediaIE(LimelightBaseIE
):
159 IE_NAME
= 'limelight'
160 _VALID_URL
= r
'''(?x)
165 link\.videoplatform\.limelight\.com/media/|
166 assets\.delvenetworks\.com/player/loader\.swf
173 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
175 'id': '3ffd040b522b4485b6d84effc750cd86',
177 'title': 'HaP and the HB Prince Trailer',
178 'description': 'md5:8005b944181778e313d95c1237ddb640',
179 'thumbnail': r
're:^https?://.*\.jpeg$',
181 'timestamp': 1244136834,
182 'upload_date': '20090604',
186 'skip_download': True,
189 # video with subtitles
190 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
191 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
193 'id': 'a3e00274d4564ec4a9b29b9466432335',
195 'title': '3Play Media Overview Video',
196 'thumbnail': r
're:^https?://.*\.jpeg$',
198 'timestamp': 1338929955,
199 'upload_date': '20120605',
200 'subtitles': 'mincount:9',
203 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
204 'only_matching': True,
206 _PLAYLIST_SERVICE_PATH
= 'media'
209 def _real_extract(self
, url
):
210 video_id
= self
._match
_id
(url
)
212 pc
, mobile
, metadata
= self
._extract
(
213 video_id
, 'getPlaylistByMediaId', 'getMobilePlaylistByMediaId', 'properties')
215 return self
._extract
_info
(
216 pc
['playlistItems'][0].get('streams', []),
217 mobile
['mediaList'][0].get('mobileUrls', []) if mobile
else [],
221 class LimelightChannelIE(LimelightBaseIE
):
222 IE_NAME
= 'limelight:channel'
223 _VALID_URL
= r
'''(?x)
228 link\.videoplatform\.limelight\.com/media/|
229 assets\.delvenetworks\.com/player/loader\.swf
236 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
238 'id': 'ab6a524c379342f9b23642917020c082',
239 'title': 'Javascript Sample Code',
241 'playlist_mincount': 3,
243 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
244 'only_matching': True,
246 _PLAYLIST_SERVICE_PATH
= 'channel'
247 _API_PATH
= 'channels'
249 def _real_extract(self
, url
):
250 channel_id
= self
._match
_id
(url
)
252 pc
, mobile
, medias
= self
._extract
(
253 channel_id
, 'getPlaylistByChannelId',
254 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', 'media')
258 pc
['playlistItems'][i
].get('streams', []),
259 mobile
['mediaList'][i
].get('mobileUrls', []) if mobile
else [],
260 medias
['media_list'][i
])
261 for i
in range(len(medias
['media_list']))]
263 return self
.playlist_result(entries
, channel_id
, pc
['title'])
266 class LimelightChannelListIE(LimelightBaseIE
):
267 IE_NAME
= 'limelight:channel_list'
268 _VALID_URL
= r
'''(?x)
270 limelight:channel_list:|
273 link\.videoplatform\.limelight\.com/media/|
274 assets\.delvenetworks\.com/player/loader\.swf
276 \?.*?\bchannelListId=
281 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
283 'id': '301b117890c4465c8179ede21fd92e2b',
284 'title': 'Website - Hero Player',
286 'playlist_mincount': 2,
288 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
289 'only_matching': True,
291 _PLAYLIST_SERVICE_PATH
= 'channel_list'
293 def _real_extract(self
, url
):
294 channel_list_id
= self
._match
_id
(url
)
296 channel_list
= self
._call
_playlist
_service
(channel_list_id
, 'getMobileChannelListById')
299 self
.url_result('limelight:channel:%s' % channel
['id'], 'LimelightChannel')
300 for channel
in channel_list
['channelList']]
302 return self
.playlist_result(entries
, channel_list_id
, channel_list
['title'])