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.

85 lines
3.2 KiB

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. class ViddlerIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)'
  9. _TEST = {
  10. "url": "http://www.viddler.com/v/43903784",
  11. 'md5': 'ae43ad7cb59431ce043f0ff7fa13cbf4',
  12. 'info_dict': {
  13. 'id': '43903784',
  14. 'ext': 'mp4',
  15. "title": "Video Made Easy",
  16. 'description': 'You don\'t need to be a professional to make high-quality video content. Viddler provides some quick and easy tips on how to produce great video content with limited resources. ',
  17. "uploader": "viddler",
  18. 'timestamp': 1335371429,
  19. 'upload_date': '20120425',
  20. "duration": 100.89,
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. 'view_count': int,
  23. 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. json_url = (
  29. 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json?video_id=%s&key=v0vhrt7bg2xq1vyxhkct' %
  30. video_id)
  31. data = self._download_json(json_url, video_id)['video']
  32. formats = []
  33. for filed in data['files']:
  34. if filed.get('status', 'ready') != 'ready':
  35. continue
  36. f = {
  37. 'format_id': filed['profile_id'],
  38. 'format_note': filed['profile_name'],
  39. 'url': self._proto_relative_url(filed['url']),
  40. 'width': int_or_none(filed.get('width')),
  41. 'height': int_or_none(filed.get('height')),
  42. 'filesize': int_or_none(filed.get('size')),
  43. 'ext': filed.get('ext'),
  44. 'source_preference': -1,
  45. }
  46. formats.append(f)
  47. if filed.get('cdn_url'):
  48. f = f.copy()
  49. f['url'] = self._proto_relative_url(filed['cdn_url'])
  50. f['format_id'] = filed['profile_id'] + '-cdn'
  51. f['source_preference'] = 1
  52. formats.append(f)
  53. if filed.get('html5_video_source'):
  54. f = f.copy()
  55. f['url'] = self._proto_relative_url(
  56. filed['html5_video_source'])
  57. f['format_id'] = filed['profile_id'] + '-html5'
  58. f['source_preference'] = 0
  59. formats.append(f)
  60. self._sort_formats(formats)
  61. categories = [
  62. t.get('text') for t in data.get('tags', []) if 'text' in t]
  63. return {
  64. '_type': 'video',
  65. 'id': video_id,
  66. 'title': data['title'],
  67. 'formats': formats,
  68. 'description': data.get('description'),
  69. 'timestamp': int_or_none(data.get('upload_time')),
  70. 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')),
  71. 'uploader': data.get('author'),
  72. 'duration': float_or_none(data.get('length')),
  73. 'view_count': int_or_none(data.get('view_count')),
  74. 'categories': categories,
  75. }