]>
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_url
= 'http://cpl.delvenetworks.com/' + rtmp
.group('playpath')[4:]
67 'format_id': format_id
.replace('rtmp', 'http'),
69 formats
.append(http_fmt
)
71 'url': rtmp
.group('url'),
72 'play_path': rtmp
.group('playpath'),
73 'app': rtmp
.group('app'),
75 'format_id': format_id
,
79 for mobile_url
in mobile_urls
:
80 media_url
= mobile_url
.get('mobileUrl')
81 format_id
= mobile_url
.get('targetMediaPlatform')
82 if not media_url
or format_id
in ('Widevine', 'SmoothStreaming') or media_url
in urls
:
84 urls
.append(media_url
)
85 ext
= determine_ext(media_url
)
87 formats
.extend(self
._extract
_m
3u8_formats
(
88 media_url
, video_id
, 'mp4', 'm3u8_native',
89 m3u8_id
=format_id
, fatal
=False))
91 formats
.extend(self
._extract
_f
4m
_formats
(
92 stream_url
, video_id
, f4m_id
=format_id
, fatal
=False))
96 'format_id': format_id
,
101 self
._sort
_formats
(formats
)
103 title
= properties
['title']
104 description
= properties
.get('description')
105 timestamp
= int_or_none(properties
.get('publish_date') or properties
.get('create_date'))
106 duration
= float_or_none(properties
.get('duration_in_milliseconds'), 1000)
107 filesize
= int_or_none(properties
.get('total_storage_in_bytes'))
108 categories
= [properties
.get('category')]
109 tags
= properties
.get('tags', [])
111 'url': thumbnail
['url'],
112 'width': int_or_none(thumbnail
.get('width')),
113 'height': int_or_none(thumbnail
.get('height')),
114 } for thumbnail
in properties
.get('thumbnails', []) if thumbnail
.get('url')]
117 for caption
in properties
.get('captions', []):
118 lang
= caption
.get('language_code')
119 subtitles_url
= caption
.get('url')
120 if lang
and subtitles_url
:
121 subtitles
.setdefault(lang
, []).append({
122 'url': subtitles_url
,
124 closed_captions_url
= properties
.get('closed_captions_url')
125 if closed_captions_url
:
126 subtitles
.setdefault('en', []).append({
127 'url': closed_captions_url
,
134 'description': description
,
136 'timestamp': timestamp
,
137 'duration': duration
,
138 'filesize': filesize
,
139 'categories': categories
,
141 'thumbnails': thumbnails
,
142 'subtitles': subtitles
,
146 class LimelightMediaIE(LimelightBaseIE
):
147 IE_NAME
= 'limelight'
148 _VALID_URL
= r
'''(?x)
153 link\.videoplatform\.limelight\.com/media/|
154 assets\.delvenetworks\.com/player/loader\.swf
161 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
163 'id': '3ffd040b522b4485b6d84effc750cd86',
165 'title': 'HaP and the HB Prince Trailer',
166 'description': 'md5:8005b944181778e313d95c1237ddb640',
167 'thumbnail': 're:^https?://.*\.jpeg$',
169 'timestamp': 1244136834,
170 'upload_date': '20090604',
174 'skip_download': True,
177 # video with subtitles
178 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
179 'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
181 'id': 'a3e00274d4564ec4a9b29b9466432335',
183 'title': '3Play Media Overview Video',
184 'thumbnail': 're:^https?://.*\.jpeg$',
186 'timestamp': 1338929955,
187 'upload_date': '20120605',
188 'subtitles': 'mincount:9',
191 'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
192 'only_matching': True,
194 _PLAYLIST_SERVICE_PATH
= 'media'
197 def _real_extract(self
, url
):
198 video_id
= self
._match
_id
(url
)
200 pc
, mobile
, metadata
= self
._extract
(
201 video_id
, 'getPlaylistByMediaId', 'getMobilePlaylistByMediaId', 'properties')
203 return self
._extract
_info
(
204 pc
['playlistItems'][0].get('streams', []),
205 mobile
['mediaList'][0].get('mobileUrls', []) if mobile
else [],
209 class LimelightChannelIE(LimelightBaseIE
):
210 IE_NAME
= 'limelight:channel'
211 _VALID_URL
= r
'''(?x)
216 link\.videoplatform\.limelight\.com/media/|
217 assets\.delvenetworks\.com/player/loader\.swf
224 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
226 'id': 'ab6a524c379342f9b23642917020c082',
227 'title': 'Javascript Sample Code',
229 'playlist_mincount': 3,
231 'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
232 'only_matching': True,
234 _PLAYLIST_SERVICE_PATH
= 'channel'
235 _API_PATH
= 'channels'
237 def _real_extract(self
, url
):
238 channel_id
= self
._match
_id
(url
)
240 pc
, mobile
, medias
= self
._extract
(
241 channel_id
, 'getPlaylistByChannelId',
242 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', 'media')
246 pc
['playlistItems'][i
].get('streams', []),
247 mobile
['mediaList'][i
].get('mobileUrls', []) if mobile
else [],
248 medias
['media_list'][i
])
249 for i
in range(len(medias
['media_list']))]
251 return self
.playlist_result(entries
, channel_id
, pc
['title'])
254 class LimelightChannelListIE(LimelightBaseIE
):
255 IE_NAME
= 'limelight:channel_list'
256 _VALID_URL
= r
'''(?x)
258 limelight:channel_list:|
261 link\.videoplatform\.limelight\.com/media/|
262 assets\.delvenetworks\.com/player/loader\.swf
264 \?.*?\bchannelListId=
269 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
271 'id': '301b117890c4465c8179ede21fd92e2b',
272 'title': 'Website - Hero Player',
274 'playlist_mincount': 2,
276 'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
277 'only_matching': True,
279 _PLAYLIST_SERVICE_PATH
= 'channel_list'
281 def _real_extract(self
, url
):
282 channel_list_id
= self
._match
_id
(url
)
284 channel_list
= self
._call
_playlist
_service
(channel_list_id
, 'getMobileChannelListById')
287 self
.url_result('limelight:channel:%s' % channel
['id'], 'LimelightChannel')
288 for channel
in channel_list
['channelList']]
290 return self
.playlist_result(entries
, channel_list_id
, channel_list
['title'])