]>
Commit | Line | Data |
---|---|---|
f577e0ce PH |
1 | from __future__ import unicode_literals |
2 | ||
d7dda168 PH |
3 | import json |
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
8f93030c | 7 | from ..utils import remove_start |
d7dda168 PH |
8 | |
9 | ||
10 | class BlinkxIE(InfoExtractor): | |
1b969041 | 11 | _VALID_URL = r'^(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)' |
0dc13f4c | 12 | IE_NAME = 'blinkx' |
d7dda168 PH |
13 | |
14 | _TEST = { | |
f577e0ce | 15 | 'url': 'http://www.blinkx.com/ce/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB', |
f577e0ce PH |
16 | 'md5': '2e9a07364af40163a908edbf10bb2492', |
17 | 'info_dict': { | |
8f93030c S |
18 | 'id': '8aQUy7GV', |
19 | 'ext': 'mp4', | |
69f83640 | 20 | 'title': 'Police Car Rolls Away', |
21 | 'uploader': 'stupidvideos.com', | |
22 | 'upload_date': '20131215', | |
23 | 'timestamp': 1387068000, | |
24 | 'description': 'A police car gently rolls away from a fight. Maybe it felt weird being around a confrontation and just had to get out of there!', | |
25 | 'duration': 14.886, | |
26 | 'thumbnails': [{ | |
27 | 'width': 100, | |
28 | 'height': 76, | |
8f93030c | 29 | 'resolution': '100x76', |
69f83640 | 30 | 'url': 'http://cdn.blinkx.com/stream/b/41/StupidVideos/20131215/1873969261/1873969261_tn_0.jpg', |
d7dda168 PH |
31 | }], |
32 | }, | |
33 | } | |
34 | ||
f577e0ce PH |
35 | def _real_extract(self, rl): |
36 | m = re.match(self._VALID_URL, rl) | |
d7dda168 PH |
37 | video_id = m.group('id') |
38 | display_id = video_id[:8] | |
39 | ||
8f93030c | 40 | api_url = ('https://apib4.blinkx.com/api.php?action=play_video&' + |
f577e0ce | 41 | 'video=%s' % video_id) |
d7dda168 PH |
42 | data_json = self._download_webpage(api_url, display_id) |
43 | data = json.loads(data_json)['api']['results'][0] | |
d7dda168 PH |
44 | duration = None |
45 | thumbnails = [] | |
46 | formats = [] | |
47 | for m in data['media']: | |
48 | if m['type'] == 'jpg': | |
49 | thumbnails.append({ | |
50 | 'url': m['link'], | |
51 | 'width': int(m['w']), | |
52 | 'height': int(m['h']), | |
53 | }) | |
54 | elif m['type'] == 'original': | |
8d2cc6fb | 55 | duration = float(m['d']) |
768df745 JMF |
56 | elif m['type'] == 'youtube': |
57 | yt_id = m['link'] | |
8f93030c | 58 | self.to_screen('Youtube video detected: %s' % yt_id) |
768df745 | 59 | return self.url_result(yt_id, 'Youtube', video_id=yt_id) |
d7dda168 PH |
60 | elif m['type'] in ('flv', 'mp4'): |
61 | vcodec = remove_start(m['vcodec'], 'ff') | |
62 | acodec = remove_start(m['acodec'], 'ff') | |
4bc60daf | 63 | tbr = (int(m['vbr']) + int(m['abr'])) // 1000 |
8f93030c | 64 | format_id = '%s-%sk-%s' % (vcodec, tbr, m['w']) |
d7dda168 PH |
65 | formats.append({ |
66 | 'format_id': format_id, | |
67 | 'url': m['link'], | |
68 | 'vcodec': vcodec, | |
69 | 'acodec': acodec, | |
70 | 'abr': int(m['abr']) // 1000, | |
71 | 'vbr': int(m['vbr']) // 1000, | |
4bc60daf | 72 | 'tbr': tbr, |
d7dda168 PH |
73 | 'width': int(m['w']), |
74 | 'height': int(m['h']), | |
75 | }) | |
4bc60daf PH |
76 | |
77 | self._sort_formats(formats) | |
d7dda168 PH |
78 | |
79 | return { | |
80 | 'id': display_id, | |
81 | 'fullid': video_id, | |
82 | 'title': data['title'], | |
83 | 'formats': formats, | |
84 | 'uploader': data['channel_name'], | |
69f83640 | 85 | 'timestamp': data['pubdate_epoch'], |
d7dda168 PH |
86 | 'description': data.get('description'), |
87 | 'thumbnails': thumbnails, | |
88 | 'duration': duration, | |
89 | } |