]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/viddler.py
f491b67efd615a1c2338a5de9c479fb8c81d3dff
[yt-dlp.git] / yt_dlp / extractor / viddler.py
1 from .common import InfoExtractor
2 from ..utils import (
3 float_or_none,
4 int_or_none,
5 )
6
7
8 class ViddlerIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)(?:.+?\bsecret=(\d+))?'
10 _TESTS = [{
11 'url': 'http://www.viddler.com/v/43903784',
12 'md5': '9eee21161d2c7f5b39690c3e325fab2f',
13 'info_dict': {
14 'id': '43903784',
15 'ext': 'mov',
16 'title': 'Video Made Easy',
17 'description': 'md5:6a697ebd844ff3093bd2e82c37b409cd',
18 'uploader': 'viddler',
19 'timestamp': 1335371429,
20 'upload_date': '20120425',
21 'duration': 100.89,
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'view_count': int,
24 'comment_count': int,
25 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
26 }
27 }, {
28 'url': 'http://www.viddler.com/v/4d03aad9/',
29 'md5': 'f12c5a7fa839c47a79363bfdf69404fb',
30 'info_dict': {
31 'id': '4d03aad9',
32 'ext': 'ts',
33 'title': 'WALL-TO-GORTAT',
34 'upload_date': '20150126',
35 'uploader': 'deadspin',
36 'timestamp': 1422285291,
37 'view_count': int,
38 'comment_count': int,
39 }
40 }, {
41 'url': 'http://www.viddler.com/player/221ebbbd/0/',
42 'md5': '740511f61d3d1bb71dc14a0fe01a1c10',
43 'info_dict': {
44 'id': '221ebbbd',
45 'ext': 'mov',
46 'title': 'LETeens-Grammar-snack-third-conditional',
47 'description': ' ',
48 'upload_date': '20140929',
49 'uploader': 'BCLETeens',
50 'timestamp': 1411997190,
51 'view_count': int,
52 'comment_count': int,
53 }
54 }, {
55 # secret protected
56 'url': 'http://www.viddler.com/v/890c0985?secret=34051570',
57 'info_dict': {
58 'id': '890c0985',
59 'ext': 'mp4',
60 'title': 'Complete Property Training - Traineeships',
61 'description': ' ',
62 'upload_date': '20130606',
63 'uploader': 'TiffanyBowtell',
64 'timestamp': 1370496993,
65 'view_count': int,
66 'comment_count': int,
67 },
68 'params': {
69 'skip_download': True,
70 },
71 }]
72
73 def _real_extract(self, url):
74 video_id, secret = self._match_valid_url(url).groups()
75
76 query = {
77 'video_id': video_id,
78 'key': 'v0vhrt7bg2xq1vyxhkct',
79 }
80 if secret:
81 query['secret'] = secret
82
83 data = self._download_json(
84 'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json',
85 video_id, headers={'Referer': url}, query=query)['video']
86
87 formats = []
88 for filed in data['files']:
89 if filed.get('status', 'ready') != 'ready':
90 continue
91 format_id = filed.get('profile_id') or filed['profile_name']
92 f = {
93 'format_id': format_id,
94 'format_note': filed['profile_name'],
95 'url': self._proto_relative_url(filed['url']),
96 'width': int_or_none(filed.get('width')),
97 'height': int_or_none(filed.get('height')),
98 'filesize': int_or_none(filed.get('size')),
99 'ext': filed.get('ext'),
100 'source_preference': -1,
101 }
102 formats.append(f)
103
104 if filed.get('cdn_url'):
105 f = f.copy()
106 f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:')
107 f['format_id'] = format_id + '-cdn'
108 f['source_preference'] = 1
109 formats.append(f)
110
111 if filed.get('html5_video_source'):
112 f = f.copy()
113 f['url'] = self._proto_relative_url(filed['html5_video_source'])
114 f['format_id'] = format_id + '-html5'
115 f['source_preference'] = 0
116 formats.append(f)
117 self._sort_formats(formats)
118
119 categories = [
120 t.get('text') for t in data.get('tags', []) if 'text' in t]
121
122 return {
123 'id': video_id,
124 'title': data['title'],
125 'formats': formats,
126 'description': data.get('description'),
127 'timestamp': int_or_none(data.get('upload_time')),
128 'thumbnail': self._proto_relative_url(data.get('thumbnail_url')),
129 'uploader': data.get('author'),
130 'duration': float_or_none(data.get('length')),
131 'view_count': int_or_none(data.get('view_count')),
132 'comment_count': int_or_none(data.get('comment_count')),
133 'categories': categories,
134 }