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.

93 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. tbr = (int(m['vbr']) + int(m['abr'])) // 1000
  58. format_id = (u'%s-%sk-%s' %
  59. (vcodec,
  60. tbr,
  61. m['w']))
  62. formats.append({
  63. 'format_id': format_id,
  64. 'url': m['link'],
  65. 'vcodec': vcodec,
  66. 'acodec': acodec,
  67. 'abr': int(m['abr']) // 1000,
  68. 'vbr': int(m['vbr']) // 1000,
  69. 'tbr': tbr,
  70. 'width': int(m['w']),
  71. 'height': int(m['h']),
  72. })
  73. self._sort_formats(formats)
  74. return {
  75. 'id': display_id,
  76. 'fullid': video_id,
  77. 'title': data['title'],
  78. 'formats': formats,
  79. 'uploader': data['channel_name'],
  80. 'upload_date': upload_date,
  81. 'description': data.get('description'),
  82. 'thumbnails': thumbnails,
  83. 'duration': duration,
  84. }