[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / joj.py
blobea46042404148b44c45c5f4292a36d43d070e780
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,
11 class JojIE(InfoExtractor):
12 _VALID_URL = r'''(?x)
13 (?:
14 joj:|
15 https?://media\.joj\.sk/embed/
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?://.*?$',
27 'duration': 3118,
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?://.*?$',
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,
50 def _real_extract(self, url):
51 video_id = self._match_id(url)
53 webpage = self._download_webpage(
54 'https://media.joj.sk/embed/%s' % video_id, video_id)
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))
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)
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(
71 r'(\d+)[pP]|(pal)\.', format_url, 'height', default=None)
72 if height == 'pal':
73 height = 576
74 formats.append({
75 'url': format_url,
76 'format_id': format_field(height, None, '%sp'),
77 'height': int_or_none(height),
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)),
97 thumbnail = self._og_search_thumbnail(webpage)
99 duration = int_or_none(self._search_regex(
100 r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
102 return {
103 'id': video_id,
104 'title': title,
105 'thumbnail': thumbnail,
106 'duration': duration,
107 'formats': formats,