]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/pladform.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / pladform.py
CommitLineData
28778d6b
S
1from .common import InfoExtractor
2from ..utils import (
3c3bceb4 3 determine_ext,
28778d6b
S
4 ExtractorError,
5 int_or_none,
4dfbf869 6 parse_qs,
28778d6b 7 xpath_text,
11101076 8 qualities,
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,
38 'category': list,
39 'uploader_id': '12082',
40 'uploader': 'Comedy Club',
41 'duration': 367,
42 },
43 'expected_warnings': ['HTTP Error 404: Not Found']
44 }, {
3c3bceb4
S
45 'url': 'https://out.pladform.ru/player?pl=64471&videoid=3777899&vk_puid15=0&vk_puid34=0',
46 'md5': '53362fac3a27352da20fa2803cc5cd6f',
28778d6b 47 'info_dict': {
3c3bceb4 48 'id': '3777899',
28778d6b 49 'ext': 'mp4',
3c3bceb4
S
50 'title': 'СТУДИЯ СОЮЗ • Шоу Студия Союз, 24 выпуск (01.02.2018) Нурлан Сабуров и Слава Комиссаренко',
51 'description': 'md5:05140e8bf1b7e2d46e7ba140be57fd95',
ec85ded8 52 'thumbnail': r're:^https?://.*\.jpg$',
3c3bceb4 53 'duration': 3190,
28778d6b
S
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
4dfbf869 66 qs = parse_qs(url)
3c3bceb4
S
67 pl = qs.get('pl', ['1'])[0]
68
28778d6b 69 video = self._download_xml(
3c3bceb4
S
70 'http://out.pladform.ru/getVideo', video_id, query={
71 'pl': pl,
72 'videoid': video_id,
f7d48541 73 }, fatal=False)
28778d6b 74
3c3bceb4 75 def fail(text):
28778d6b 76 raise ExtractorError(
3c3bceb4 77 '%s returned error: %s' % (self.IE_NAME, text),
28778d6b
S
78 expected=True)
79
f7d48541
K
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
3c3bceb4
S
86 if video.tag == 'error':
87 fail(video.text)
88
11101076
S
89 quality = qualities(('ld', 'sd', 'hd'))
90
3c3bceb4
S
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
28778d6b
S
114 webpage = self._download_webpage(
115 'http://video.pladform.ru/catalog/video/videoid/%s' % video_id,
116 video_id)
117
118 title = self._og_search_title(webpage, fatal=False) or xpath_text(
119 video, './/title', 'title', fatal=True)
120 description = self._search_regex(
121 r'</h3>\s*<p>([^<]+)</p>', webpage, 'description', fatal=False)
122 thumbnail = self._og_search_thumbnail(webpage) or xpath_text(
123 video, './/cover', 'cover')
124
125 duration = int_or_none(xpath_text(video, './/time', 'duration'))
126 age_limit = int_or_none(xpath_text(video, './/age18', 'age limit'))
127
128 return {
129 'id': video_id,
130 'title': title,
131 'description': description,
132 'thumbnail': thumbnail,
133 'duration': duration,
134 'age_limit': age_limit,
135 'formats': formats,
136 }