1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-12-24 07:43:03 +08:00
youtube-dl/youtube_dl/extractor/blinkx.py

87 lines
3.1 KiB
Python
Raw Normal View History

2014-01-07 16:45:40 +08:00
from __future__ import unicode_literals
2013-12-16 20:56:13 +08:00
import json
from .common import InfoExtractor
2015-02-20 03:19:38 +08:00
from ..utils import (
remove_start,
int_or_none,
)
2013-12-16 20:56:13 +08:00
class BlinkxIE(InfoExtractor):
2015-02-20 03:19:38 +08:00
_VALID_URL = r'(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)'
2014-01-07 16:45:58 +08:00
IE_NAME = 'blinkx'
2013-12-16 20:56:13 +08:00
_TEST = {
2015-02-20 03:19:38 +08:00
'url': 'http://www.blinkx.com/ce/Da0Gw3xc5ucpNduzLuDDlv4WC9PuI4fDi1-t6Y3LyfdY2SZS5Urbvn-UPJvrvbo8LTKTc67Wu2rPKSQDJyZeeORCR8bYkhs8lI7eqddznH2ofh5WEEdjYXnoRtj7ByQwt7atMErmXIeYKPsSDuMAAqJDlQZ-3Ff4HJVeH_s3Gh8oQ',
'md5': '337cf7a344663ec79bf93a526a2e06c7',
2014-01-07 16:45:40 +08:00
'info_dict': {
2015-02-20 03:19:38 +08:00
'id': 'Da0Gw3xc',
2014-06-11 19:38:13 +08:00
'ext': 'mp4',
2015-02-20 03:19:38 +08:00
'title': 'No Daily Show for John Oliver; HBO Show Renewed - IGN News',
'uploader': 'IGN News',
'upload_date': '20150217',
'timestamp': 1424215740,
'description': 'HBO has renewed Last Week Tonight With John Oliver for two more seasons.',
'duration': 47.743333,
2013-12-16 20:56:13 +08:00
},
}
2015-02-20 03:19:38 +08:00
def _real_extract(self, url):
video_id = self._match_id(url)
2013-12-16 20:56:13 +08:00
display_id = video_id[:8]
2014-06-11 19:38:13 +08:00
api_url = ('https://apib4.blinkx.com/api.php?action=play_video&' +
2014-01-07 16:45:40 +08:00
'video=%s' % video_id)
2013-12-16 20:56:13 +08:00
data_json = self._download_webpage(api_url, display_id)
data = json.loads(data_json)['api']['results'][0]
duration = None
thumbnails = []
formats = []
for m in data['media']:
if m['type'] == 'jpg':
thumbnails.append({
'url': m['link'],
'width': int(m['w']),
'height': int(m['h']),
})
elif m['type'] == 'original':
2014-07-28 01:40:17 +08:00
duration = float(m['d'])
elif m['type'] == 'youtube':
yt_id = m['link']
2014-06-11 19:38:13 +08:00
self.to_screen('Youtube video detected: %s' % yt_id)
return self.url_result(yt_id, 'Youtube', video_id=yt_id)
2013-12-16 20:56:13 +08:00
elif m['type'] in ('flv', 'mp4'):
vcodec = remove_start(m['vcodec'], 'ff')
acodec = remove_start(m['acodec'], 'ff')
2015-02-20 03:19:38 +08:00
vbr = int_or_none(m.get('vbr') or m.get('vbitrate'), 1000)
abr = int_or_none(m.get('abr') or m.get('abitrate'), 1000)
tbr = vbr + abr if vbr and abr else None
2014-06-11 19:38:13 +08:00
format_id = '%s-%sk-%s' % (vcodec, tbr, m['w'])
2013-12-16 20:56:13 +08:00
formats.append({
'format_id': format_id,
'url': m['link'],
'vcodec': vcodec,
'acodec': acodec,
2015-02-20 03:19:38 +08:00
'abr': abr,
'vbr': vbr,
'tbr': tbr,
2015-02-20 03:19:38 +08:00
'width': int_or_none(m.get('w')),
'height': int_or_none(m.get('h')),
2013-12-16 20:56:13 +08:00
})
self._sort_formats(formats)
2013-12-16 20:56:13 +08:00
return {
'id': display_id,
'fullid': video_id,
'title': data['title'],
'formats': formats,
'uploader': data['channel_name'],
'timestamp': data['pubdate_epoch'],
2013-12-16 20:56:13 +08:00
'description': data.get('description'),
'thumbnails': thumbnails,
'duration': duration,
}