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