]>
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 |
7def3571 T |
7 | from ..utils import int_or_none |
8 | ||
9 | ||
10 | class VidioIE(InfoExtractor): | |
0fc832e1 S |
11 | _VALID_URL = r'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)' |
12 | _TESTS = [{ | |
7def3571 | 13 | 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015', |
0fc832e1 | 14 | 'md5': 'cd2801394afc164e9775db6a140b91fe', |
7def3571 T |
15 | 'info_dict': { |
16 | 'id': '165683', | |
0fc832e1 | 17 | 'display_id': 'dj_ambred-booyah-live-2015', |
7def3571 | 18 | 'ext': 'mp4', |
0fc832e1 | 19 | 'title': 'DJ_AMBRED - Booyah (Live 2015)', |
7def3571 | 20 | 'description': 'md5:27dc15f819b6a78a626490881adbadf8', |
ec85ded8 | 21 | 'thumbnail': r're:^https?://.*\.jpg$', |
0fc832e1 S |
22 | 'duration': 149, |
23 | 'like_count': int, | |
7def3571 | 24 | }, |
0fc832e1 S |
25 | }, { |
26 | 'url': 'https://www.vidio.com/watch/77949-south-korea-test-fires-missile-that-can-strike-all-of-the-north', | |
27 | 'only_matching': True, | |
28 | }] | |
7def3571 T |
29 | |
30 | def _real_extract(self, url): | |
31 | mobj = re.match(self._VALID_URL, url) | |
32 | video_id, display_id = mobj.group('id', 'display_id') | |
33 | ||
34 | webpage = self._download_webpage(url, display_id) | |
35 | ||
0fc832e1 S |
36 | title = self._og_search_title(webpage) |
37 | ||
38 | m3u8_url, duration, thumbnail = [None] * 3 | |
7def3571 | 39 | |
0fc832e1 S |
40 | clips = self._parse_json( |
41 | self._html_search_regex( | |
42 | r'data-json-clips\s*=\s*(["\'])(?P<data>\[.+?\])\1', | |
43 | webpage, 'video data', default='[]', group='data'), | |
44 | display_id, fatal=False) | |
45 | if clips: | |
46 | clip = clips[0] | |
47 | m3u8_url = clip.get('sources', [{}])[0].get('file') | |
48 | duration = clip.get('clip_duration') | |
49 | thumbnail = clip.get('image') | |
50 | ||
51 | m3u8_url = m3u8_url or self._search_regex( | |
2acc11d7 S |
52 | r'data(?:-vjs)?-clip-hls-url=(["\'])(?P<url>(?:(?!\1).)+)\1', |
53 | webpage, 'hls url', group='url') | |
07ad0cf3 S |
54 | formats = self._extract_m3u8_formats( |
55 | m3u8_url, display_id, 'mp4', entry_protocol='m3u8_native') | |
56 | self._sort_formats(formats) | |
0fc832e1 S |
57 | |
58 | duration = int_or_none(duration or self._search_regex( | |
935d6c20 S |
59 | r'data-video-duration=(["\'])(?P<duration>\d+)\1', webpage, |
60 | 'duration', fatal=False, group='duration')) | |
0fc832e1 S |
61 | thumbnail = thumbnail or self._og_search_thumbnail(webpage) |
62 | ||
63 | like_count = int_or_none(self._search_regex( | |
64 | (r'<span[^>]+data-comment-vote-count=["\'](\d+)', | |
65 | r'<span[^>]+class=["\'].*?\blike(?:__|-)count\b.*?["\'][^>]*>\s*(\d+)'), | |
66 | webpage, 'like count', fatal=False)) | |
7def3571 T |
67 | |
68 | return { | |
69 | 'id': video_id, | |
0fc832e1 S |
70 | 'display_id': display_id, |
71 | 'title': title, | |
7def3571 | 72 | 'description': self._og_search_description(webpage), |
0fc832e1 S |
73 | 'thumbnail': thumbnail, |
74 | 'duration': duration, | |
75 | 'like_count': like_count, | |
76 | 'formats': formats, | |
7def3571 | 77 | } |