]>
Commit | Line | Data |
---|---|---|
c64ed2a3 | 1 | from __future__ import unicode_literals |
41e8bca4 | 2 | |
e5855472 RA |
3 | import re |
4 | ||
41e8bca4 | 5 | from .common import InfoExtractor |
c64ed2a3 PH |
6 | from ..utils import ( |
7 | float_or_none, | |
8 | int_or_none, | |
796df3c6 | 9 | ) |
41e8bca4 PH |
10 | |
11 | ||
12 | class ViddlerIE(InfoExtractor): | |
e5855472 | 13 | _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)(?:.+?\bsecret=(\d+))?' |
796df3c6 | 14 | _TESTS = [{ |
b04fbd78 | 15 | 'url': 'http://www.viddler.com/v/43903784', |
47246ae2 | 16 | 'md5': '9eee21161d2c7f5b39690c3e325fab2f', |
c64ed2a3 PH |
17 | 'info_dict': { |
18 | 'id': '43903784', | |
47246ae2 | 19 | 'ext': 'mov', |
b04fbd78 S |
20 | 'title': 'Video Made Easy', |
21 | 'description': 'md5:6a697ebd844ff3093bd2e82c37b409cd', | |
22 | 'uploader': 'viddler', | |
c64ed2a3 PH |
23 | 'timestamp': 1335371429, |
24 | 'upload_date': '20120425', | |
b04fbd78 | 25 | 'duration': 100.89, |
ec85ded8 | 26 | 'thumbnail': r're:^https?://.*\.jpg$', |
c64ed2a3 | 27 | 'view_count': int, |
18b4e9e7 | 28 | 'comment_count': int, |
c64ed2a3 | 29 | 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'], |
41e8bca4 | 30 | } |
796df3c6 | 31 | }, { |
b04fbd78 | 32 | 'url': 'http://www.viddler.com/v/4d03aad9/', |
47246ae2 | 33 | 'md5': 'f12c5a7fa839c47a79363bfdf69404fb', |
b04fbd78 S |
34 | 'info_dict': { |
35 | 'id': '4d03aad9', | |
47246ae2 | 36 | 'ext': 'ts', |
b04fbd78 | 37 | 'title': 'WALL-TO-GORTAT', |
796df3c6 S |
38 | 'upload_date': '20150126', |
39 | 'uploader': 'deadspin', | |
796df3c6 | 40 | 'timestamp': 1422285291, |
18b4e9e7 S |
41 | 'view_count': int, |
42 | 'comment_count': int, | |
796df3c6 S |
43 | } |
44 | }, { | |
b04fbd78 | 45 | 'url': 'http://www.viddler.com/player/221ebbbd/0/', |
47246ae2 | 46 | 'md5': '740511f61d3d1bb71dc14a0fe01a1c10', |
b04fbd78 S |
47 | 'info_dict': { |
48 | 'id': '221ebbbd', | |
47246ae2 | 49 | 'ext': 'mov', |
b04fbd78 S |
50 | 'title': 'LETeens-Grammar-snack-third-conditional', |
51 | 'description': ' ', | |
796df3c6 S |
52 | 'upload_date': '20140929', |
53 | 'uploader': 'BCLETeens', | |
796df3c6 | 54 | 'timestamp': 1411997190, |
18b4e9e7 S |
55 | 'view_count': int, |
56 | 'comment_count': int, | |
796df3c6 | 57 | } |
9c15869c S |
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 | }, | |
796df3c6 | 75 | }] |
41e8bca4 PH |
76 | |
77 | def _real_extract(self, url): | |
e5855472 | 78 | video_id, secret = re.match(self._VALID_URL, url).groups() |
c64ed2a3 | 79 | |
9c15869c S |
80 | query = { |
81 | 'video_id': video_id, | |
82 | 'key': 'v0vhrt7bg2xq1vyxhkct', | |
83 | } | |
9c15869c S |
84 | if secret: |
85 | query['secret'] = secret | |
86 | ||
e5855472 RA |
87 | data = self._download_json( |
88 | 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json', | |
89 | video_id, headers={'Referer': url}, query=query)['video'] | |
c64ed2a3 PH |
90 | |
91 | formats = [] | |
92 | for filed in data['files']: | |
93 | if filed.get('status', 'ready') != 'ready': | |
94 | continue | |
18b4e9e7 | 95 | format_id = filed.get('profile_id') or filed['profile_name'] |
c64ed2a3 | 96 | f = { |
18b4e9e7 | 97 | 'format_id': format_id, |
c64ed2a3 PH |
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 | ||
108 | if filed.get('cdn_url'): | |
109 | f = f.copy() | |
796df3c6 | 110 | f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:') |
18b4e9e7 | 111 | f['format_id'] = format_id + '-cdn' |
c64ed2a3 PH |
112 | f['source_preference'] = 1 |
113 | formats.append(f) | |
114 | ||
115 | if filed.get('html5_video_source'): | |
116 | f = f.copy() | |
b04fbd78 | 117 | f['url'] = self._proto_relative_url(filed['html5_video_source']) |
18b4e9e7 | 118 | f['format_id'] = format_id + '-html5' |
c64ed2a3 PH |
119 | f['source_preference'] = 0 |
120 | formats.append(f) | |
121 | self._sort_formats(formats) | |
122 | ||
123 | categories = [ | |
124 | t.get('text') for t in data.get('tags', []) if 'text' in t] | |
41e8bca4 | 125 | |
fb7abb31 | 126 | return { |
41e8bca4 | 127 | 'id': video_id, |
c64ed2a3 | 128 | 'title': data['title'], |
41e8bca4 | 129 | 'formats': formats, |
c64ed2a3 PH |
130 | 'description': data.get('description'), |
131 | 'timestamp': int_or_none(data.get('upload_time')), | |
132 | 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')), | |
133 | 'uploader': data.get('author'), | |
134 | 'duration': float_or_none(data.get('length')), | |
135 | 'view_count': int_or_none(data.get('view_count')), | |
18b4e9e7 | 136 | 'comment_count': int_or_none(data.get('comment_count')), |
c64ed2a3 | 137 | 'categories': categories, |
41e8bca4 | 138 | } |