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.

118 lines
4.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  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. 'comment_count': int,
  27. 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
  28. }
  29. }, {
  30. 'url': 'http://www.viddler.com/v/4d03aad9/',
  31. 'md5': 'faa71fbf70c0bee7ab93076fd007f4b0',
  32. 'info_dict': {
  33. 'id': '4d03aad9',
  34. 'ext': 'mp4',
  35. 'title': 'WALL-TO-GORTAT',
  36. 'upload_date': '20150126',
  37. 'uploader': 'deadspin',
  38. 'timestamp': 1422285291,
  39. 'view_count': int,
  40. 'comment_count': int,
  41. }
  42. }, {
  43. 'url': 'http://www.viddler.com/player/221ebbbd/0/',
  44. 'md5': '0defa2bd0ea613d14a6e9bd1db6be326',
  45. 'info_dict': {
  46. 'id': '221ebbbd',
  47. 'ext': 'mp4',
  48. 'title': 'LETeens-Grammar-snack-third-conditional',
  49. 'description': ' ',
  50. 'upload_date': '20140929',
  51. 'uploader': 'BCLETeens',
  52. 'timestamp': 1411997190,
  53. 'view_count': int,
  54. 'comment_count': int,
  55. }
  56. }]
  57. def _real_extract(self, url):
  58. video_id = self._match_id(url)
  59. json_url = (
  60. 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json?video_id=%s&key=v0vhrt7bg2xq1vyxhkct' %
  61. video_id)
  62. headers = {'Referer': 'http://static.cdn-ec.viddler.com/js/arpeggio/v2/embed.html'}
  63. request = compat_urllib_request.Request(json_url, None, headers)
  64. data = self._download_json(request, video_id)['video']
  65. formats = []
  66. for filed in data['files']:
  67. if filed.get('status', 'ready') != 'ready':
  68. continue
  69. format_id = filed.get('profile_id') or filed['profile_name']
  70. f = {
  71. 'format_id': format_id,
  72. 'format_note': filed['profile_name'],
  73. 'url': self._proto_relative_url(filed['url']),
  74. 'width': int_or_none(filed.get('width')),
  75. 'height': int_or_none(filed.get('height')),
  76. 'filesize': int_or_none(filed.get('size')),
  77. 'ext': filed.get('ext'),
  78. 'source_preference': -1,
  79. }
  80. formats.append(f)
  81. if filed.get('cdn_url'):
  82. f = f.copy()
  83. f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:')
  84. f['format_id'] = format_id + '-cdn'
  85. f['source_preference'] = 1
  86. formats.append(f)
  87. if filed.get('html5_video_source'):
  88. f = f.copy()
  89. f['url'] = self._proto_relative_url(filed['html5_video_source'])
  90. f['format_id'] = format_id + '-html5'
  91. f['source_preference'] = 0
  92. formats.append(f)
  93. self._sort_formats(formats)
  94. categories = [
  95. t.get('text') for t in data.get('tags', []) if 'text' in t]
  96. return {
  97. 'id': video_id,
  98. 'title': data['title'],
  99. 'formats': formats,
  100. 'description': data.get('description'),
  101. 'timestamp': int_or_none(data.get('upload_time')),
  102. 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')),
  103. 'uploader': data.get('author'),
  104. 'duration': float_or_none(data.get('length')),
  105. 'view_count': int_or_none(data.get('view_count')),
  106. 'comment_count': int_or_none(data.get('comment_count')),
  107. 'categories': categories,
  108. }