]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/viddler.py
[JWPlatform] Use non-capturing group in RE
[youtube-dl] / youtube_dl / extractor / viddler.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import (
5     compat_urllib_parse_urlencode,
6     compat_urlparse,
7 )
8 from ..utils import (
9     float_or_none,
10     int_or_none,
11     sanitized_Request,
12 )
13
14
15 class ViddlerIE(InfoExtractor):
16     _VALID_URL = r'https?://(?:www\.)?viddler\.com/(?:v|embed|player)/(?P<id>[a-z0-9]+)'
17     _TESTS = [{
18         'url': 'http://www.viddler.com/v/43903784',
19         'md5': '9eee21161d2c7f5b39690c3e325fab2f',
20         'info_dict': {
21             'id': '43903784',
22             'ext': 'mov',
23             'title': 'Video Made Easy',
24             'description': 'md5:6a697ebd844ff3093bd2e82c37b409cd',
25             'uploader': 'viddler',
26             'timestamp': 1335371429,
27             'upload_date': '20120425',
28             'duration': 100.89,
29             'thumbnail': r're:^https?://.*\.jpg$',
30             'view_count': int,
31             'comment_count': int,
32             'categories': ['video content', 'high quality video', 'video made easy', 'how to produce video with limited resources', 'viddler'],
33         }
34     }, {
35         'url': 'http://www.viddler.com/v/4d03aad9/',
36         'md5': 'f12c5a7fa839c47a79363bfdf69404fb',
37         'info_dict': {
38             'id': '4d03aad9',
39             'ext': 'ts',
40             'title': 'WALL-TO-GORTAT',
41             'upload_date': '20150126',
42             'uploader': 'deadspin',
43             'timestamp': 1422285291,
44             'view_count': int,
45             'comment_count': int,
46         }
47     }, {
48         'url': 'http://www.viddler.com/player/221ebbbd/0/',
49         'md5': '740511f61d3d1bb71dc14a0fe01a1c10',
50         'info_dict': {
51             'id': '221ebbbd',
52             'ext': 'mov',
53             'title': 'LETeens-Grammar-snack-third-conditional',
54             'description': ' ',
55             'upload_date': '20140929',
56             'uploader': 'BCLETeens',
57             'timestamp': 1411997190,
58             'view_count': int,
59             'comment_count': int,
60         }
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         },
78     }]
79
80     def _real_extract(self, url):
81         video_id = self._match_id(url)
82
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
93         headers = {'Referer': 'http://static.cdn-ec.viddler.com/js/arpeggio/v2/embed.html'}
94         request = sanitized_Request(
95             'http://api.viddler.com/api/v2/viddler.videos.getPlaybackDetails.json?%s'
96             % compat_urllib_parse_urlencode(query), None, headers)
97         data = self._download_json(request, video_id)['video']
98
99         formats = []
100         for filed in data['files']:
101             if filed.get('status', 'ready') != 'ready':
102                 continue
103             format_id = filed.get('profile_id') or filed['profile_name']
104             f = {
105                 'format_id': format_id,
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()
118                 f['url'] = self._proto_relative_url(filed['cdn_url'], 'http:')
119                 f['format_id'] = format_id + '-cdn'
120                 f['source_preference'] = 1
121                 formats.append(f)
122
123             if filed.get('html5_video_source'):
124                 f = f.copy()
125                 f['url'] = self._proto_relative_url(filed['html5_video_source'])
126                 f['format_id'] = format_id + '-html5'
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]
133
134         return {
135             'id': video_id,
136             'title': data['title'],
137             'formats': formats,
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')),
144             'comment_count': int_or_none(data.get('comment_count')),
145             'categories': categories,
146         }