]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ivi.py
4 from .common
import InfoExtractor
12 class IviIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?ivi\.(?:ru|tv)/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
17 _GEO_COUNTRIES
= ['RU']
18 _LIGHT_KEY
= b
'\xf1\x02\x32\xb7\xbc\x5c\x7a\xe8\xf7\x96\xc1\x33\x2b\x27\xa1\x8c'
19 _LIGHT_URL
= 'https://api.ivi.ru/light/'
24 'url': 'http://www.ivi.ru/watch/53141',
25 'md5': '6ff5be2254e796ed346251d117196cf4',
29 'title': 'Иван Васильевич меняет профессию',
30 'description': 'md5:b924063ea1677c8fe343d8a72ac2195f',
32 'thumbnail': r
're:^https?://.*\.jpg$',
34 'skip': 'Only works from Russia',
38 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/9549',
39 'md5': '221f56b35e3ed815fde2df71032f4b3e',
43 'title': 'Двое из ларца - Дело Гольдберга (1 часть)',
44 'series': 'Двое из ларца',
47 'episode': 'Дело Гольдберга (1 часть)',
50 'thumbnail': r
're:^https?://.*\.jpg$',
52 'skip': 'Only works from Russia',
55 # with MP4-HD720 format
56 'url': 'http://www.ivi.ru/watch/146500',
57 'md5': 'd63d35cdbfa1ea61a5eafec7cc523e1e',
62 'description': 'md5:ffca9372399976a2d260a407cc74cce6',
64 'thumbnail': r
're:^https?://.*\.jpg$',
66 'skip': 'Only works from Russia',
69 'url': 'https://www.ivi.tv/watch/33560/',
70 'only_matching': True,
76 'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi',
77 'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
79 def _real_extract(self
, url
):
80 video_id
= self
._match
_id
(url
)
83 'method': 'da.content.get',
87 'referrer': 'http://www.ivi.ru/watch/%s' % video_id
,
93 for site
in (353, 183):
94 content_data
= (data
% site
).encode()
97 from Cryptodome
.Cipher
import Blowfish
98 from Cryptodome
.Hash
import CMAC
99 pycryptodome_found
= True
102 from Crypto
.Cipher
import Blowfish
103 from Crypto
.Hash
import CMAC
104 pycryptodome_found
= True
106 pycryptodome_found
= False
109 timestamp
= (self
._download
_json
(
110 self
._LIGHT
_URL
, video_id
,
111 'Downloading timestamp JSON', data
=json
.dumps({
112 'method': 'da.timestamp.get',
114 }).encode(), fatal
=False) or {}).get('result')
120 'sign': CMAC
.new(self
._LIGHT
_KEY
, timestamp
.encode() + content_data
, Blowfish
).hexdigest(),
125 video_json
= self
._download
_json
(
126 self
._LIGHT
_URL
, video_id
,
127 'Downloading video JSON', data
=content_data
, query
=query
)
129 error
= video_json
.get('error')
131 origin
= error
.get('origin')
132 message
= error
.get('message') or error
.get('user_message')
133 extractor_msg
= 'Unable to download video %s'
134 if origin
== 'NotAllowedForLocation':
135 self
.raise_geo_restricted(message
, self
._GEO
_COUNTRIES
)
136 elif origin
== 'NoRedisValidData':
137 extractor_msg
= 'Video %s does not exist'
140 elif not pycryptodome_found
:
141 raise ExtractorError('pycryptodomex not found. Please install', expected
=True)
143 extractor_msg
+= ': ' + message
144 raise ExtractorError(extractor_msg
% video_id
, expected
=True)
148 result
= video_json
['result']
149 title
= result
['title']
151 quality
= qualities(self
._KNOWN
_FORMATS
)
154 for f
in result
.get('files', []):
156 content_format
= f
.get('content_format')
159 if (not self
.get_param('allow_unplayable_formats')
160 and ('-MDRM-' in content_format
or '-FPS-' in content_format
)):
164 'format_id': content_format
,
165 'quality': quality(content_format
),
166 'filesize': int_or_none(f
.get('size_in_bytes')),
168 self
._sort
_formats
(formats
)
170 compilation
= result
.get('compilation')
171 episode
= title
if compilation
else None
173 title
= '%s - %s' % (compilation
, title
) if compilation
is not None else title
176 'url': preview
['url'],
177 'id': preview
.get('content_format'),
178 } for preview
in result
.get('preview', []) if preview
.get('url')]
180 webpage
= self
._download
_webpage
(url
, video_id
)
182 season
= self
._search
_regex
(
183 r
'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)',
184 webpage
, 'season', default
=None)
185 season_number
= int_or_none(self
._search
_regex
(
186 r
'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"',
187 webpage
, 'season number', default
=None))
189 episode_number
= int_or_none(self
._search
_regex
(
190 r
'[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)',
191 webpage
, 'episode number', default
=None))
193 description
= self
._og
_search
_description
(webpage
, default
=None) or self
._html
_search
_meta
(
194 'description', webpage
, 'description', default
=None)
199 'series': compilation
,
201 'season_number': season_number
,
203 'episode_number': episode_number
,
204 'thumbnails': thumbnails
,
205 'description': description
,
206 'duration': int_or_none(result
.get('duration')),
211 class IviCompilationIE(InfoExtractor
):
212 IE_DESC
= 'ivi.ru compilations'
213 IE_NAME
= 'ivi:compilation'
214 _VALID_URL
= r
'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
216 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa',
218 'id': 'dvoe_iz_lartsa',
219 'title': 'Двое из ларца (2006 - 2008)',
221 'playlist_mincount': 24,
223 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1',
225 'id': 'dvoe_iz_lartsa/season1',
226 'title': 'Двое из ларца (2006 - 2008) 1 сезон',
228 'playlist_mincount': 12,
231 def _extract_entries(self
, html
, compilation_id
):
234 'http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), IviIE
.ie_key())
235 for serie
in re
.findall(
236 r
'<a\b[^>]+\bhref=["\']/watch
/%s/(\d
+)["\']' % compilation_id, html)]
238 def _real_extract(self, url):
239 mobj = self._match_valid_url(url)
240 compilation_id = mobj.group('compilationid')
241 season_id = mobj.group('seasonid')
243 if season_id is not None: # Season link
244 season_page = self._download_webpage(
245 url, compilation_id, 'Downloading season %s web page' % season_id)
246 playlist_id = '%s/season%s' % (compilation_id, season_id)
247 playlist_title = self._html_search_meta('title', season_page, 'title')
248 entries = self._extract_entries(season_page, compilation_id)
249 else: # Compilation link
250 compilation_page = self._download_webpage(url, compilation_id, 'Downloading compilation web page')
251 playlist_id = compilation_id
252 playlist_title = self._html_search_meta('title', compilation_page, 'title')
253 seasons = re.findall(
254 r'<a href="/watch
/%s/season(\d
+)' % compilation_id, compilation_page)
255 if not seasons: # No seasons in this compilation
256 entries = self._extract_entries(compilation_page, compilation_id)
259 for season_id in seasons:
260 season_page = self._download_webpage(
261 'http
://www
.ivi
.ru
/watch
/%s/season
%s' % (compilation_id, season_id),
262 compilation_id, 'Downloading season
%s web page
' % season_id)
263 entries.extend(self._extract_entries(season_page, compilation_id))
265 return self.playlist_result(entries, playlist_id, playlist_title)