]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
4 | format_field, | |
5 | int_or_none, | |
6 | js_to_json, | |
7 | try_get, | |
8 | ) | |
9 | ||
10 | ||
11 | class JojIE(InfoExtractor): | |
12 | _VALID_URL = r'''(?x) | |
13 | (?: | |
14 | joj:| | |
15 | https?://media\.joj\.sk/embed/ | |
16 | ) | |
17 | (?P<id>[^/?#^]+) | |
18 | ''' | |
19 | _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1'] | |
20 | _TESTS = [{ | |
21 | 'url': 'https://media.joj.sk/embed/a388ec4c-6019-4a4a-9312-b1bee194e932', | |
22 | 'info_dict': { | |
23 | 'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'NOVÉ BÝVANIE', | |
26 | 'thumbnail': r're:^https?://.*\.jpg$', | |
27 | 'duration': 3118, | |
28 | } | |
29 | }, { | |
30 | 'url': 'https://media.joj.sk/embed/9i1cxv', | |
31 | 'only_matching': True, | |
32 | }, { | |
33 | 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932', | |
34 | 'only_matching': True, | |
35 | }, { | |
36 | 'url': 'joj:9i1cxv', | |
37 | 'only_matching': True, | |
38 | }] | |
39 | ||
40 | def _real_extract(self, url): | |
41 | video_id = self._match_id(url) | |
42 | ||
43 | webpage = self._download_webpage( | |
44 | 'https://media.joj.sk/embed/%s' % video_id, video_id) | |
45 | ||
46 | title = self._search_regex( | |
47 | (r'videoTitle\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1', | |
48 | r'<title>(?P<title>[^<]+)'), webpage, 'title', | |
49 | default=None, group='title') or self._og_search_title(webpage) | |
50 | ||
51 | bitrates = self._parse_json( | |
52 | self._search_regex( | |
53 | r'(?s)(?:src|bitrates)\s*=\s*({.+?});', webpage, 'bitrates', | |
54 | default='{}'), | |
55 | video_id, transform_source=js_to_json, fatal=False) | |
56 | ||
57 | formats = [] | |
58 | for format_url in try_get(bitrates, lambda x: x['mp4'], list) or []: | |
59 | if isinstance(format_url, compat_str): | |
60 | height = self._search_regex( | |
61 | r'(\d+)[pP]\.', format_url, 'height', default=None) | |
62 | formats.append({ | |
63 | 'url': format_url, | |
64 | 'format_id': format_field(height, None, '%sp'), | |
65 | 'height': int(height), | |
66 | }) | |
67 | if not formats: | |
68 | playlist = self._download_xml( | |
69 | 'https://media.joj.sk/services/Video.php?clip=%s' % video_id, | |
70 | video_id) | |
71 | for file_el in playlist.findall('./files/file'): | |
72 | path = file_el.get('path') | |
73 | if not path: | |
74 | continue | |
75 | format_id = file_el.get('id') or file_el.get('label') | |
76 | formats.append({ | |
77 | 'url': 'http://n16.joj.sk/storage/%s' % path.replace( | |
78 | 'dat/', '', 1), | |
79 | 'format_id': format_id, | |
80 | 'height': int_or_none(self._search_regex( | |
81 | r'(\d+)[pP]', format_id or path, 'height', | |
82 | default=None)), | |
83 | }) | |
84 | ||
85 | thumbnail = self._og_search_thumbnail(webpage) | |
86 | ||
87 | duration = int_or_none(self._search_regex( | |
88 | r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False)) | |
89 | ||
90 | return { | |
91 | 'id': video_id, | |
92 | 'title': title, | |
93 | 'thumbnail': thumbnail, | |
94 | 'duration': duration, | |
95 | 'formats': formats, | |
96 | } |