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.

95 lines
3.3 KiB

  1. from __future__ import unicode_literals
  2. import datetime
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. remove_start,
  8. )
  9. class BlinkxIE(InfoExtractor):
  10. _VALID_URL = r'^(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)'
  11. IE_NAME = 'blinkx'
  12. _TEST = {
  13. 'url': 'http://www.blinkx.com/ce/8aQUy7GVFYgFzpKhT0oqsilwOGFRVXk3R1ZGWWdGenBLaFQwb3FzaWx3OGFRVXk3R1ZGWWdGenB',
  14. 'file': '8aQUy7GV.mp4',
  15. 'md5': '2e9a07364af40163a908edbf10bb2492',
  16. 'info_dict': {
  17. "title": "Police Car Rolls Away",
  18. "uploader": "stupidvideos.com",
  19. "upload_date": "20131215",
  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. dt = datetime.datetime.fromtimestamp(data['pubdate_epoch'])
  38. pload_date = dt.strftime('%Y%m%d')
  39. duration = None
  40. thumbnails = []
  41. formats = []
  42. for m in data['media']:
  43. if m['type'] == 'jpg':
  44. thumbnails.append({
  45. 'url': m['link'],
  46. 'width': int(m['w']),
  47. 'height': int(m['h']),
  48. })
  49. elif m['type'] == 'original':
  50. duration = m['d']
  51. elif m['type'] == 'youtube':
  52. yt_id = m['link']
  53. self.to_screen(u'Youtube video detected: %s' % yt_id)
  54. return self.url_result(yt_id, 'Youtube', video_id=yt_id)
  55. elif m['type'] in ('flv', 'mp4'):
  56. vcodec = remove_start(m['vcodec'], 'ff')
  57. acodec = remove_start(m['acodec'], 'ff')
  58. tbr = (int(m['vbr']) + int(m['abr'])) // 1000
  59. format_id = (u'%s-%sk-%s' %
  60. (vcodec,
  61. tbr,
  62. m['w']))
  63. formats.append({
  64. 'format_id': format_id,
  65. 'url': m['link'],
  66. 'vcodec': vcodec,
  67. 'acodec': acodec,
  68. 'abr': int(m['abr']) // 1000,
  69. 'vbr': int(m['vbr']) // 1000,
  70. 'tbr': tbr,
  71. 'width': int(m['w']),
  72. 'height': int(m['h']),
  73. })
  74. self._sort_formats(formats)
  75. return {
  76. 'id': display_id,
  77. 'fullid': video_id,
  78. 'title': data['title'],
  79. 'formats': formats,
  80. 'uploader': data['channel_name'],
  81. 'upload_date': pload_date,
  82. 'description': data.get('description'),
  83. 'thumbnails': thumbnails,
  84. 'duration': duration,
  85. }