]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/videomore.py
Fix `--check-formats` when there is network error
[yt-dlp.git] / yt_dlp / extractor / videomore.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_parse_qs,
9 compat_str,
10 compat_urllib_parse_urlparse,
11 )
12 from ..utils import (
13 int_or_none,
14 )
15
16
17 class 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
34 class VideomoreIE(InfoExtractor):
35 IE_NAME = 'videomore'
36 _VALID_URL = r'''(?x)
37 videomore:(?P<sid>\d+)$|
38 https?://
39 (?:
40 videomore\.ru/
41 (?:
42 embed|
43 [^/]+/[^/]+
44 )/|
45 (?:
46 (?:player\.)?videomore\.ru|
47 siren\.more\.tv/player
48 )/[^/]*\?.*?\btrack_id=|
49 odysseus\.more.tv/player/(?P<partner_id>\d+)/
50 )
51 (?P<id>\d+)
52 (?:[/?#&]|\.(?:xml|json)|$)
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 @staticmethod
134 def _extract_url(webpage):
135 mobj = re.search(
136 r'<object[^>]+data=(["\'])https?://videomore\.ru/player\.swf\?.*config=(?P<url>https?://videomore\.ru/(?:[^/]+/)+\d+\.xml).*\1',
137 webpage)
138 if not mobj:
139 mobj = re.search(
140 r'<iframe[^>]+src=([\'"])(?P<url>https?://videomore\.ru/embed/\d+)',
141 webpage)
142
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')
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 ('Данное видео недоступно для просмотра на территории этой страны', 'Данное видео доступно для просмотра только на территории России'):
195 self.raise_geo_restricted(countries=['RU'], metadata_available=True)
196 self.raise_no_formats(error, expected=True)
197 self._sort_formats(formats)
198
199 return {
200 'id': video_id,
201 'title': title,
202 'series': series,
203 'season': season,
204 'episode': episode,
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')),
209 'formats': formats,
210 }
211
212
213 class VideomoreVideoIE(VideomoreBaseIE):
214 IE_NAME = 'videomore:video'
215 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?P<id>(?:(?:[^/]+/){2})?[^/?#&]+)(?:/*|[?#&].*?)$'
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': '',
224 'thumbnail': r're:^https?://.*\.jpg',
225 'duration': 5579,
226 'age_limit': 6,
227 'view_count': int,
228 },
229 'params': {
230 'skip_download': True,
231 },
232 'skip': 'Requires logging in',
233 }, {
234 # season single series with og:video:iframe
235 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
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 },
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',
262 'thumbnail': r're:^https?://.*\.jpg',
263 'duration': 754,
264 'age_limit': 6,
265 'view_count': int,
266 },
267 'params': {
268 'skip_download': True,
269 },
270 'skip': 'redirects to https://more.tv/'
271 }, {
272 'url': 'https://videomore.ru/molodezhka/6_sezon/29_seriya?utm_so',
273 'only_matching': True,
274 }, {
275 'url': 'https://more.tv/poslednii_ment/1_sezon/14_seriya',
276 'only_matching': True,
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)
285 return self._track_url_result(self._download_page_data(display_id))
286
287
288 class VideomoreSeasonIE(VideomoreBaseIE):
289 IE_NAME = 'videomore:season'
290 _VALID_URL = VideomoreBaseIE._VALID_URL_BASE + r'(?!embed)(?P<id>[^/]+/[^/?#&]+)(?:/*|[?#&].*?)$'
291 _TESTS = [{
292 'url': 'http://videomore.ru/molodezhka/film_o_filme',
293 'info_dict': {
294 'id': 'molodezhka/film_o_filme',
295 'title': 'Фильм о фильме',
296 },
297 'playlist_mincount': 3,
298 }, {
299 'url': 'http://videomore.ru/molodezhka/sezon_promo?utm_so',
300 'only_matching': True,
301 }, {
302 'url': 'https://more.tv/molodezhka/film_o_filme',
303 'only_matching': True,
304 }]
305
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
311 def _real_extract(self, url):
312 display_id = self._match_id(url)
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']
318 entries = []
319 for track in tracks:
320 entries.append(self._track_url_result(track))
321 return self.playlist_result(entries, display_id, season.get('title'))