viddler.py 5.1 KB

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