]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/videomore.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / videomore.py
CommitLineData
030dfb04 1from .common import InfoExtractor
29f7c58a 2from ..compat import (
29f7c58a 3 compat_str,
29f7c58a 4)
030dfb04
S
5from ..utils import (
6 int_or_none,
4dfbf869 7 parse_qs,
030dfb04
S
8)
9
10
29f7c58a 11class 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
030dfb04 28class VideomoreIE(InfoExtractor):
69759a59 29 IE_NAME = 'videomore'
19d69913
S
30 _VALID_URL = r'''(?x)
31 videomore:(?P<sid>\d+)$|
29f7c58a 32 https?://
19d69913 33 (?:
29f7c58a 34 videomore\.ru/
19d69913
S
35 (?:
36 embed|
37 [^/]+/[^/]+
38 )/|
29f7c58a 39 (?:
40 (?:player\.)?videomore\.ru|
41 siren\.more\.tv/player
42 )/[^/]*\?.*?\btrack_id=|
43 odysseus\.more.tv/player/(?P<partner_id>\d+)/
19d69913
S
44 )
45 (?P<id>\d+)
46 (?:[/?#&]|\.(?:xml|json)|$)
47 '''
bfd973ec 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 ''']
030dfb04
S
54 _TESTS = [{
55 'url': 'http://videomore.ru/kino_v_detalayah/5_sezon/367617',
010d034f 56 'md5': '44455a346edc0d509ac5b5a5b531dc35',
030dfb04
S
57 'info_dict': {
58 'id': '367617',
59 'ext': 'flv',
010d034f 60 'title': 'Кино в деталях 5 сезон В гостях Алексей Чумаков и Юлия Ковальчук',
7a0b07c7
S
61 'series': 'Кино в деталях',
62 'episode': 'В гостях Алексей Чумаков и Юлия Ковальчук',
ec85ded8 63 'thumbnail': r're:^https?://.*\.jpg',
030dfb04 64 'duration': 2910,
030dfb04 65 'view_count': int,
010d034f
S
66 'comment_count': int,
67 'age_limit': 16,
030dfb04 68 },
29f7c58a 69 'skip': 'The video is not available for viewing.',
7a0b07c7
S
70 }, {
71 'url': 'http://videomore.ru/embed/259974',
72 'info_dict': {
73 'id': '259974',
29f7c58a 74 'ext': 'mp4',
010d034f 75 'title': 'Молодежка 2 сезон 40 серия',
7a0b07c7 76 'series': 'Молодежка',
29f7c58a 77 'season': '2 сезон',
010d034f 78 'episode': '40 серия',
ec85ded8 79 'thumbnail': r're:^https?://.*\.jpg',
29f7c58a 80 'duration': 2789,
7a0b07c7 81 'view_count': int,
010d034f 82 'age_limit': 16,
7a0b07c7
S
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',
010d034f 92 'title': 'Промо Команда проиграла из-за Бакина?',
7a0b07c7 93 'episode': 'Команда проиграла из-за Бакина?',
ec85ded8 94 'thumbnail': r're:^https?://.*\.jpg',
7a0b07c7
S
95 'duration': 29,
96 'age_limit': 16,
97 'view_count': int,
98 },
99 'params': {
100 'skip_download': True,
101 },
29f7c58a 102 'skip': 'The video is not available for viewing.',
030dfb04
S
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,
19d69913
S
121 }, {
122 'url': 'https://player.videomore.ru/?partner_id=97&track_id=736234&autoplay=0&userToken=',
123 'only_matching': True,
29f7c58a 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,
030dfb04 130 }]
29f7c58a 131 _GEO_BYPASS = False
030dfb04 132
030dfb04 133 def _real_extract(self, url):
5ad28e7f 134 mobj = self._match_valid_url(url)
030dfb04 135 video_id = mobj.group('sid') or mobj.group('id')
4dfbf869 136 partner_id = mobj.group('partner_id') or parse_qs(url).get('partner_id', [None])[0] or '97'
29f7c58a 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 ('Данное видео недоступно для просмотра на территории этой страны', 'Данное видео доступно для просмотра только на территории России'):
b7da73eb 182 self.raise_geo_restricted(countries=['RU'], metadata_available=True)
183 self.raise_no_formats(error, expected=True)
030dfb04 184
030dfb04
S
185 return {
186 'id': video_id,
187 'title': title,
7a0b07c7 188 'series': series,
29f7c58a 189 'season': season,
7a0b07c7 190 'episode': episode,
29f7c58a 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')),
030dfb04
S
195 'formats': formats,
196 }
197
198
29f7c58a 199class VideomoreVideoIE(VideomoreBaseIE):
030dfb04 200 IE_NAME = 'videomore:video'
29f7c58a 201 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?P<id>(?:(?:[^/]+/){2})?[^/?#&]+)(?:/*|[?#&].*?)$'
030dfb04
S
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': '',
ec85ded8 210 'thumbnail': r're:^https?://.*\.jpg',
030dfb04
S
211 'duration': 5579,
212 'age_limit': 6,
213 'view_count': int,
214 },
215 'params': {
216 'skip_download': True,
217 },
29f7c58a 218 'skip': 'Requires logging in',
030dfb04 219 }, {
dfb1b146 220 # season single series with og:video:iframe
030dfb04 221 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
29f7c58a 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 },
030dfb04
S
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',
ec85ded8 248 'thumbnail': r're:^https?://.*\.jpg',
030dfb04
S
249 'duration': 754,
250 'age_limit': 6,
251 'view_count': int,
252 },
253 'params': {
254 'skip_download': True,
255 },
29f7c58a 256 'skip': 'redirects to https://more.tv/'
19d69913
S
257 }, {
258 'url': 'https://videomore.ru/molodezhka/6_sezon/29_seriya?utm_so',
259 'only_matching': True,
29f7c58a 260 }, {
261 'url': 'https://more.tv/poslednii_ment/1_sezon/14_seriya',
262 'only_matching': True,
030dfb04
S
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)
29f7c58a 271 return self._track_url_result(self._download_page_data(display_id))
030dfb04
S
272
273
29f7c58a 274class VideomoreSeasonIE(VideomoreBaseIE):
030dfb04 275 IE_NAME = 'videomore:season'
29f7c58a 276 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?!embed)(?P<id>[^/]+/[^/?#&]+)(?:/*|[?#&].*?)$'
030dfb04 277 _TESTS = [{
29f7c58a 278 'url': 'http://videomore.ru/molodezhka/film_o_filme',
030dfb04 279 'info_dict': {
29f7c58a 280 'id': 'molodezhka/film_o_filme',
281 'title': 'Фильм о фильме',
030dfb04 282 },
29f7c58a 283 'playlist_mincount': 3,
19d69913
S
284 }, {
285 'url': 'http://videomore.ru/molodezhka/sezon_promo?utm_so',
286 'only_matching': True,
29f7c58a 287 }, {
288 'url': 'https://more.tv/molodezhka/film_o_filme',
289 'only_matching': True,
030dfb04
S
290 }]
291
19d69913
S
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
030dfb04
S
297 def _real_extract(self, url):
298 display_id = self._match_id(url)
29f7c58a 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']
19d69913 304 entries = []
29f7c58a 305 for track in tracks:
306 entries.append(self._track_url_result(track))
307 return self.playlist_result(entries, display_id, season.get('title'))