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