[ie/dplay] Fix extractors (#10471)
[yt-dlp3.git] / yt_dlp / extractor / pladform.py
blobf4355d0cf5141add2c6a6d0636ecb5d6087be00b
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 determine_ext,
5 int_or_none,
6 parse_qs,
7 qualities,
8 xpath_text,
12 class PladformIE(InfoExtractor):
13 _VALID_URL = r'''(?x)
14 https?://
15 (?:
16 (?:
17 out\.pladform\.ru/player|
18 static\.pladform\.ru/player\.swf
20 \?.*\bvideoid=|
21 video\.pladform\.ru/catalog/video/videoid/
23 (?P<id>\d+)
24 '''
25 _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//out\.pladform\.ru/player\?.+?)\1']
26 _TESTS = [{
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,
38 'uploader_id': '12082',
39 'uploader': 'Comedy Club',
40 'duration': 367,
42 'expected_warnings': ['HTTP Error 404: Not Found'],
43 }, {
44 'url': 'https://out.pladform.ru/player?pl=64471&videoid=3777899&vk_puid15=0&vk_puid34=0',
45 'md5': '53362fac3a27352da20fa2803cc5cd6f',
46 'info_dict': {
47 'id': '3777899',
48 'ext': 'mp4',
49 'title': 'СТУДИЯ СОЮЗ • Шоу Студия Союз, 24 выпуск (01.02.2018) Нурлан Сабуров и Слава Комиссаренко',
50 'description': 'md5:05140e8bf1b7e2d46e7ba140be57fd95',
51 'thumbnail': r're:^https?://.*\.jpg$',
52 'duration': 3190,
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,
62 def _real_extract(self, url):
63 video_id = self._match_id(url)
65 qs = parse_qs(url)
66 pl = qs.get('pl', ['1'])[0]
68 video = self._download_xml(
69 'http://out.pladform.ru/getVideo', video_id, query={
70 'pl': pl,
71 'videoid': video_id,
72 }, fatal=False)
74 def fail(text):
75 raise ExtractorError(
76 f'{self.IE_NAME} returned error: {text}',
77 expected=True)
79 if not video:
80 target_url = self._request_webpage(url, video_id, note='Resolving final URL').url
81 if target_url == url:
82 raise ExtractorError('Can\'t parse page')
83 return self.url_result(target_url)
85 if video.tag == 'error':
86 fail(video.text)
88 quality = qualities(('ld', 'sd', 'hd'))
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')),
108 if not formats:
109 error = xpath_text(video, './cap', 'error', default=None)
110 if error:
111 fail(error)
113 webpage = self._download_webpage(
114 f'http://video.pladform.ru/catalog/video/videoid/{video_id}',
115 video_id)
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')
124 duration = int_or_none(xpath_text(video, './/time', 'duration'))
125 age_limit = int_or_none(xpath_text(video, './/age18', 'age limit'))
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,