]>
Commit | Line | Data |
---|---|---|
ef5acfe3 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
ef5acfe3 | 8 | determine_ext, |
d7fc5631 S |
9 | float_or_none, |
10 | int_or_none, | |
ef5acfe3 | 11 | ) |
12 | ||
13 | ||
d7fc5631 S |
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' | |
ef5acfe3 | 17 | |
d7fc5631 S |
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) | |
ef5acfe3 | 22 | |
d7fc5631 S |
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) | |
ef5acfe3 | 27 | |
d7fc5631 S |
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 | |
33 | ||
34 | def _extract_info(self, streams, mobile_urls, properties): | |
ef5acfe3 | 35 | video_id = properties['media_id'] |
36 | formats = [] | |
37 | ||
ef5acfe3 | 38 | for stream in streams: |
d7fc5631 S |
39 | stream_url = stream.get('url') |
40 | if not stream_url: | |
41 | continue | |
42 | if '.f4m' in stream_url: | |
43 | formats.extend(self._extract_f4m_formats(stream_url, video_id)) | |
ef5acfe3 | 44 | else: |
45 | fmt = { | |
d7fc5631 S |
46 | 'url': stream_url, |
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) | |
ef5acfe3 | 53 | } |
d7fc5631 | 54 | rtmp = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', stream_url) |
ef5acfe3 | 55 | if rtmp: |
d7fc5631 S |
56 | format_id = 'rtmp' |
57 | if stream.get('videoBitRate'): | |
58 | format_id += '-%d' % int_or_none(stream['videoBitRate']) | |
ef5acfe3 | 59 | fmt.update({ |
60 | 'url': rtmp.group('url'), | |
61 | 'play_path': rtmp.group('playpath'), | |
62 | 'app': rtmp.group('app'), | |
d7fc5631 S |
63 | 'ext': 'flv', |
64 | 'format_id': format_id, | |
ef5acfe3 | 65 | }) |
66 | formats.append(fmt) | |
67 | ||
d7fc5631 S |
68 | for mobile_url in mobile_urls: |
69 | media_url = mobile_url.get('mobileUrl') | |
70 | if not media_url: | |
71 | continue | |
72 | format_id = mobile_url.get('targetMediaPlatform') | |
73 | if determine_ext(media_url) == 'm3u8': | |
74 | formats.extend(self._extract_m3u8_formats( | |
75 | media_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
76 | preference=-1, m3u8_id=format_id)) | |
77 | else: | |
78 | formats.append({ | |
79 | 'url': media_url, | |
80 | 'format_id': format_id, | |
81 | 'preference': -1, | |
82 | }) | |
83 | ||
ef5acfe3 | 84 | self._sort_formats(formats) |
85 | ||
86 | title = properties['title'] | |
87 | description = properties.get('description') | |
d7fc5631 S |
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')) | |
ef5acfe3 | 91 | categories = [properties.get('category')] |
d7fc5631 | 92 | tags = properties.get('tags', []) |
ef5acfe3 | 93 | thumbnails = [{ |
d7fc5631 | 94 | 'url': thumbnail['url'], |
ef5acfe3 | 95 | 'width': int_or_none(thumbnail.get('width')), |
96 | 'height': int_or_none(thumbnail.get('height')), | |
d7fc5631 S |
97 | } for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')] |
98 | ||
99 | subtitles = {} | |
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: | |
104 | subtitles[lang] = [{ | |
105 | 'url': subtitles_url, | |
106 | }] | |
ef5acfe3 | 107 | |
108 | return { | |
109 | 'id': video_id, | |
110 | 'title': title, | |
111 | 'description': description, | |
112 | 'formats': formats, | |
113 | 'timestamp': timestamp, | |
114 | 'duration': duration, | |
115 | 'filesize': filesize, | |
116 | 'categories': categories, | |
d7fc5631 | 117 | 'tags': tags, |
ef5acfe3 | 118 | 'thumbnails': thumbnails, |
119 | 'subtitles': subtitles, | |
120 | } | |
121 | ||
122 | ||
d7fc5631 | 123 | class LimelightMediaIE(LimelightBaseIE): |
ef5acfe3 | 124 | IE_NAME = 'limelight' |
d7fc5631 | 125 | _VALID_URL = r'(?:limelight:media:|http://link\.videoplatform\.limelight\.com/media/\??\bmediaId=)(?P<id>[a-z0-9]{32})' |
9c544e25 | 126 | _TESTS = [{ |
ef5acfe3 | 127 | 'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86', |
ef5acfe3 | 128 | 'info_dict': { |
129 | 'id': '3ffd040b522b4485b6d84effc750cd86', | |
d7fc5631 | 130 | 'ext': 'flv', |
ef5acfe3 | 131 | 'title': 'HaP and the HB Prince Trailer', |
9c544e25 | 132 | 'description': 'md5:8005b944181778e313d95c1237ddb640', |
ef5acfe3 | 133 | 'thumbnail': 're:^https?://.*\.jpeg$', |
d7fc5631 | 134 | 'duration': 144.23, |
ef5acfe3 | 135 | 'timestamp': 1244136834, |
d7fc5631 S |
136 | 'upload_date': '20090604', |
137 | }, | |
138 | 'params': { | |
139 | # rtmp download | |
140 | 'skip_download': True, | |
141 | }, | |
9c544e25 S |
142 | }, { |
143 | # video with subtitles | |
144 | 'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335', | |
145 | 'info_dict': { | |
146 | 'id': 'a3e00274d4564ec4a9b29b9466432335', | |
147 | 'ext': 'flv', | |
148 | 'title': '3Play Media Overview Video', | |
149 | 'description': '', | |
150 | 'thumbnail': 're:^https?://.*\.jpeg$', | |
151 | 'duration': 78.101, | |
152 | 'timestamp': 1338929955, | |
153 | 'upload_date': '20120605', | |
154 | 'subtitles': 'mincount:9', | |
155 | }, | |
156 | 'params': { | |
157 | # rtmp download | |
158 | 'skip_download': True, | |
159 | }, | |
160 | }] | |
d7fc5631 S |
161 | _PLAYLIST_SERVICE_PATH = 'media' |
162 | _API_PATH = 'media' | |
ef5acfe3 | 163 | |
164 | def _real_extract(self, url): | |
165 | video_id = self._match_id(url) | |
166 | ||
d7fc5631 S |
167 | pc, mobile, metadata = self._extract( |
168 | video_id, 'getPlaylistByMediaId', 'getMobilePlaylistByMediaId', 'properties') | |
ef5acfe3 | 169 | |
d7fc5631 S |
170 | return self._extract_info( |
171 | pc['playlistItems'][0].get('streams', []), | |
172 | mobile['mediaList'][0].get('mobileUrls', []) if mobile else [], | |
173 | metadata) | |
ef5acfe3 | 174 | |
175 | ||
d7fc5631 | 176 | class LimelightChannelIE(LimelightBaseIE): |
ef5acfe3 | 177 | IE_NAME = 'limelight:channel' |
d7fc5631 | 178 | _VALID_URL = r'(?:limelight:channel:|http://link\.videoplatform\.limelight\.com/media/\??\bchannelId=)(?P<id>[a-z0-9]{32})' |
ef5acfe3 | 179 | _TEST = { |
180 | 'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082', | |
181 | 'info_dict': { | |
182 | 'id': 'ab6a524c379342f9b23642917020c082', | |
183 | 'title': 'Javascript Sample Code', | |
184 | }, | |
185 | 'playlist_mincount': 3, | |
186 | } | |
d7fc5631 S |
187 | _PLAYLIST_SERVICE_PATH = 'channel' |
188 | _API_PATH = 'channels' | |
ef5acfe3 | 189 | |
190 | def _real_extract(self, url): | |
191 | channel_id = self._match_id(url) | |
192 | ||
d7fc5631 S |
193 | pc, mobile, medias = self._extract( |
194 | channel_id, 'getPlaylistByChannelId', | |
195 | 'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', 'media') | |
ef5acfe3 | 196 | |
d7fc5631 S |
197 | entries = [ |
198 | self._extract_info( | |
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']))] | |
ef5acfe3 | 203 | |
d7fc5631 | 204 | return self.playlist_result(entries, channel_id, pc['title']) |
ef5acfe3 | 205 | |
206 | ||
d7fc5631 | 207 | class LimelightChannelListIE(LimelightBaseIE): |
ef5acfe3 | 208 | IE_NAME = 'limelight:channel_list' |
d7fc5631 | 209 | _VALID_URL = r'(?:limelight:channel_list:|http://link\.videoplatform\.limelight\.com/media/\?.*?\bchannelListId=)(?P<id>[a-z0-9]{32})' |
ef5acfe3 | 210 | _TEST = { |
211 | 'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b', | |
212 | 'info_dict': { | |
213 | 'id': '301b117890c4465c8179ede21fd92e2b', | |
214 | 'title': 'Website - Hero Player', | |
215 | }, | |
216 | 'playlist_mincount': 2, | |
217 | } | |
d7fc5631 | 218 | _PLAYLIST_SERVICE_PATH = 'channel_list' |
ef5acfe3 | 219 | |
220 | def _real_extract(self, url): | |
221 | channel_list_id = self._match_id(url) | |
222 | ||
d7fc5631 | 223 | channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById') |
ef5acfe3 | 224 | |
d7fc5631 S |
225 | entries = [ |
226 | self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel') | |
227 | for channel in channel_list['channelList']] | |
ef5acfe3 | 228 | |
d7fc5631 | 229 | return self.playlist_result(entries, channel_list_id, channel_list['title']) |