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