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