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