]>
Commit | Line | Data |
---|---|---|
7def3571 T |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
7def3571 | 5 | |
0fc832e1 | 6 | from .common import InfoExtractor |
2181983a | 7 | from ..utils import ( |
8 | int_or_none, | |
9 | parse_iso8601, | |
10 | str_or_none, | |
11 | strip_or_none, | |
12 | try_get, | |
13 | ) | |
7def3571 T |
14 | |
15 | ||
16 | class VidioIE(InfoExtractor): | |
0fc832e1 S |
17 | _VALID_URL = r'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)' |
18 | _TESTS = [{ | |
7def3571 | 19 | 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015', |
0fc832e1 | 20 | 'md5': 'cd2801394afc164e9775db6a140b91fe', |
7def3571 T |
21 | 'info_dict': { |
22 | 'id': '165683', | |
0fc832e1 | 23 | 'display_id': 'dj_ambred-booyah-live-2015', |
7def3571 | 24 | 'ext': 'mp4', |
0fc832e1 | 25 | 'title': 'DJ_AMBRED - Booyah (Live 2015)', |
7def3571 | 26 | 'description': 'md5:27dc15f819b6a78a626490881adbadf8', |
ec85ded8 | 27 | 'thumbnail': r're:^https?://.*\.jpg$', |
0fc832e1 S |
28 | 'duration': 149, |
29 | 'like_count': int, | |
2181983a | 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', | |
7def3571 | 40 | }, |
0fc832e1 S |
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 | }] | |
7def3571 | 45 | |
2181983a | 46 | def _real_initialize(self): |
47 | self._api_key = self._download_json( | |
48 | 'https://www.vidio.com/auth', None, data=b'')['api_key'] | |
0fc832e1 | 49 | |
2181983a | 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() | |
0fc832e1 | 59 | |
07ad0cf3 | 60 | formats = self._extract_m3u8_formats( |
2181983a | 61 | data['clips'][0]['hls_url'], display_id, 'mp4', 'm3u8_native') |
07ad0cf3 | 62 | self._sort_formats(formats) |
0fc832e1 | 63 | |
2181983a | 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)) | |
7def3571 T |
69 | |
70 | return { | |
71 | 'id': video_id, | |
0fc832e1 S |
72 | 'display_id': display_id, |
73 | 'title': title, | |
2181983a | 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'), | |
0fc832e1 | 78 | 'formats': formats, |
2181983a | 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'), | |
7def3571 | 89 | } |