]>
Commit | Line | Data |
---|---|---|
c64ed2a3 | 1 | from __future__ import unicode_literals |
41e8bca4 | 2 | |
e5855472 | 3 | |
41e8bca4 | 4 | from .common import InfoExtractor |
c64ed2a3 PH |
5 | from ..utils import ( |
6 | float_or_none, | |
7 | int_or_none, | |
796df3c6 | 8 | ) |
41e8bca4 PH |
9 | |
10 | ||
11 | class ViddlerIE(InfoExtractor): | |
e5855472 | 12 | _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)(?:.+?\bsecret=(\d+))?' |
796df3c6 | 13 | _TESTS = [{ |
b04fbd78 | 14 | 'url': 'http://www.viddler.com/v/43903784', |
47246ae2 | 15 | 'md5': '9eee21161d2c7f5b39690c3e325fab2f', |
c64ed2a3 PH |
16 | 'info_dict': { |
17 | 'id': '43903784', | |
47246ae2 | 18 | 'ext': 'mov', |
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, |
ec85ded8 | 25 | 'thumbnail': r're:^https?://.*\.jpg$', |
c64ed2a3 | 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 | 31 | 'url': 'http://www.viddler.com/v/4d03aad9/', |
47246ae2 | 32 | 'md5': 'f12c5a7fa839c47a79363bfdf69404fb', |
b04fbd78 S |
33 | 'info_dict': { |
34 | 'id': '4d03aad9', | |
47246ae2 | 35 | 'ext': 'ts', |
b04fbd78 | 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 | 44 | 'url': 'http://www.viddler.com/player/221ebbbd/0/', |
47246ae2 | 45 | 'md5': '740511f61d3d1bb71dc14a0fe01a1c10', |
b04fbd78 S |
46 | 'info_dict': { |
47 | 'id': '221ebbbd', | |
47246ae2 | 48 | 'ext': 'mov', |
b04fbd78 S |
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 | 56 | } |
9c15869c S |
57 | }, { |
58 | # secret protected | |
59 | 'url': 'http://www.viddler.com/v/890c0985?secret=34051570', | |
60 | 'info_dict': { | |
61 | 'id': '890c0985', | |
62 | 'ext': 'mp4', | |
63 | 'title': 'Complete Property Training - Traineeships', | |
64 | 'description': ' ', | |
65 | 'upload_date': '20130606', | |
66 | 'uploader': 'TiffanyBowtell', | |
67 | 'timestamp': 1370496993, | |
68 | 'view_count': int, | |
69 | 'comment_count': int, | |
70 | }, | |
71 | 'params': { | |
72 | 'skip_download': True, | |
73 | }, | |
796df3c6 | 74 | }] |
41e8bca4 PH |
75 | |
76 | def _real_extract(self, url): | |
5ad28e7f | 77 | video_id, secret = self._match_valid_url(url).groups() |
c64ed2a3 | 78 | |
9c15869c S |
79 | query = { |
80 | 'video_id': video_id, | |
81 | 'key': 'v0vhrt7bg2xq1vyxhkct', | |
82 | } | |
9c15869c S |
83 | if secret: |
84 | query['secret'] = secret | |
85 | ||
e5855472 RA |
86 | data = self._download_json( |
87 | 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json', | |
88 | video_id, headers={'Referer': url}, query=query)['video'] | |
c64ed2a3 PH |
89 | |
90 | formats = [] | |
91 | for filed in data['files']: | |
92 | if filed.get('status', 'ready') != 'ready': | |
93 | continue | |
18b4e9e7 | 94 | format_id = filed.get('profile_id') or filed['profile_name'] |
c64ed2a3 | 95 | f = { |
18b4e9e7 | 96 | 'format_id': format_id, |
c64ed2a3 PH |
97 | 'format_note': filed['profile_name'], |
98 | 'url': self._proto_relative_url(filed['url']), | |
99 | 'width': int_or_none(filed.get('width')), | |
100 | 'height': int_or_none(filed.get('height')), | |
101 | 'filesize': int_or_none(filed.get('size')), | |
102 | 'ext': filed.get('ext'), | |
103 | 'source_preference': -1, | |
104 | } | |
105 | formats.append(f) | |
106 | ||
107 | if filed.get('cdn_url'): | |
108 | f = f.copy() | |
796df3c6 | 109 | f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:') |
18b4e9e7 | 110 | f['format_id'] = format_id + '-cdn' |
c64ed2a3 PH |
111 | f['source_preference'] = 1 |
112 | formats.append(f) | |
113 | ||
114 | if filed.get('html5_video_source'): | |
115 | f = f.copy() | |
b04fbd78 | 116 | f['url'] = self._proto_relative_url(filed['html5_video_source']) |
18b4e9e7 | 117 | f['format_id'] = format_id + '-html5' |
c64ed2a3 PH |
118 | f['source_preference'] = 0 |
119 | formats.append(f) | |
120 | self._sort_formats(formats) | |
121 | ||
122 | categories = [ | |
123 | t.get('text') for t in data.get('tags', []) if 'text' in t] | |
41e8bca4 | 124 | |
fb7abb31 | 125 | return { |
41e8bca4 | 126 | 'id': video_id, |
c64ed2a3 | 127 | 'title': data['title'], |
41e8bca4 | 128 | 'formats': formats, |
c64ed2a3 PH |
129 | 'description': data.get('description'), |
130 | 'timestamp': int_or_none(data.get('upload_time')), | |
131 | 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')), | |
132 | 'uploader': data.get('author'), | |
133 | 'duration': float_or_none(data.get('length')), | |
134 | 'view_count': int_or_none(data.get('view_count')), | |
18b4e9e7 | 135 | 'comment_count': int_or_none(data.get('comment_count')), |
c64ed2a3 | 136 | 'categories': categories, |
41e8bca4 | 137 | } |