]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/blinkx.py
[blinkx] Add extractor (Fixes #1972)
[yt-dlp.git] / youtube_dl / extractor / blinkx.py
CommitLineData
d7dda168
PH
1import datetime
2import json
3import re
4
5from .common import InfoExtractor
6from ..utils import (
7 remove_start,
8)
9
10
11class BlinkxIE(InfoExtractor):
12 _VALID_URL = r'^(?:https?://(?:www\.)blinkx\.com/ce/|blinkx:)(?P<id>[^?]+)'
13 _IE_NAME = u'blinkx'
14
15 _TEST = {
16 u'url': u'http://www.blinkx.com/ce/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB',
17 u'file': u'8aQUy7GV.mp4',
18 u'md5': u'2e9a07364af40163a908edbf10bb2492',
19 u'info_dict': {
20 u"title": u"Police Car Rolls Away",
21 u"uploader": u"stupidvideos.com",
22 u"upload_date": u"20131215",
23 u"description": u"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!",
24 u"duration": 14.886,
25 u"thumbnails": [{
26 "width": 100,
27 "height": 76,
28 "url": "http://cdn.blinkx.com/stream/b/41/StupidVideos/20131215/1873969261/1873969261_tn_0.jpg",
29 }],
30 },
31 }
32
33 def _real_extract(self, url):
34 m = re.match(self._VALID_URL, url)
35 video_id = m.group('id')
36 display_id = video_id[:8]
37
38 api_url = (u'https://apib4.blinkx.com/api.php?action=play_video&' +
39 u'video=%s' % video_id)
40 data_json = self._download_webpage(api_url, display_id)
41 data = json.loads(data_json)['api']['results'][0]
42 dt = datetime.datetime.fromtimestamp(data['pubdate_epoch'])
43 upload_date = dt.strftime('%Y%m%d')
44
45 duration = None
46 thumbnails = []
47 formats = []
48 for m in data['media']:
49 if m['type'] == 'jpg':
50 thumbnails.append({
51 'url': m['link'],
52 'width': int(m['w']),
53 'height': int(m['h']),
54 })
55 elif m['type'] == 'original':
56 duration = m['d']
57 elif m['type'] in ('flv', 'mp4'):
58 vcodec = remove_start(m['vcodec'], 'ff')
59 acodec = remove_start(m['acodec'], 'ff')
60 format_id = (u'%s-%sk-%s' %
61 (vcodec,
62 (int(m['vbr']) + int(m['abr'])) // 1000,
63 m['w']))
64 formats.append({
65 'format_id': format_id,
66 'url': m['link'],
67 'vcodec': vcodec,
68 'acodec': acodec,
69 'abr': int(m['abr']) // 1000,
70 'vbr': int(m['vbr']) // 1000,
71 'width': int(m['w']),
72 'height': int(m['h']),
73 })
74 formats.sort(key=lambda f: (f['width'], f['vbr'], f['abr']))
75
76 return {
77 'id': display_id,
78 'fullid': video_id,
79 'title': data['title'],
80 'formats': formats,
81 'uploader': data['channel_name'],
82 'upload_date': upload_date,
83 'description': data.get('description'),
84 'thumbnails': thumbnails,
85 'duration': duration,
86 }