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