]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/videomore.py
[tv5mondeplus] Fix extractor (#739)
[yt-dlp.git] / yt_dlp / 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
S
12from ..utils import (
13 int_or_none,
030dfb04
S
14)
15
16
29f7c58a 17class VideomoreBaseIE(InfoExtractor):
18 _API_BASE_URL = 'https://more.tv/api/v3/web/'
19 _VALID_URL_BASE = r'https?://(?:videomore\.ru|more\.tv)/'
20
21 def _download_page_data(self, display_id):
22 return self._download_json(
23 self._API_BASE_URL + 'PageData', display_id, query={
24 'url': '/' + display_id,
25 })['attributes']['response']['data']
26
27 def _track_url_result(self, track):
28 track_vod = track['trackVod']
29 video_url = track_vod.get('playerLink') or track_vod['link']
30 return self.url_result(
31 video_url, VideomoreIE.ie_key(), track_vod.get('hubId'))
32
33
030dfb04 34class VideomoreIE(InfoExtractor):
69759a59 35 IE_NAME = 'videomore'
19d69913
S
36 _VALID_URL = r'''(?x)
37 videomore:(?P<sid>\d+)$|
29f7c58a 38 https?://
19d69913 39 (?:
29f7c58a 40 videomore\.ru/
19d69913
S
41 (?:
42 embed|
43 [^/]+/[^/]+
44 )/|
29f7c58a 45 (?:
46 (?:player\.)?videomore\.ru|
47 siren\.more\.tv/player
48 )/[^/]*\?.*?\btrack_id=|
49 odysseus\.more.tv/player/(?P<partner_id>\d+)/
19d69913
S
50 )
51 (?P<id>\d+)
52 (?:[/?#&]|\.(?:xml|json)|$)
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
S
132
133 @staticmethod
134 def _extract_url(webpage):
135 mobj = re.search(
12f211d0 136 r'<object[^>]+data=(["\'])https?://videomore\.ru/player\.swf\?.*config=(?P<url>https?://videomore\.ru/(?:[^/]+/)+\d+\.xml).*\1',
030dfb04 137 webpage)
146969e0
YCH
138 if not mobj:
139 mobj = re.search(
140 r'<iframe[^>]+src=([\'"])(?P<url>https?://videomore\.ru/embed/\d+)',
141 webpage)
142
030dfb04
S
143 if mobj:
144 return mobj.group('url')
145
146 def _real_extract(self, url):
147 mobj = re.match(self._VALID_URL, url)
148 video_id = mobj.group('sid') or mobj.group('id')
29f7c58a 149 partner_id = mobj.group('partner_id') or compat_parse_qs(compat_urllib_parse_urlparse(url).query).get('partner_id', [None])[0] or '97'
150
151 item = self._download_json(
152 'https://siren.more.tv/player/config', video_id, query={
153 'partner_id': partner_id,
154 'track_id': video_id,
155 })['data']['playlist']['items'][0]
156
157 title = item.get('title')
158 series = item.get('project_name')
159 season = item.get('season_name')
160 episode = item.get('episode_name')
161 if not title:
162 title = []
163 for v in (series, season, episode):
164 if v:
165 title.append(v)
166 title = ' '.join(title)
167
168 streams = item.get('streams') or []
169 for protocol in ('DASH', 'HLS'):
170 stream_url = item.get(protocol.lower() + '_url')
171 if stream_url:
172 streams.append({'protocol': protocol, 'url': stream_url})
173
174 formats = []
175 for stream in streams:
176 stream_url = stream.get('url')
177 if not stream_url:
178 continue
179 protocol = stream.get('protocol')
180 if protocol == 'DASH':
181 formats.extend(self._extract_mpd_formats(
182 stream_url, video_id, mpd_id='dash', fatal=False))
183 elif protocol == 'HLS':
184 formats.extend(self._extract_m3u8_formats(
185 stream_url, video_id, 'mp4', 'm3u8_native',
186 m3u8_id='hls', fatal=False))
187 elif protocol == 'MSS':
188 formats.extend(self._extract_ism_formats(
189 stream_url, video_id, ism_id='mss', fatal=False))
190
191 if not formats:
192 error = item.get('error')
193 if error:
194 if error in ('Данное видео недоступно для просмотра на территории этой страны', 'Данное видео доступно для просмотра только на территории России'):
b7da73eb 195 self.raise_geo_restricted(countries=['RU'], metadata_available=True)
196 self.raise_no_formats(error, expected=True)
19dbaeec 197 self._sort_formats(formats)
030dfb04 198
030dfb04
S
199 return {
200 'id': video_id,
201 'title': title,
7a0b07c7 202 'series': series,
29f7c58a 203 'season': season,
7a0b07c7 204 'episode': episode,
29f7c58a 205 'thumbnail': item.get('thumbnail_url'),
206 'duration': int_or_none(item.get('duration')),
207 'view_count': int_or_none(item.get('views')),
208 'age_limit': int_or_none(item.get('min_age')),
030dfb04
S
209 'formats': formats,
210 }
211
212
29f7c58a 213class VideomoreVideoIE(VideomoreBaseIE):
030dfb04 214 IE_NAME = 'videomore:video'
29f7c58a 215 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?P<id>(?:(?:[^/]+/){2})?[^/?#&]+)(?:/*|[?#&].*?)$'
030dfb04
S
216 _TESTS = [{
217 # single video with og:video:iframe
218 'url': 'http://videomore.ru/elki_3',
219 'info_dict': {
220 'id': '364623',
221 'ext': 'flv',
222 'title': 'Ёлки 3',
223 'description': '',
ec85ded8 224 'thumbnail': r're:^https?://.*\.jpg',
030dfb04
S
225 'duration': 5579,
226 'age_limit': 6,
227 'view_count': int,
228 },
229 'params': {
230 'skip_download': True,
231 },
29f7c58a 232 'skip': 'Requires logging in',
030dfb04 233 }, {
dfb1b146 234 # season single series with og:video:iframe
030dfb04 235 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
29f7c58a 236 'info_dict': {
237 'id': '352317',
238 'ext': 'mp4',
239 'title': 'Последний мент 1 сезон 14 серия',
240 'series': 'Последний мент',
241 'season': '1 сезон',
242 'episode': '14 серия',
243 'thumbnail': r're:^https?://.*\.jpg',
244 'duration': 2464,
245 'age_limit': 16,
246 'view_count': int,
247 },
248 'params': {
249 'skip_download': True,
250 },
030dfb04
S
251 }, {
252 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
253 'only_matching': True,
254 }, {
255 # single video without og:video:iframe
256 'url': 'http://videomore.ru/marin_i_ego_druzya',
257 'info_dict': {
258 'id': '359073',
259 'ext': 'flv',
260 'title': '1 серия. Здравствуй, Аквавилль!',
261 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
ec85ded8 262 'thumbnail': r're:^https?://.*\.jpg',
030dfb04
S
263 'duration': 754,
264 'age_limit': 6,
265 'view_count': int,
266 },
267 'params': {
268 'skip_download': True,
269 },
29f7c58a 270 'skip': 'redirects to https://more.tv/'
19d69913
S
271 }, {
272 'url': 'https://videomore.ru/molodezhka/6_sezon/29_seriya?utm_so',
273 'only_matching': True,
29f7c58a 274 }, {
275 'url': 'https://more.tv/poslednii_ment/1_sezon/14_seriya',
276 'only_matching': True,
030dfb04
S
277 }]
278
279 @classmethod
280 def suitable(cls, url):
281 return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
282
283 def _real_extract(self, url):
284 display_id = self._match_id(url)
29f7c58a 285 return self._track_url_result(self._download_page_data(display_id))
030dfb04
S
286
287
29f7c58a 288class VideomoreSeasonIE(VideomoreBaseIE):
030dfb04 289 IE_NAME = 'videomore:season'
29f7c58a 290 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?!embed)(?P<id>[^/]+/[^/?#&]+)(?:/*|[?#&].*?)$'
030dfb04 291 _TESTS = [{
29f7c58a 292 'url': 'http://videomore.ru/molodezhka/film_o_filme',
030dfb04 293 'info_dict': {
29f7c58a 294 'id': 'molodezhka/film_o_filme',
295 'title': 'Фильм о фильме',
030dfb04 296 },
29f7c58a 297 'playlist_mincount': 3,
19d69913
S
298 }, {
299 'url': 'http://videomore.ru/molodezhka/sezon_promo?utm_so',
300 'only_matching': True,
29f7c58a 301 }, {
302 'url': 'https://more.tv/molodezhka/film_o_filme',
303 'only_matching': True,
030dfb04
S
304 }]
305
19d69913
S
306 @classmethod
307 def suitable(cls, url):
308 return (False if (VideomoreIE.suitable(url) or VideomoreVideoIE.suitable(url))
309 else super(VideomoreSeasonIE, cls).suitable(url))
310
030dfb04
S
311 def _real_extract(self, url):
312 display_id = self._match_id(url)
29f7c58a 313 season = self._download_page_data(display_id)
314 season_id = compat_str(season['id'])
315 tracks = self._download_json(
316 self._API_BASE_URL + 'seasons/%s/tracks' % season_id,
317 season_id)['data']
19d69913 318 entries = []
29f7c58a 319 for track in tracks:
320 entries.append(self._track_url_result(track))
321 return self.playlist_result(entries, display_id, season.get('title'))