]>
Commit | Line | Data |
---|---|---|
cefecac1 U |
1 | from .common import InfoExtractor |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
e0ddbd02 | 4 | format_field, |
cefecac1 U |
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 | ''' | |
bfd973ec | 19 | _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1'] |
cefecac1 U |
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', | |
1a3cd8ec | 26 | 'thumbnail': r're:^https?://.*?$', |
cefecac1 U |
27 | 'duration': 3118, |
28 | } | |
1a3cd8ec O |
29 | }, { |
30 | 'url': 'https://media.joj.sk/embed/CSM0Na0l0p1', | |
31 | 'info_dict': { | |
32 | 'id': 'CSM0Na0l0p1', | |
33 | 'ext': 'mp4', | |
34 | 'height': 576, | |
35 | 'title': 'Extrémne rodiny 2 - POKRAČOVANIE (2012/04/09 21:30:00)', | |
36 | 'duration': 3937, | |
37 | 'thumbnail': r're:^https?://.*?$', | |
38 | } | |
cefecac1 U |
39 | }, { |
40 | 'url': 'https://media.joj.sk/embed/9i1cxv', | |
41 | 'only_matching': True, | |
42 | }, { | |
43 | 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932', | |
44 | 'only_matching': True, | |
45 | }, { | |
46 | 'url': 'joj:9i1cxv', | |
47 | 'only_matching': True, | |
48 | }] | |
49 | ||
cefecac1 U |
50 | def _real_extract(self, url): |
51 | video_id = self._match_id(url) | |
52 | ||
53 | webpage = self._download_webpage( | |
54 | 'https://media.joj.sk/embed/%s' % video_id, video_id) | |
55 | ||
1a3cd8ec O |
56 | title = (self._search_json(r'videoTitle\s*:', webpage, 'title', video_id, |
57 | contains_pattern=r'["\'].+["\']', default=None) | |
58 | or self._html_extract_title(webpage, default=None) | |
59 | or self._og_search_title(webpage)) | |
cefecac1 U |
60 | |
61 | bitrates = self._parse_json( | |
62 | self._search_regex( | |
63 | r'(?s)(?:src|bitrates)\s*=\s*({.+?});', webpage, 'bitrates', | |
64 | default='{}'), | |
65 | video_id, transform_source=js_to_json, fatal=False) | |
66 | ||
67 | formats = [] | |
68 | for format_url in try_get(bitrates, lambda x: x['mp4'], list) or []: | |
69 | if isinstance(format_url, compat_str): | |
70 | height = self._search_regex( | |
1a3cd8ec O |
71 | r'(\d+)[pP]|(pal)\.', format_url, 'height', default=None) |
72 | if height == 'pal': | |
73 | height = 576 | |
cefecac1 U |
74 | formats.append({ |
75 | 'url': format_url, | |
a70635b8 | 76 | 'format_id': format_field(height, None, '%sp'), |
1a3cd8ec | 77 | 'height': int_or_none(height), |
cefecac1 U |
78 | }) |
79 | if not formats: | |
80 | playlist = self._download_xml( | |
81 | 'https://media.joj.sk/services/Video.php?clip=%s' % video_id, | |
82 | video_id) | |
83 | for file_el in playlist.findall('./files/file'): | |
84 | path = file_el.get('path') | |
85 | if not path: | |
86 | continue | |
87 | format_id = file_el.get('id') or file_el.get('label') | |
88 | formats.append({ | |
89 | 'url': 'http://n16.joj.sk/storage/%s' % path.replace( | |
90 | 'dat/', '', 1), | |
91 | 'format_id': format_id, | |
92 | 'height': int_or_none(self._search_regex( | |
93 | r'(\d+)[pP]', format_id or path, 'height', | |
94 | default=None)), | |
95 | }) | |
cefecac1 U |
96 | |
97 | thumbnail = self._og_search_thumbnail(webpage) | |
98 | ||
99 | duration = int_or_none(self._search_regex( | |
100 | r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False)) | |
101 | ||
102 | return { | |
103 | 'id': video_id, | |
104 | 'title': title, | |
105 | 'thumbnail': thumbnail, | |
106 | 'duration': duration, | |
107 | 'formats': formats, | |
108 | } |