]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/limelight.py
fb03dd52782e70d91021d7d520e99bd7dba60bd8
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')
42 if '.f4m' in stream_url
:
43 formats
.extend(self
._extract
_f
4m
_formats
(stream_url
, video_id
))
47 'abr': float_or_none(stream
.get('audioBitRate')),
48 'vbr': float_or_none(stream
.get('videoBitRate')),
49 'fps': float_or_none(stream
.get('videoFrameRate')),
50 'width': int_or_none(stream
.get('videoWidthInPixels')),
51 'height': int_or_none(stream
.get('videoHeightInPixels')),
52 'ext': determine_ext(stream_url
)
54 rtmp
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', stream_url
)
57 if stream
.get('videoBitRate'):
58 format_id
+= '-%d' % int_or_none(stream
['videoBitRate'])
60 'url': rtmp
.group('url'),
61 'play_path': rtmp
.group('playpath'),
62 'app': rtmp
.group('app'),
64 'format_id': format_id
,
68 for mobile_url
in mobile_urls
:
69 media_url
= mobile_url
.get('mobileUrl')
72 format_id
= mobile_url
.get('targetMediaPlatform')
73 if determine_ext(media_url
) == 'm3u8':
74 formats
.extend(self
._extract
_m
3u8_formats
(
75 media_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
76 preference
=-1, m3u8_id
=format_id
))
80 'format_id': format_id
,
84 self
._sort
_formats
(formats
)
86 title
= properties
['title']
87 description
= properties
.get('description')
88 timestamp
= int_or_none(properties
.get('publish_date') or properties
.get('create_date'))
89 duration
= float_or_none(properties
.get('duration_in_milliseconds'), 1000)
90 filesize
= int_or_none(properties
.get('total_storage_in_bytes'))
91 categories
= [properties
.get('category')]
92 tags
= properties
.get('tags', [])
94 'url': thumbnail
['url'],
95 'width': int_or_none(thumbnail
.get('width')),
96 'height': int_or_none(thumbnail
.get('height')),
97 } for thumbnail
in properties
.get('thumbnails', []) if thumbnail
.get('url')]
100 for caption
in properties
.get('captions', {}):
101 lang
= caption
.get('language_code')
102 subtitles_url
= caption
.get('url')
103 if lang
and subtitles_url
:
105 'url': subtitles_url
,
111 'description': description
,
113 'timestamp': timestamp
,
114 'duration': duration
,
115 'filesize': filesize
,
116 'categories': categories
,
118 'thumbnails': thumbnails
,
119 'subtitles': subtitles
,
123 class LimelightMediaIE(LimelightBaseIE
):
124 IE_NAME
= 'limelight'
125 _VALID_URL
= r
'(?:limelight:media:|http://link\.videoplatform\.limelight\.com/media/\??\bmediaId=)(?P<id>[a-z0-9]{32})'
127 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
129 'id': '3ffd040b522b4485b6d84effc750cd86',
131 'title': 'HaP and the HB Prince Trailer',
132 'description': 'md5:8005b944181778e313d95c1237ddb640',
133 'thumbnail': 're:^https?://.*\.jpeg$',
135 'timestamp': 1244136834,
136 'upload_date': '20090604',
140 'skip_download': True,
143 # video with subtitles
144 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
146 'id': 'a3e00274d4564ec4a9b29b9466432335',
148 'title': '3Play Media Overview Video',
150 'thumbnail': 're:^https?://.*\.jpeg$',
152 'timestamp': 1338929955,
153 'upload_date': '20120605',
154 'subtitles': 'mincount:9',
158 'skip_download': True,
161 _PLAYLIST_SERVICE_PATH
= 'media'
164 def _real_extract(self
, url
):
165 video_id
= self
._match
_id
(url
)
167 pc
, mobile
, metadata
= self
._extract
(
168 video_id
, 'getPlaylistByMediaId', 'getMobilePlaylistByMediaId', 'properties')
170 return self
._extract
_info
(
171 pc
['playlistItems'][0].get('streams', []),
172 mobile
['mediaList'][0].get('mobileUrls', []) if mobile
else [],
176 class LimelightChannelIE(LimelightBaseIE
):
177 IE_NAME
= 'limelight:channel'
178 _VALID_URL
= r
'(?:limelight:channel:|http://link\.videoplatform\.limelight\.com/media/\??\bchannelId=)(?P<id>[a-z0-9]{32})'
180 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
182 'id': 'ab6a524c379342f9b23642917020c082',
183 'title': 'Javascript Sample Code',
185 'playlist_mincount': 3,
187 _PLAYLIST_SERVICE_PATH
= 'channel'
188 _API_PATH
= 'channels'
190 def _real_extract(self
, url
):
191 channel_id
= self
._match
_id
(url
)
193 pc
, mobile
, medias
= self
._extract
(
194 channel_id
, 'getPlaylistByChannelId',
195 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', 'media')
199 pc
['playlistItems'][i
].get('streams', []),
200 mobile
['mediaList'][i
].get('mobileUrls', []) if mobile
else [],
201 medias
['media_list'][i
])
202 for i
in range(len(medias
['media_list']))]
204 return self
.playlist_result(entries
, channel_id
, pc
['title'])
207 class LimelightChannelListIE(LimelightBaseIE
):
208 IE_NAME
= 'limelight:channel_list'
209 _VALID_URL
= r
'(?:limelight:channel_list:|http://link\.videoplatform\.limelight\.com/media/\?.*?\bchannelListId=)(?P<id>[a-z0-9]{32})'
211 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
213 'id': '301b117890c4465c8179ede21fd92e2b',
214 'title': 'Website - Hero Player',
216 'playlist_mincount': 2,
218 _PLAYLIST_SERVICE_PATH
= 'channel_list'
220 def _real_extract(self
, url
):
221 channel_list_id
= self
._match
_id
(url
)
223 channel_list
= self
._call
_playlist
_service
(channel_list_id
, 'getMobileChannelListById')
226 self
.url_result('limelight:channel:%s' % channel
['id'], 'LimelightChannel')
227 for channel
in channel_list
['channelList']]
229 return self
.playlist_result(entries
, channel_list_id
, channel_list
['title'])