]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/videomore.py
[extractors] Use new framework for existing embeds (#4307)
[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 self._sort_formats(formats)
185
186 return {
187 'id': video_id,
188 'title': title,
189 'series': series,
190 'season': season,
191 'episode': episode,
192 'thumbnail': item.get('thumbnail_url'),
193 'duration': int_or_none(item.get('duration')),
194 'view_count': int_or_none(item.get('views')),
195 'age_limit': int_or_none(item.get('min_age')),
196 'formats': formats,
197 }
198
199
200 class VideomoreVideoIE(VideomoreBaseIE):
201 IE_NAME = 'videomore:video'
202 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?P<id>(?:(?:[^/]+/){2})?[^/?#&]+)(?:/*|[?#&].*?)$'
203 _TESTS = [{
204 # single video with og:video:iframe
205 'url': 'http://videomore.ru/elki_3',
206 'info_dict': {
207 'id': '364623',
208 'ext': 'flv',
209 'title': 'Ёлки 3',
210 'description': '',
211 'thumbnail': r're:^https?://.*\.jpg',
212 'duration': 5579,
213 'age_limit': 6,
214 'view_count': int,
215 },
216 'params': {
217 'skip_download': True,
218 },
219 'skip': 'Requires logging in',
220 }, {
221 # season single series with og:video:iframe
222 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
223 'info_dict': {
224 'id': '352317',
225 'ext': 'mp4',
226 'title': 'Последний мент 1 сезон 14 серия',
227 'series': 'Последний мент',
228 'season': '1 сезон',
229 'episode': '14 серия',
230 'thumbnail': r're:^https?://.*\.jpg',
231 'duration': 2464,
232 'age_limit': 16,
233 'view_count': int,
234 },
235 'params': {
236 'skip_download': True,
237 },
238 }, {
239 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
240 'only_matching': True,
241 }, {
242 # single video without og:video:iframe
243 'url': 'http://videomore.ru/marin_i_ego_druzya',
244 'info_dict': {
245 'id': '359073',
246 'ext': 'flv',
247 'title': '1 серия. Здравствуй, Аквавилль!',
248 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
249 'thumbnail': r're:^https?://.*\.jpg',
250 'duration': 754,
251 'age_limit': 6,
252 'view_count': int,
253 },
254 'params': {
255 'skip_download': True,
256 },
257 'skip': 'redirects to https://more.tv/'
258 }, {
259 'url': 'https://videomore.ru/molodezhka/6_sezon/29_seriya?utm_so',
260 'only_matching': True,
261 }, {
262 'url': 'https://more.tv/poslednii_ment/1_sezon/14_seriya',
263 'only_matching': True,
264 }]
265
266 @classmethod
267 def suitable(cls, url):
268 return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
269
270 def _real_extract(self, url):
271 display_id = self._match_id(url)
272 return self._track_url_result(self._download_page_data(display_id))
273
274
275 class VideomoreSeasonIE(VideomoreBaseIE):
276 IE_NAME = 'videomore:season'
277 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?!embed)(?P<id>[^/]+/[^/?#&]+)(?:/*|[?#&].*?)$'
278 _TESTS = [{
279 'url': 'http://videomore.ru/molodezhka/film_o_filme',
280 'info_dict': {
281 'id': 'molodezhka/film_o_filme',
282 'title': 'Фильм о фильме',
283 },
284 'playlist_mincount': 3,
285 }, {
286 'url': 'http://videomore.ru/molodezhka/sezon_promo?utm_so',
287 'only_matching': True,
288 }, {
289 'url': 'https://more.tv/molodezhka/film_o_filme',
290 'only_matching': True,
291 }]
292
293 @classmethod
294 def suitable(cls, url):
295 return (False if (VideomoreIE.suitable(url) or VideomoreVideoIE.suitable(url))
296 else super(VideomoreSeasonIE, cls).suitable(url))
297
298 def _real_extract(self, url):
299 display_id = self._match_id(url)
300 season = self._download_page_data(display_id)
301 season_id = compat_str(season['id'])
302 tracks = self._download_json(
303 self._API_BASE_URL + 'seasons/%s/tracks' % season_id,
304 season_id)['data']
305 entries = []
306 for track in tracks:
307 entries.append(self._track_url_result(track))
308 return self.playlist_result(entries, display_id, season.get('title'))