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