]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | int_or_none, | |
9 | parse_iso8601, | |
10 | str_or_none, | |
11 | strip_or_none, | |
12 | try_get, | |
13 | ) | |
14 | ||
15 | ||
16 | class VidioIE(InfoExtractor): | |
17 | _VALID_URL = r'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)' | |
18 | _TESTS = [{ | |
19 | 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015', | |
20 | 'md5': 'cd2801394afc164e9775db6a140b91fe', | |
21 | 'info_dict': { | |
22 | 'id': '165683', | |
23 | 'display_id': 'dj_ambred-booyah-live-2015', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'DJ_AMBRED - Booyah (Live 2015)', | |
26 | 'description': 'md5:27dc15f819b6a78a626490881adbadf8', | |
27 | 'thumbnail': r're:^https?://.*\.jpg$', | |
28 | 'duration': 149, | |
29 | 'like_count': int, | |
30 | 'uploader': 'TWELVE Pic', | |
31 | 'timestamp': 1444902800, | |
32 | 'upload_date': '20151015', | |
33 | 'uploader_id': 'twelvepictures', | |
34 | 'channel': 'Cover Music Video', | |
35 | 'channel_id': '280236', | |
36 | 'view_count': int, | |
37 | 'dislike_count': int, | |
38 | 'comment_count': int, | |
39 | 'tags': 'count:4', | |
40 | }, | |
41 | }, { | |
42 | 'url': 'https://www.vidio.com/watch/77949-south-korea-test-fires-missile-that-can-strike-all-of-the-north', | |
43 | 'only_matching': True, | |
44 | }] | |
45 | ||
46 | def _real_initialize(self): | |
47 | self._api_key = self._download_json( | |
48 | 'https://www.vidio.com/auth', None, data=b'')['api_key'] | |
49 | ||
50 | def _real_extract(self, url): | |
51 | video_id, display_id = re.match(self._VALID_URL, url).groups() | |
52 | data = self._download_json( | |
53 | 'https://api.vidio.com/videos/' + video_id, display_id, headers={ | |
54 | 'Content-Type': 'application/vnd.api+json', | |
55 | 'X-API-KEY': self._api_key, | |
56 | }) | |
57 | video = data['videos'][0] | |
58 | title = video['title'].strip() | |
59 | ||
60 | formats = self._extract_m3u8_formats( | |
61 | data['clips'][0]['hls_url'], display_id, 'mp4', 'm3u8_native') | |
62 | self._sort_formats(formats) | |
63 | ||
64 | get_first = lambda x: try_get(data, lambda y: y[x + 's'][0], dict) or {} | |
65 | channel = get_first('channel') | |
66 | user = get_first('user') | |
67 | username = user.get('username') | |
68 | get_count = lambda x: int_or_none(video.get('total_' + x)) | |
69 | ||
70 | return { | |
71 | 'id': video_id, | |
72 | 'display_id': display_id, | |
73 | 'title': title, | |
74 | 'description': strip_or_none(video.get('description')), | |
75 | 'thumbnail': video.get('image_url_medium'), | |
76 | 'duration': int_or_none(video.get('duration')), | |
77 | 'like_count': get_count('likes'), | |
78 | 'formats': formats, | |
79 | 'uploader': user.get('name'), | |
80 | 'timestamp': parse_iso8601(video.get('created_at')), | |
81 | 'uploader_id': username, | |
82 | 'uploader_url': 'https://www.vidio.com/@' + username if username else None, | |
83 | 'channel': channel.get('name'), | |
84 | 'channel_id': str_or_none(channel.get('id')), | |
85 | 'view_count': get_count('view_count'), | |
86 | 'dislike_count': get_count('dislikes'), | |
87 | 'comment_count': get_count('comments'), | |
88 | 'tags': video.get('tag_list'), | |
89 | } |