You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.1 KiB

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