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.

89 lines
3.2 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. remove_start,
  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/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB',
  13. 'file': '8aQUy7GV.mp4',
  14. 'md5': '2e9a07364af40163a908edbf10bb2492',
  15. 'info_dict': {
  16. 'title': 'Police Car Rolls Away',
  17. 'uploader': 'stupidvideos.com',
  18. 'upload_date': '20131215',
  19. 'timestamp': 1387068000,
  20. '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!',
  21. 'duration': 14.886,
  22. 'thumbnails': [{
  23. 'width': 100,
  24. 'height': 76,
  25. 'url': 'http://cdn.blinkx.com/stream/b/41/StupidVideos/20131215/1873969261/1873969261_tn_0.jpg',
  26. }],
  27. },
  28. }
  29. def _real_extract(self, rl):
  30. m = re.match(self._VALID_URL, rl)
  31. video_id = m.group('id')
  32. display_id = video_id[:8]
  33. api_url = (u'https://apib4.blinkx.com/api.php?action=play_video&' +
  34. 'video=%s' % video_id)
  35. data_json = self._download_webpage(api_url, display_id)
  36. data = json.loads(data_json)['api']['results'][0]
  37. duration = None
  38. thumbnails = []
  39. formats = []
  40. for m in data['media']:
  41. if m['type'] == 'jpg':
  42. thumbnails.append({
  43. 'url': m['link'],
  44. 'width': int(m['w']),
  45. 'height': int(m['h']),
  46. })
  47. elif m['type'] == 'original':
  48. duration = m['d']
  49. elif m['type'] == 'youtube':
  50. yt_id = m['link']
  51. self.to_screen(u'Youtube video detected: %s' % yt_id)
  52. return self.url_result(yt_id, 'Youtube', video_id=yt_id)
  53. elif m['type'] in ('flv', 'mp4'):
  54. vcodec = remove_start(m['vcodec'], 'ff')
  55. acodec = remove_start(m['acodec'], 'ff')
  56. tbr = (int(m['vbr']) + int(m['abr'])) // 1000
  57. format_id = u'%s-%sk-%s' % (vcodec, tbr, m['w'])
  58. formats.append({
  59. 'format_id': format_id,
  60. 'url': m['link'],
  61. 'vcodec': vcodec,
  62. 'acodec': acodec,
  63. 'abr': int(m['abr']) // 1000,
  64. 'vbr': int(m['vbr']) // 1000,
  65. 'tbr': tbr,
  66. 'width': int(m['w']),
  67. 'height': int(m['h']),
  68. })
  69. self._sort_formats(formats)
  70. return {
  71. 'id': display_id,
  72. 'fullid': video_id,
  73. 'title': data['title'],
  74. 'formats': formats,
  75. 'uploader': data['channel_name'],
  76. 'timestamp': data['pubdate_epoch'],
  77. 'description': data.get('description'),
  78. 'thumbnails': thumbnails,
  79. 'duration': duration,
  80. }