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.

90 lines
3.3 KiB

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