]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/joj.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / joj.py
1 from .common import InfoExtractor
2 from ..utils import (
3 format_field,
4 int_or_none,
5 js_to_json,
6 try_get,
7 )
8
9
10 class JojIE(InfoExtractor):
11 _VALID_URL = r'''(?x)
12 (?:
13 joj:|
14 https?://media\.joj\.sk/embed/
15 )
16 (?P<id>[^/?#^]+)
17 '''
18 _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1']
19 _TESTS = [{
20 'url': 'https://media.joj.sk/embed/a388ec4c-6019-4a4a-9312-b1bee194e932',
21 'info_dict': {
22 'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932',
23 'ext': 'mp4',
24 'title': 'NOVÉ BÝVANIE',
25 'thumbnail': r're:^https?://.*?$',
26 'duration': 3118,
27 },
28 }, {
29 'url': 'https://media.joj.sk/embed/CSM0Na0l0p1',
30 'info_dict': {
31 'id': 'CSM0Na0l0p1',
32 'ext': 'mp4',
33 'height': 576,
34 'title': 'Extrémne rodiny 2 - POKRAČOVANIE (2012/04/09 21:30:00)',
35 'duration': 3937,
36 'thumbnail': r're:^https?://.*?$',
37 },
38 }, {
39 'url': 'https://media.joj.sk/embed/9i1cxv',
40 'only_matching': True,
41 }, {
42 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932',
43 'only_matching': True,
44 }, {
45 'url': 'joj:9i1cxv',
46 'only_matching': True,
47 }]
48
49 def _real_extract(self, url):
50 video_id = self._match_id(url)
51
52 webpage = self._download_webpage(
53 f'https://media.joj.sk/embed/{video_id}', video_id)
54
55 title = (self._search_json(r'videoTitle\s*:', webpage, 'title', video_id,
56 contains_pattern=r'["\'].+["\']', default=None)
57 or self._html_extract_title(webpage, default=None)
58 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, str):
69 height = self._search_regex(
70 r'(\d+)[pP]|(pal)\.', format_url, 'height', default=None)
71 if height == 'pal':
72 height = 576
73 formats.append({
74 'url': format_url,
75 'format_id': format_field(height, None, '%sp'),
76 'height': int_or_none(height),
77 })
78 if not formats:
79 playlist = self._download_xml(
80 f'https://media.joj.sk/services/Video.php?clip={video_id}',
81 video_id)
82 for file_el in playlist.findall('./files/file'):
83 path = file_el.get('path')
84 if not path:
85 continue
86 format_id = file_el.get('id') or file_el.get('label')
87 formats.append({
88 'url': 'http://n16.joj.sk/storage/{}'.format(path.replace(
89 'dat/', '', 1)),
90 'format_id': format_id,
91 'height': int_or_none(self._search_regex(
92 r'(\d+)[pP]', format_id or path, 'height',
93 default=None)),
94 })
95
96 thumbnail = self._og_search_thumbnail(webpage)
97
98 duration = int_or_none(self._search_regex(
99 r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
100
101 return {
102 'id': video_id,
103 'title': title,
104 'thumbnail': thumbnail,
105 'duration': duration,
106 'formats': formats,
107 }