]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/pladform.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / pladform.py
CommitLineData
28778d6b
S
1from .common import InfoExtractor
2from ..utils import (
3 ExtractorError,
e897bd82 4 determine_ext,
28778d6b 5 int_or_none,
4dfbf869 6 parse_qs,
11101076 7 qualities,
e897bd82 8 xpath_text,
28778d6b
S
9)
10
11
12class PladformIE(InfoExtractor):
13 _VALID_URL = r'''(?x)
14 https?://
15 (?:
16 (?:
17 out\.pladform\.ru/player|
18 static\.pladform\.ru/player\.swf
19 )
20 \?.*\bvideoid=|
21 video\.pladform\.ru/catalog/video/videoid/
22 )
23 (?P<id>\d+)
24 '''
bfd973ec 25 _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//out\.pladform\.ru/player\?.+?)\1']
28778d6b 26 _TESTS = [{
f7d48541
K
27 'url': 'http://out.pladform.ru/player?pl=18079&type=html5&videoid=100231282',
28 'info_dict': {
29 'id': '6216d548e755edae6e8280667d774791',
30 'ext': 'mp4',
31 'timestamp': 1406117012,
32 'title': 'Гарик Мартиросян и Гарик Харламов - Кастинг на концерт ко Дню милиции',
33 'age_limit': 0,
34 'upload_date': '20140723',
35 'thumbnail': str,
36 'view_count': int,
37 'description': str,
f7d48541
K
38 'uploader_id': '12082',
39 'uploader': 'Comedy Club',
40 'duration': 367,
41 },
42 'expected_warnings': ['HTTP Error 404: Not Found']
43 }, {
3c3bceb4
S
44 'url': 'https://out.pladform.ru/player?pl=64471&videoid=3777899&vk_puid15=0&vk_puid34=0',
45 'md5': '53362fac3a27352da20fa2803cc5cd6f',
28778d6b 46 'info_dict': {
3c3bceb4 47 'id': '3777899',
28778d6b 48 'ext': 'mp4',
3c3bceb4
S
49 'title': 'СТУДИЯ СОЮЗ • Шоу Студия Союз, 24 выпуск (01.02.2018) Нурлан Сабуров и Слава Комиссаренко',
50 'description': 'md5:05140e8bf1b7e2d46e7ba140be57fd95',
ec85ded8 51 'thumbnail': r're:^https?://.*\.jpg$',
3c3bceb4 52 'duration': 3190,
28778d6b
S
53 },
54 }, {
55 'url': 'http://static.pladform.ru/player.swf?pl=21469&videoid=100183293&vkcid=0',
56 'only_matching': True,
57 }, {
58 'url': 'http://video.pladform.ru/catalog/video/videoid/100183293/vkcid/0',
59 'only_matching': True,
60 }]
61
62 def _real_extract(self, url):
63 video_id = self._match_id(url)
64
4dfbf869 65 qs = parse_qs(url)
3c3bceb4
S
66 pl = qs.get('pl', ['1'])[0]
67
28778d6b 68 video = self._download_xml(
3c3bceb4
S
69 'http://out.pladform.ru/getVideo', video_id, query={
70 'pl': pl,
71 'videoid': video_id,
f7d48541 72 }, fatal=False)
28778d6b 73
3c3bceb4 74 def fail(text):
28778d6b 75 raise ExtractorError(
3c3bceb4 76 '%s returned error: %s' % (self.IE_NAME, text),
28778d6b
S
77 expected=True)
78
f7d48541 79 if not video:
3d2623a8 80 targetUrl = self._request_webpage(url, video_id, note='Resolving final URL').url
f7d48541
K
81 if targetUrl == url:
82 raise ExtractorError('Can\'t parse page')
83 return self.url_result(targetUrl)
84
3c3bceb4
S
85 if video.tag == 'error':
86 fail(video.text)
87
11101076
S
88 quality = qualities(('ld', 'sd', 'hd'))
89
3c3bceb4
S
90 formats = []
91 for src in video.findall('./src'):
92 if src is None:
93 continue
94 format_url = src.text
95 if not format_url:
96 continue
97 if src.get('type') == 'hls' or determine_ext(format_url) == 'm3u8':
98 formats.extend(self._extract_m3u8_formats(
99 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
100 m3u8_id='hls', fatal=False))
101 else:
102 formats.append({
103 'url': src.text,
104 'format_id': src.get('quality'),
105 'quality': quality(src.get('quality')),
106 })
107
108 if not formats:
109 error = xpath_text(video, './cap', 'error', default=None)
110 if error:
111 fail(error)
112
28778d6b
S
113 webpage = self._download_webpage(
114 'http://video.pladform.ru/catalog/video/videoid/%s' % video_id,
115 video_id)
116
117 title = self._og_search_title(webpage, fatal=False) or xpath_text(
118 video, './/title', 'title', fatal=True)
119 description = self._search_regex(
120 r'</h3>\s*<p>([^<]+)</p>', webpage, 'description', fatal=False)
121 thumbnail = self._og_search_thumbnail(webpage) or xpath_text(
122 video, './/cover', 'cover')
123
124 duration = int_or_none(xpath_text(video, './/time', 'duration'))
125 age_limit = int_or_none(xpath_text(video, './/age18', 'age limit'))
126
127 return {
128 'id': video_id,
129 'title': title,
130 'description': description,
131 'thumbnail': thumbnail,
132 'duration': duration,
133 'age_limit': age_limit,
134 'formats': formats,
135 }