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