]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/blinkx.py
switch more to unicode_literals
[yt-dlp.git] / youtube_dl / extractor / blinkx.py
CommitLineData
f577e0ce
PH
1from __future__ import unicode_literals
2
d7dda168
PH
3import datetime
4import json
5import re
6
7from .common import InfoExtractor
8from ..utils import (
9 remove_start,
10)
11
12
13class BlinkxIE(InfoExtractor):
1b969041 14 _VALID_URL = r'^(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)'
f577e0ce 15 _IE_NAME = 'blinkx'
d7dda168
PH
16
17 _TEST = {
f577e0ce
PH
18 'url': 'http://www.blinkx.com/ce/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB',
19 'file': '8aQUy7GV.mp4',
20 'md5': '2e9a07364af40163a908edbf10bb2492',
21 'info_dict': {
22 "title": "Police Car Rolls Away",
23 "uploader": "stupidvideos.com",
24 "upload_date": "20131215",
25 "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!",
26 "duration": 14.886,
27 "thumbnails": [{
d7dda168
PH
28 "width": 100,
29 "height": 76,
30 "url": "http://cdn.blinkx.com/stream/b/41/StupidVideos/20131215/1873969261/1873969261_tn_0.jpg",
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
40 api_url = (u'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]
44 dt = datetime.datetime.fromtimestamp(data['pubdate_epoch'])
f577e0ce 45 pload_date = dt.strftime('%Y%m%d')
d7dda168
PH
46
47 duration = None
48 thumbnails = []
49 formats = []
50 for m in data['media']:
51 if m['type'] == 'jpg':
52 thumbnails.append({
53 'url': m['link'],
54 'width': int(m['w']),
55 'height': int(m['h']),
56 })
57 elif m['type'] == 'original':
58 duration = m['d']
768df745
JMF
59 elif m['type'] == 'youtube':
60 yt_id = m['link']
61 self.to_screen(u'Youtube video detected: %s' % yt_id)
62 return self.url_result(yt_id, 'Youtube', video_id=yt_id)
d7dda168
PH
63 elif m['type'] in ('flv', 'mp4'):
64 vcodec = remove_start(m['vcodec'], 'ff')
65 acodec = remove_start(m['acodec'], 'ff')
4bc60daf 66 tbr = (int(m['vbr']) + int(m['abr'])) // 1000
d7dda168
PH
67 format_id = (u'%s-%sk-%s' %
68 (vcodec,
4bc60daf 69 tbr,
d7dda168
PH
70 m['w']))
71 formats.append({
72 'format_id': format_id,
73 'url': m['link'],
74 'vcodec': vcodec,
75 'acodec': acodec,
76 'abr': int(m['abr']) // 1000,
77 'vbr': int(m['vbr']) // 1000,
4bc60daf 78 'tbr': tbr,
d7dda168
PH
79 'width': int(m['w']),
80 'height': int(m['h']),
81 })
4bc60daf
PH
82
83 self._sort_formats(formats)
d7dda168
PH
84
85 return {
86 'id': display_id,
87 'fullid': video_id,
88 'title': data['title'],
89 'formats': formats,
90 'uploader': data['channel_name'],
f577e0ce 91 'upload_date': pload_date,
d7dda168
PH
92 'description': data.get('description'),
93 'thumbnails': thumbnails,
94 'duration': duration,
95 }