viddler.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. float_or_none,
  5. int_or_none,
  6. )
  7. from ..compat import (
  8. compat_urllib_request
  9. )
  10. class ViddlerIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.viddler.com/v/43903784',
  14. 'md5': 'ae43ad7cb59431ce043f0ff7fa13cbf4',
  15. 'info_dict': {
  16. 'id': '43903784',
  17. 'ext': 'mp4',
  18. 'title': 'Video Made Easy',
  19. 'description': 'md5:6a697ebd844ff3093bd2e82c37b409cd',
  20. 'uploader': 'viddler',
  21. 'timestamp': 1335371429,
  22. 'upload_date': '20120425',
  23. 'duration': 100.89,
  24. 'thumbnail': 're:^https?://.*\.jpg$',
  25. 'view_count': int,
  26. 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
  27. }
  28. }, {
  29. 'url': 'http://www.viddler.com/v/4d03aad9/',
  30. 'md5': 'faa71fbf70c0bee7ab93076fd007f4b0',
  31. 'info_dict': {
  32. 'id': '4d03aad9',
  33. 'ext': 'mp4',
  34. 'title': 'WALL-TO-GORTAT',
  35. 'upload_date': '20150126',
  36. 'uploader': 'deadspin',
  37. 'timestamp': 1422285291,
  38. }
  39. }, {
  40. 'url': 'http://www.viddler.com/player/221ebbbd/0/',
  41. 'md5': '0defa2bd0ea613d14a6e9bd1db6be326',
  42. 'info_dict': {
  43. 'id': '221ebbbd',
  44. 'ext': 'mp4',
  45. 'title': 'LETeens-Grammar-snack-third-conditional',
  46. 'description': ' ',
  47. 'upload_date': '20140929',
  48. 'uploader': 'BCLETeens',
  49. 'timestamp': 1411997190,
  50. }
  51. }]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. json_url = (
  55. 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json?video_id=%s&key=v0vhrt7bg2xq1vyxhkct' %
  56. video_id)
  57. headers = {'Referer': 'http://static.cdn-ec.viddler.com/js/arpeggio/v2/embed.html'}
  58. request = compat_urllib_request.Request(json_url, None, headers)
  59. data = self._download_json(request, video_id)['video']
  60. formats = []
  61. for filed in data['files']:
  62. if filed.get('status', 'ready') != 'ready':
  63. continue
  64. f = {
  65. 'format_id': filed['profile_id'] or filed['profile_name'],
  66. 'format_note': filed['profile_name'],
  67. 'url': self._proto_relative_url(filed['url']),
  68. 'width': int_or_none(filed.get('width')),
  69. 'height': int_or_none(filed.get('height')),
  70. 'filesize': int_or_none(filed.get('size')),
  71. 'ext': filed.get('ext'),
  72. 'source_preference': -1,
  73. }
  74. formats.append(f)
  75. if filed.get('cdn_url'):
  76. f = f.copy()
  77. f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:')
  78. f['format_id'] = (filed['profile_id'] or filed['profile_name']) + '-cdn'
  79. f['source_preference'] = 1
  80. formats.append(f)
  81. if filed.get('html5_video_source'):
  82. f = f.copy()
  83. f['url'] = self._proto_relative_url(filed['html5_video_source'])
  84. f['format_id'] = (filed['profile_id'] or filed['profile_name']) + '-html5'
  85. f['source_preference'] = 0
  86. formats.append(f)
  87. self._sort_formats(formats)
  88. categories = [
  89. t.get('text') for t in data.get('tags', []) if 'text' in t]
  90. return {
  91. 'id': video_id,
  92. 'title': data['title'],
  93. 'formats': formats,
  94. 'description': data.get('description'),
  95. 'timestamp': int_or_none(data.get('upload_time')),
  96. 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')),
  97. 'uploader': data.get('author'),
  98. 'duration': float_or_none(data.get('length')),
  99. 'view_count': int_or_none(data.get('view_count')),
  100. 'categories': categories,
  101. }