]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/videomore.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / videomore.py
1 from .common import InfoExtractor
2 from ..compat import (
3 compat_str,
4 )
5 from ..utils import (
6 int_or_none,
7 parse_qs,
8 )
9
10
11 class VideomoreBaseIE(InfoExtractor):
12 _API_BASE_URL = 'https://more.tv/api/v3/web/'
13 _VALID_URL_BASE = r'https?://(?:videomore\.ru|more\.tv)/'
14
15 def _download_page_data(self, display_id):
16 return self._download_json(
17 self._API_BASE_URL + 'PageData', display_id, query={
18 'url': '/' + display_id,
19 })['attributes']['response']['data']
20
21 def _track_url_result(self, track):
22 track_vod = track['trackVod']
23 video_url = track_vod.get('playerLink') or track_vod['link']
24 return self.url_result(
25 video_url, VideomoreIE.ie_key(), track_vod.get('hubId'))
26
27
28 class VideomoreIE(InfoExtractor):
29 IE_NAME = 'videomore'
30 _VALID_URL = r'''(?x)
31 videomore:(?P<sid>\d+)$|
32 https?://
33 (?:
34 videomore\.ru/
35 (?:
36 embed|
37 [^/]+/[^/]+
38 )/|
39 (?:
40 (?:player\.)?videomore\.ru|
41 siren\.more\.tv/player
42 )/[^/]*\?.*?\btrack_id=|
43 odysseus\.more.tv/player/(?P<partner_id>\d+)/
44 )
45 (?P<id>\d+)
46 (?:[/?#&]|\.(?:xml|json)|$)
47 '''
48 _EMBED_REGEX = [r'''(?x)
49 (?:
50 <iframe[^>]+src=([\'"])|
51 <object[^>]+data=(["\'])https?://videomore\.ru/player\.swf\?.*config=
52 )(?P<url>https?://videomore\.ru/[^?#"']+/\d+(?:\.xml)?)
53 ''']
54 _TESTS = [{
55 'url': 'http://videomore.ru/kino_v_detalayah/5_sezon/367617',
56 'md5': '44455a346edc0d509ac5b5a5b531dc35',
57 'info_dict': {
58 'id': '367617',
59 'ext': 'flv',
60 'title': 'Кино в деталях 5 сезон В гостях Алексей Чумаков и Юлия Ковальчук',
61 'series': 'Кино в деталях',
62 'episode': 'В гостях Алексей Чумаков и Юлия Ковальчук',
63 'thumbnail': r're:^https?://.*\.jpg',
64 'duration': 2910,
65 'view_count': int,
66 'comment_count': int,
67 'age_limit': 16,
68 },
69 'skip': 'The video is not available for viewing.',
70 }, {
71 'url': 'http://videomore.ru/embed/259974',
72 'info_dict': {
73 'id': '259974',
74 'ext': 'mp4',
75 'title': 'Молодежка 2 сезон 40 серия',
76 'series': 'Молодежка',
77 'season': '2 сезон',
78 'episode': '40 серия',
79 'thumbnail': r're:^https?://.*\.jpg',
80 'duration': 2789,
81 'view_count': int,
82 'age_limit': 16,
83 },
84 'params': {
85 'skip_download': True,
86 },
87 }, {
88 'url': 'http://videomore.ru/molodezhka/sezon_promo/341073',
89 'info_dict': {
90 'id': '341073',
91 'ext': 'flv',
92 'title': 'Промо Команда проиграла из-за Бакина?',
93 'episode': 'Команда проиграла из-за Бакина?',
94 'thumbnail': r're:^https?://.*\.jpg',
95 'duration': 29,
96 'age_limit': 16,
97 'view_count': int,
98 },
99 'params': {
100 'skip_download': True,
101 },
102 'skip': 'The video is not available for viewing.',
103 }, {
104 'url': 'http://videomore.ru/elki_3?track_id=364623',
105 'only_matching': True,
106 }, {
107 'url': 'http://videomore.ru/embed/364623',
108 'only_matching': True,
109 }, {
110 'url': 'http://videomore.ru/video/tracks/364623.xml',
111 'only_matching': True,
112 }, {
113 'url': 'http://videomore.ru/video/tracks/364623.json',
114 'only_matching': True,
115 }, {
116 'url': 'http://videomore.ru/video/tracks/158031/quotes/33248',
117 'only_matching': True,
118 }, {
119 'url': 'videomore:367617',
120 'only_matching': True,
121 }, {
122 'url': 'https://player.videomore.ru/?partner_id=97&track_id=736234&autoplay=0&userToken=',
123 'only_matching': True,
124 }, {
125 'url': 'https://odysseus.more.tv/player/1788/352317',
126 'only_matching': True,
127 }, {
128 'url': 'https://siren.more.tv/player/config?track_id=352317&partner_id=1788&user_token=',
129 'only_matching': True,
130 }]
131 _GEO_BYPASS = False
132
133 def _real_extract(self, url):
134 mobj = self._match_valid_url(url)
135 video_id = mobj.group('sid') or mobj.group('id')
136 partner_id = mobj.group('partner_id') or parse_qs(url).get('partner_id', [None])[0] or '97'
137
138 item = self._download_json(
139 'https://siren.more.tv/player/config', video_id, query={
140 'partner_id': partner_id,
141 'track_id': video_id,
142 })['data']['playlist']['items'][0]
143
144 title = item.get('title')
145 series = item.get('project_name')
146 season = item.get('season_name')
147 episode = item.get('episode_name')
148 if not title:
149 title = []
150 for v in (series, season, episode):
151 if v:
152 title.append(v)
153 title = ' '.join(title)
154
155 streams = item.get('streams') or []
156 for protocol in ('DASH', 'HLS'):
157 stream_url = item.get(protocol.lower() + '_url')
158 if stream_url:
159 streams.append({'protocol': protocol, 'url': stream_url})
160
161 formats = []
162 for stream in streams:
163 stream_url = stream.get('url')
164 if not stream_url:
165 continue
166 protocol = stream.get('protocol')
167 if protocol == 'DASH':
168 formats.extend(self._extract_mpd_formats(
169 stream_url, video_id, mpd_id='dash', fatal=False))
170 elif protocol == 'HLS':
171 formats.extend(self._extract_m3u8_formats(
172 stream_url, video_id, 'mp4', 'm3u8_native',
173 m3u8_id='hls', fatal=False))
174 elif protocol == 'MSS':
175 formats.extend(self._extract_ism_formats(
176 stream_url, video_id, ism_id='mss', fatal=False))
177
178 if not formats:
179 error = item.get('error')
180 if error:
181 if error in ('Данное видео недоступно для просмотра на территории этой страны', 'Данное видео доступно для просмотра только на территории России'):
182 self.raise_geo_restricted(countries=['RU'], metadata_available=True)
183 self.raise_no_formats(error, expected=True)
184
185 return {
186 'id': video_id,
187 'title': title,
188 'series': series,
189 'season': season,
190 'episode': episode,
191 'thumbnail': item.get('thumbnail_url'),
192 'duration': int_or_none(item.get('duration')),
193 'view_count': int_or_none(item.get('views')),
194 'age_limit': int_or_none(item.get('min_age')),
195 'formats': formats,
196 }
197
198
199 class VideomoreVideoIE(VideomoreBaseIE):
200 IE_NAME = 'videomore:video'
201 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?P<id>(?:(?:[^/]+/){2})?[^/?#&]+)(?:/*|[?#&].*?)$'
202 _TESTS = [{
203 # single video with og:video:iframe
204 'url': 'http://videomore.ru/elki_3',
205 'info_dict': {
206 'id': '364623',
207 'ext': 'flv',
208 'title': 'Ёлки 3',
209 'description': '',
210 'thumbnail': r're:^https?://.*\.jpg',
211 'duration': 5579,
212 'age_limit': 6,
213 'view_count': int,
214 },
215 'params': {
216 'skip_download': True,
217 },
218 'skip': 'Requires logging in',
219 }, {
220 # season single series with og:video:iframe
221 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
222 'info_dict': {
223 'id': '352317',
224 'ext': 'mp4',
225 'title': 'Последний мент 1 сезон 14 серия',
226 'series': 'Последний мент',
227 'season': '1 сезон',
228 'episode': '14 серия',
229 'thumbnail': r're:^https?://.*\.jpg',
230 'duration': 2464,
231 'age_limit': 16,
232 'view_count': int,
233 },
234 'params': {
235 'skip_download': True,
236 },
237 }, {
238 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
239 'only_matching': True,
240 }, {
241 # single video without og:video:iframe
242 'url': 'http://videomore.ru/marin_i_ego_druzya',
243 'info_dict': {
244 'id': '359073',
245 'ext': 'flv',
246 'title': '1 серия. Здравствуй, Аквавилль!',
247 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
248 'thumbnail': r're:^https?://.*\.jpg',
249 'duration': 754,
250 'age_limit': 6,
251 'view_count': int,
252 },
253 'params': {
254 'skip_download': True,
255 },
256 'skip': 'redirects to https://more.tv/'
257 }, {
258 'url': 'https://videomore.ru/molodezhka/6_sezon/29_seriya?utm_so',
259 'only_matching': True,
260 }, {
261 'url': 'https://more.tv/poslednii_ment/1_sezon/14_seriya',
262 'only_matching': True,
263 }]
264
265 @classmethod
266 def suitable(cls, url):
267 return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
268
269 def _real_extract(self, url):
270 display_id = self._match_id(url)
271 return self._track_url_result(self._download_page_data(display_id))
272
273
274 class VideomoreSeasonIE(VideomoreBaseIE):
275 IE_NAME = 'videomore:season'
276 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?!embed)(?P<id>[^/]+/[^/?#&]+)(?:/*|[?#&].*?)$'
277 _TESTS = [{
278 'url': 'http://videomore.ru/molodezhka/film_o_filme',
279 'info_dict': {
280 'id': 'molodezhka/film_o_filme',
281 'title': 'Фильм о фильме',
282 },
283 'playlist_mincount': 3,
284 }, {
285 'url': 'http://videomore.ru/molodezhka/sezon_promo?utm_so',
286 'only_matching': True,
287 }, {
288 'url': 'https://more.tv/molodezhka/film_o_filme',
289 'only_matching': True,
290 }]
291
292 @classmethod
293 def suitable(cls, url):
294 return (False if (VideomoreIE.suitable(url) or VideomoreVideoIE.suitable(url))
295 else super(VideomoreSeasonIE, cls).suitable(url))
296
297 def _real_extract(self, url):
298 display_id = self._match_id(url)
299 season = self._download_page_data(display_id)
300 season_id = compat_str(season['id'])
301 tracks = self._download_json(
302 self._API_BASE_URL + 'seasons/%s/tracks' % season_id,
303 season_id)['data']
304 entries = []
305 for track in tracks:
306 entries.append(self._track_url_result(track))
307 return self.playlist_result(entries, display_id, season.get('title'))