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 remove_start
  6. class BlinkxIE(InfoExtractor):
  7. _VALID_URL = r'^(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)'
  8. IE_NAME = 'blinkx'
  9. _TEST = {
  10. 'url': 'http://www.blinkx.com/ce/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB',
  11. 'md5': '2e9a07364af40163a908edbf10bb2492',
  12. 'info_dict': {
  13. 'id': '8aQUy7GV',
  14. 'ext': 'mp4',
  15. 'title': 'Police Car Rolls Away',
  16. 'uploader': 'stupidvideos.com',
  17. 'upload_date': '20131215',
  18. 'timestamp': 1387068000,
  19. '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!',
  20. 'duration': 14.886,
  21. 'thumbnails': [{
  22. 'width': 100,
  23. 'height': 76,
  24. 'resolution': '100x76',
  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 = ('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 = float(m['d'])
  49. elif m['type'] == 'youtube':
  50. yt_id = m['link']
  51. self.to_screen('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 = '%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. }