1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-16 20:07:19 +01:00
youtube-dl/youtube_dl/extractor/blinkx.py

87 lines
3.1 KiB
Python
Raw Normal View History

2014-01-07 09:45:40 +01:00
from __future__ import unicode_literals
2013-12-16 13:56:13 +01:00
import json
from .common import InfoExtractor
2015-02-19 20:19:38 +01:00
from ..utils import (
remove_start,
int_or_none,
)
2013-12-16 13:56:13 +01:00
class BlinkxIE(InfoExtractor):
2015-02-19 20:19:38 +01:00
_VALID_URL = r'(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)'
2014-01-07 09:45:58 +01:00
IE_NAME = 'blinkx'
2013-12-16 13:56:13 +01:00
_TEST = {
2015-02-19 20:19:38 +01:00
'url': 'http://www.blinkx.com/ce/Da0Gw3xc5ucpNduzLuDDlv4WC9PuI4fDi1-t6Y3LyfdY2SZS5Urbvn-UPJvrvbo8LTKTc67Wu2rPKSQDJyZeeORCR8bYkhs8lI7eqddznH2ofh5WEEdjYXnoRtj7ByQwt7atMErmXIeYKPsSDuMAAqJDlQZ-3Ff4HJVeH_s3Gh8oQ',
'md5': '337cf7a344663ec79bf93a526a2e06c7',
2014-01-07 09:45:40 +01:00
'info_dict': {
2015-02-19 20:19:38 +01:00
'id': 'Da0Gw3xc',
2014-06-11 13:38:13 +02:00
'ext': 'mp4',
2015-02-19 20:19:38 +01: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 13:56:13 +01:00
},
}
2015-02-19 20:19:38 +01:00
def _real_extract(self, url):
video_id = self._match_id(url)
2013-12-16 13:56:13 +01:00
display_id = video_id[:8]
2014-06-11 13:38:13 +02:00
api_url = ('https://apib4.blinkx.com/api.php?action=play_video&' +
2014-01-07 09:45:40 +01:00
'video=%s' % video_id)
2013-12-16 13:56:13 +01: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-27 19:40:17 +02:00
duration = float(m['d'])
elif m['type'] == 'youtube':
yt_id = m['link']
2014-06-11 13:38:13 +02:00
self.to_screen('Youtube video detected: %s' % yt_id)
return self.url_result(yt_id, 'Youtube', video_id=yt_id)
2013-12-16 13:56:13 +01:00
elif m['type'] in ('flv', 'mp4'):
vcodec = remove_start(m['vcodec'], 'ff')
acodec = remove_start(m['acodec'], 'ff')
2015-02-19 20:19:38 +01: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 13:38:13 +02:00
format_id = '%s-%sk-%s' % (vcodec, tbr, m['w'])
2013-12-16 13:56:13 +01:00
formats.append({
'format_id': format_id,
'url': m['link'],
'vcodec': vcodec,
'acodec': acodec,
2015-02-19 20:19:38 +01:00
'abr': abr,
'vbr': vbr,
'tbr': tbr,
2015-02-19 20:19:38 +01:00
'width': int_or_none(m.get('w')),
'height': int_or_none(m.get('h')),
2013-12-16 13:56:13 +01:00
})
self._sort_formats(formats)
2013-12-16 13:56:13 +01:00
return {
'id': display_id,
'fullid': video_id,
'title': data['title'],
'formats': formats,
'uploader': data['channel_name'],
'timestamp': data['pubdate_epoch'],
2013-12-16 13:56:13 +01:00
'description': data.get('description'),
'thumbnails': thumbnails,
'duration': duration,
}