]>
Commit | Line | Data |
---|---|---|
f577e0ce PH |
1 | from __future__ import unicode_literals |
2 | ||
d7dda168 | 3 | import json |
d7dda168 PH |
4 | |
5 | from .common import InfoExtractor | |
dd0a58f5 S |
6 | from ..utils import ( |
7 | remove_start, | |
8 | int_or_none, | |
9 | ) | |
d7dda168 PH |
10 | |
11 | ||
12 | class BlinkxIE(InfoExtractor): | |
dd0a58f5 | 13 | _VALID_URL = r'(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)' |
0dc13f4c | 14 | IE_NAME = 'blinkx' |
d7dda168 PH |
15 | |
16 | _TEST = { | |
dd0a58f5 S |
17 | 'url': 'http://www.blinkx.com/ce/Da0Gw3xc5ucpNduzLuDDlv4WC9PuI4fDi1-t6Y3LyfdY2SZS5Urbvn-UPJvrvbo8LTKTc67Wu2rPKSQDJyZeeORCR8bYkhs8lI7eqddznH2ofh5WEEdjYXnoRtj7ByQwt7atMErmXIeYKPsSDuMAAqJDlQZ-3Ff4HJVeH_s3Gh8oQ', |
18 | 'md5': '337cf7a344663ec79bf93a526a2e06c7', | |
f577e0ce | 19 | 'info_dict': { |
dd0a58f5 | 20 | 'id': 'Da0Gw3xc', |
8f93030c | 21 | 'ext': 'mp4', |
dd0a58f5 S |
22 | 'title': 'No Daily Show for John Oliver; HBO Show Renewed - IGN News', |
23 | 'uploader': 'IGN News', | |
24 | 'upload_date': '20150217', | |
25 | 'timestamp': 1424215740, | |
26 | 'description': 'HBO has renewed Last Week Tonight With John Oliver for two more seasons.', | |
27 | 'duration': 47.743333, | |
d7dda168 PH |
28 | }, |
29 | } | |
30 | ||
dd0a58f5 S |
31 | def _real_extract(self, url): |
32 | video_id = self._match_id(url) | |
d7dda168 PH |
33 | display_id = video_id[:8] |
34 | ||
3089bc74 S |
35 | api_url = ('https://apib4.blinkx.com/api.php?action=play_video&' |
36 | + 'video=%s' % video_id) | |
d7dda168 PH |
37 | data_json = self._download_webpage(api_url, display_id) |
38 | data = json.loads(data_json)['api']['results'][0] | |
d7dda168 PH |
39 | duration = None |
40 | thumbnails = [] | |
41 | formats = [] | |
42 | for m in data['media']: | |
43 | if m['type'] == 'jpg': | |
44 | thumbnails.append({ | |
45 | 'url': m['link'], | |
46 | 'width': int(m['w']), | |
47 | 'height': int(m['h']), | |
48 | }) | |
49 | elif m['type'] == 'original': | |
8d2cc6fb | 50 | duration = float(m['d']) |
768df745 JMF |
51 | elif m['type'] == 'youtube': |
52 | yt_id = m['link'] | |
8f93030c | 53 | self.to_screen('Youtube video detected: %s' % yt_id) |
768df745 | 54 | return self.url_result(yt_id, 'Youtube', video_id=yt_id) |
d7dda168 PH |
55 | elif m['type'] in ('flv', 'mp4'): |
56 | vcodec = remove_start(m['vcodec'], 'ff') | |
57 | acodec = remove_start(m['acodec'], 'ff') | |
dd0a58f5 S |
58 | vbr = int_or_none(m.get('vbr') or m.get('vbitrate'), 1000) |
59 | abr = int_or_none(m.get('abr') or m.get('abitrate'), 1000) | |
60 | tbr = vbr + abr if vbr and abr else None | |
8f93030c | 61 | format_id = '%s-%sk-%s' % (vcodec, tbr, m['w']) |
d7dda168 PH |
62 | formats.append({ |
63 | 'format_id': format_id, | |
64 | 'url': m['link'], | |
65 | 'vcodec': vcodec, | |
66 | 'acodec': acodec, | |
dd0a58f5 S |
67 | 'abr': abr, |
68 | 'vbr': vbr, | |
4bc60daf | 69 | 'tbr': tbr, |
dd0a58f5 S |
70 | 'width': int_or_none(m.get('w')), |
71 | 'height': int_or_none(m.get('h')), | |
d7dda168 | 72 | }) |
4bc60daf PH |
73 | |
74 | self._sort_formats(formats) | |
d7dda168 PH |
75 | |
76 | return { | |
77 | 'id': display_id, | |
78 | 'fullid': video_id, | |
79 | 'title': data['title'], | |
80 | 'formats': formats, | |
06425e96 | 81 | 'uploader': data.get('channel_name'), |
82 | 'timestamp': data.get('pubdate_epoch'), | |
d7dda168 PH |
83 | 'description': data.get('description'), |
84 | 'thumbnails': thumbnails, | |
85 | 'duration': duration, | |
86 | } |