]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/pladform.py
[extractors] Use new framework for existing embeds (#4307)
[yt-dlp.git] / yt_dlp / extractor / pladform.py
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 ExtractorError,
5 int_or_none,
6 parse_qs,
7 xpath_text,
8 qualities,
9 )
10
11
12 class 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 '''
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 'category': list,
39 'uploader_id': '12082',
40 'uploader': 'Comedy Club',
41 'duration': 367,
42 },
43 'expected_warnings': ['HTTP Error 404: Not Found']
44 }, {
45 'url': 'https://out.pladform.ru/player?pl=64471&videoid=3777899&vk_puid15=0&vk_puid34=0',
46 'md5': '53362fac3a27352da20fa2803cc5cd6f',
47 'info_dict': {
48 'id': '3777899',
49 'ext': 'mp4',
50 'title': 'СТУДИЯ СОЮЗ • Шоу Студия Союз, 24 выпуск (01.02.2018) Нурлан Сабуров и Слава Комиссаренко',
51 'description': 'md5:05140e8bf1b7e2d46e7ba140be57fd95',
52 'thumbnail': r're:^https?://.*\.jpg$',
53 'duration': 3190,
54 },
55 }, {
56 'url': 'http://static.pladform.ru/player.swf?pl=21469&videoid=100183293&vkcid=0',
57 'only_matching': True,
58 }, {
59 'url': 'http://video.pladform.ru/catalog/video/videoid/100183293/vkcid/0',
60 'only_matching': True,
61 }]
62
63 def _real_extract(self, url):
64 video_id = self._match_id(url)
65
66 qs = parse_qs(url)
67 pl = qs.get('pl', ['1'])[0]
68
69 video = self._download_xml(
70 'http://out.pladform.ru/getVideo', video_id, query={
71 'pl': pl,
72 'videoid': video_id,
73 }, fatal=False)
74
75 def fail(text):
76 raise ExtractorError(
77 '%s returned error: %s' % (self.IE_NAME, text),
78 expected=True)
79
80 if not video:
81 targetUrl = self._request_webpage(url, video_id, note='Resolving final URL').geturl()
82 if targetUrl == url:
83 raise ExtractorError('Can\'t parse page')
84 return self.url_result(targetUrl)
85
86 if video.tag == 'error':
87 fail(video.text)
88
89 quality = qualities(('ld', 'sd', 'hd'))
90
91 formats = []
92 for src in video.findall('./src'):
93 if src is None:
94 continue
95 format_url = src.text
96 if not format_url:
97 continue
98 if src.get('type') == 'hls' or determine_ext(format_url) == 'm3u8':
99 formats.extend(self._extract_m3u8_formats(
100 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
101 m3u8_id='hls', fatal=False))
102 else:
103 formats.append({
104 'url': src.text,
105 'format_id': src.get('quality'),
106 'quality': quality(src.get('quality')),
107 })
108
109 if not formats:
110 error = xpath_text(video, './cap', 'error', default=None)
111 if error:
112 fail(error)
113
114 self._sort_formats(formats)
115
116 webpage = self._download_webpage(
117 'http://video.pladform.ru/catalog/video/videoid/%s' % video_id,
118 video_id)
119
120 title = self._og_search_title(webpage, fatal=False) or xpath_text(
121 video, './/title', 'title', fatal=True)
122 description = self._search_regex(
123 r'</h3>\s*<p>([^<]+)</p>', webpage, 'description', fatal=False)
124 thumbnail = self._og_search_thumbnail(webpage) or xpath_text(
125 video, './/cover', 'cover')
126
127 duration = int_or_none(xpath_text(video, './/time', 'duration'))
128 age_limit = int_or_none(xpath_text(video, './/age18', 'age limit'))
129
130 return {
131 'id': video_id,
132 'title': title,
133 'description': description,
134 'thumbnail': thumbnail,
135 'duration': duration,
136 'age_limit': age_limit,
137 'formats': formats,
138 }