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.

138 lines
4.8 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
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. int_or_none,
  7. )
  8. class ViddlerIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)(?:.+?\bsecret=(\d+))?'
  10. _TESTS = [{
  11. 'url': 'http://www.viddler.com/v/43903784',
  12. 'md5': '9eee21161d2c7f5b39690c3e325fab2f',
  13. 'info_dict': {
  14. 'id': '43903784',
  15. 'ext': 'mov',
  16. 'title': 'Video Made Easy',
  17. 'description': 'md5:6a697ebd844ff3093bd2e82c37b409cd',
  18. 'uploader': 'viddler',
  19. 'timestamp': 1335371429,
  20. 'upload_date': '20120425',
  21. 'duration': 100.89,
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'view_count': int,
  24. 'comment_count': int,
  25. 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
  26. }
  27. }, {
  28. 'url': 'http://www.viddler.com/v/4d03aad9/',
  29. 'md5': 'f12c5a7fa839c47a79363bfdf69404fb',
  30. 'info_dict': {
  31. 'id': '4d03aad9',
  32. 'ext': 'ts',
  33. 'title': 'WALL-TO-GORTAT',
  34. 'upload_date': '20150126',
  35. 'uploader': 'deadspin',
  36. 'timestamp': 1422285291,
  37. 'view_count': int,
  38. 'comment_count': int,
  39. }
  40. }, {
  41. 'url': 'http://www.viddler.com/player/221ebbbd/0/',
  42. 'md5': '740511f61d3d1bb71dc14a0fe01a1c10',
  43. 'info_dict': {
  44. 'id': '221ebbbd',
  45. 'ext': 'mov',
  46. 'title': 'LETeens-Grammar-snack-third-conditional',
  47. 'description': ' ',
  48. 'upload_date': '20140929',
  49. 'uploader': 'BCLETeens',
  50. 'timestamp': 1411997190,
  51. 'view_count': int,
  52. 'comment_count': int,
  53. }
  54. }, {
  55. # secret protected
  56. 'url': 'http://www.viddler.com/v/890c0985?secret=34051570',
  57. 'info_dict': {
  58. 'id': '890c0985',
  59. 'ext': 'mp4',
  60. 'title': 'Complete Property Training - Traineeships',
  61. 'description': ' ',
  62. 'upload_date': '20130606',
  63. 'uploader': 'TiffanyBowtell',
  64. 'timestamp': 1370496993,
  65. 'view_count': int,
  66. 'comment_count': int,
  67. },
  68. 'params': {
  69. 'skip_download': True,
  70. },
  71. }]
  72. def _real_extract(self, url):
  73. video_id, secret = re.match(self._VALID_URL, url).groups()
  74. query = {
  75. 'video_id': video_id,
  76. 'key': 'v0vhrt7bg2xq1vyxhkct',
  77. }
  78. if secret:
  79. query['secret'] = secret
  80. data = self._download_json(
  81. 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json',
  82. video_id, headers={'Referer': url}, query=query)['video']
  83. formats = []
  84. for filed in data['files']:
  85. if filed.get('status', 'ready') != 'ready':
  86. continue
  87. format_id = filed.get('profile_id') or filed['profile_name']
  88. f = {
  89. 'format_id': format_id,
  90. 'format_note': filed['profile_name'],
  91. 'url': self._proto_relative_url(filed['url']),
  92. 'width': int_or_none(filed.get('width')),
  93. 'height': int_or_none(filed.get('height')),
  94. 'filesize': int_or_none(filed.get('size')),
  95. 'ext': filed.get('ext'),
  96. 'source_preference': -1,
  97. }
  98. formats.append(f)
  99. if filed.get('cdn_url'):
  100. f = f.copy()
  101. f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:')
  102. f['format_id'] = format_id + '-cdn'
  103. f['source_preference'] = 1
  104. formats.append(f)
  105. if filed.get('html5_video_source'):
  106. f = f.copy()
  107. f['url'] = self._proto_relative_url(filed['html5_video_source'])
  108. f['format_id'] = format_id + '-html5'
  109. f['source_preference'] = 0
  110. formats.append(f)
  111. self._sort_formats(formats)
  112. categories = [
  113. t.get('text') for t in data.get('tags', []) if 'text' in t]
  114. return {
  115. 'id': video_id,
  116. 'title': data['title'],
  117. 'formats': formats,
  118. 'description': data.get('description'),
  119. 'timestamp': int_or_none(data.get('upload_time')),
  120. 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')),
  121. 'uploader': data.get('author'),
  122. 'duration': float_or_none(data.get('length')),
  123. 'view_count': int_or_none(data.get('view_count')),
  124. 'comment_count': int_or_none(data.get('comment_count')),
  125. 'categories': categories,
  126. }