]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/viddler.py
[test/cookies] Improve logging
[yt-dlp.git] / yt_dlp / extractor / viddler.py
1 from __future__ import unicode_literals
2
3
4 from .common import InfoExtractor
5 from ..utils import (
6 float_or_none,
7 int_or_none,
8 )
9
10
11 class ViddlerIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)(?:.+?\bsecret=(\d+))?'
13 _TESTS = [{
14 'url': 'http://www.viddler.com/v/43903784',
15 'md5': '9eee21161d2c7f5b39690c3e325fab2f',
16 'info_dict': {
17 'id': '43903784',
18 'ext': 'mov',
19 'title': 'Video Made Easy',
20 'description': 'md5:6a697ebd844ff3093bd2e82c37b409cd',
21 'uploader': 'viddler',
22 'timestamp': 1335371429,
23 'upload_date': '20120425',
24 'duration': 100.89,
25 'thumbnail': r're:^https?://.*\.jpg$',
26 'view_count': int,
27 'comment_count': int,
28 'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
29 }
30 }, {
31 'url': 'http://www.viddler.com/v/4d03aad9/',
32 'md5': 'f12c5a7fa839c47a79363bfdf69404fb',
33 'info_dict': {
34 'id': '4d03aad9',
35 'ext': 'ts',
36 'title': 'WALL-TO-GORTAT',
37 'upload_date': '20150126',
38 'uploader': 'deadspin',
39 'timestamp': 1422285291,
40 'view_count': int,
41 'comment_count': int,
42 }
43 }, {
44 'url': 'http://www.viddler.com/player/221ebbbd/0/',
45 'md5': '740511f61d3d1bb71dc14a0fe01a1c10',
46 'info_dict': {
47 'id': '221ebbbd',
48 'ext': 'mov',
49 'title': 'LETeens-Grammar-snack-third-conditional',
50 'description': ' ',
51 'upload_date': '20140929',
52 'uploader': 'BCLETeens',
53 'timestamp': 1411997190,
54 'view_count': int,
55 'comment_count': int,
56 }
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 },
74 }]
75
76 def _real_extract(self, url):
77 video_id, secret = self._match_valid_url(url).groups()
78
79 query = {
80 'video_id': video_id,
81 'key': 'v0vhrt7bg2xq1vyxhkct',
82 }
83 if secret:
84 query['secret'] = secret
85
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']
89
90 formats = []
91 for filed in data['files']:
92 if filed.get('status', 'ready') != 'ready':
93 continue
94 format_id = filed.get('profile_id') or filed['profile_name']
95 f = {
96 'format_id': format_id,
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()
109 f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:')
110 f['format_id'] = format_id + '-cdn'
111 f['source_preference'] = 1
112 formats.append(f)
113
114 if filed.get('html5_video_source'):
115 f = f.copy()
116 f['url'] = self._proto_relative_url(filed['html5_video_source'])
117 f['format_id'] = format_id + '-html5'
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]
124
125 return {
126 'id': video_id,
127 'title': data['title'],
128 'formats': formats,
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')),
135 'comment_count': int_or_none(data.get('comment_count')),
136 'categories': categories,
137 }