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+)'
16 _EMBED_REGEX
= [r
'<embed[^>]+?src=(["\'])(?P
<url
>https?
://(?
:www\
.)?ivi\
.ru
/video
/player
.+?
)\
1']
18 _GEO_COUNTRIES = ['RU
']
19 _LIGHT_KEY = b'\xf1\x02\x32\xb7\xbc\x5c\x7a\xe8\xf7\x96\xc1\x33\x2b\x27\xa1\x8c'
20 _LIGHT_URL = 'https
://api
.ivi
.ru
/light
/'
25 'url
': 'http
://www
.ivi
.ru
/watch
/53141',
26 'md5
': '6ff5be2254e796ed346251d117196cf4
',
30 'title
': 'Иван Васильевич меняет профессию
',
31 'description
': 'md5
:b924063ea1677c8fe343d8a72ac2195f
',
33 'thumbnail
': r're
:^https?
://.*\
.jpg$
',
35 'skip
': 'Only works
from Russia
',
39 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/9549',
40 'md5': '221f56b35e3ed815fde2df71032f4b3e',
44 'title': 'Двое из ларца - Дело Гольдберга (1 часть)',
45 'series': 'Двое из ларца',
48 'episode': 'Дело Гольдберга (1 часть)',
51 'thumbnail': r
're:^https?://.*\.jpg$',
53 'skip': 'Only works from Russia',
56 # with MP4-HD720 format
57 'url': 'http://www.ivi.ru/watch/146500',
58 'md5': 'd63d35cdbfa1ea61a5eafec7cc523e1e',
63 'description': 'md5:ffca9372399976a2d260a407cc74cce6',
65 'thumbnail': r
're:^https?://.*\.jpg$',
67 'skip': 'Only works from Russia',
70 'url': 'https://www.ivi.tv/watch/33560/',
71 'only_matching': True,
77 'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi',
78 'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
80 def _real_extract(self
, url
):
81 video_id
= self
._match
_id
(url
)
84 'method': 'da.content.get',
88 'referrer': 'http://www.ivi.ru/watch/%s' % video_id
,
94 for site
in (353, 183):
95 content_data
= (data
% site
).encode()
98 from Cryptodome
.Cipher
import Blowfish
99 from Cryptodome
.Hash
import CMAC
100 pycryptodome_found
= True
103 from Crypto
.Cipher
import Blowfish
104 from Crypto
.Hash
import CMAC
105 pycryptodome_found
= True
107 pycryptodome_found
= False
110 timestamp
= (self
._download
_json
(
111 self
._LIGHT
_URL
, video_id
,
112 'Downloading timestamp JSON', data
=json
.dumps({
113 'method': 'da.timestamp.get',
115 }).encode(), fatal
=False) or {}).get('result')
121 'sign': CMAC
.new(self
._LIGHT
_KEY
, timestamp
.encode() + content_data
, Blowfish
).hexdigest(),
126 video_json
= self
._download
_json
(
127 self
._LIGHT
_URL
, video_id
,
128 'Downloading video JSON', data
=content_data
, query
=query
)
130 error
= video_json
.get('error')
132 origin
= error
.get('origin')
133 message
= error
.get('message') or error
.get('user_message')
134 extractor_msg
= 'Unable to download video %s'
135 if origin
== 'NotAllowedForLocation':
136 self
.raise_geo_restricted(message
, self
._GEO
_COUNTRIES
)
137 elif origin
== 'NoRedisValidData':
138 extractor_msg
= 'Video %s does not exist'
141 elif not pycryptodome_found
:
142 raise ExtractorError('pycryptodomex not found. Please install', expected
=True)
144 extractor_msg
+= ': ' + message
145 raise ExtractorError(extractor_msg
% video_id
, expected
=True)
149 result
= video_json
['result']
150 title
= result
['title']
152 quality
= qualities(self
._KNOWN
_FORMATS
)
155 for f
in result
.get('files', []):
157 content_format
= f
.get('content_format')
160 if (not self
.get_param('allow_unplayable_formats')
161 and ('-MDRM-' in content_format
or '-FPS-' in content_format
)):
165 'format_id': content_format
,
166 'quality': quality(content_format
),
167 'filesize': int_or_none(f
.get('size_in_bytes')),
169 self
._sort
_formats
(formats
)
171 compilation
= result
.get('compilation')
172 episode
= title
if compilation
else None
174 title
= '%s - %s' % (compilation
, title
) if compilation
is not None else title
177 'url': preview
['url'],
178 'id': preview
.get('content_format'),
179 } for preview
in result
.get('preview', []) if preview
.get('url')]
181 webpage
= self
._download
_webpage
(url
, video_id
)
183 season
= self
._search
_regex
(
184 r
'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)',
185 webpage
, 'season', default
=None)
186 season_number
= int_or_none(self
._search
_regex
(
187 r
'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"',
188 webpage
, 'season number', default
=None))
190 episode_number
= int_or_none(self
._search
_regex
(
191 r
'[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)',
192 webpage
, 'episode number', default
=None))
194 description
= self
._og
_search
_description
(webpage
, default
=None) or self
._html
_search
_meta
(
195 'description', webpage
, 'description', default
=None)
200 'series': compilation
,
202 'season_number': season_number
,
204 'episode_number': episode_number
,
205 'thumbnails': thumbnails
,
206 'description': description
,
207 'duration': int_or_none(result
.get('duration')),
212 class IviCompilationIE(InfoExtractor
):
213 IE_DESC
= 'ivi.ru compilations'
214 IE_NAME
= 'ivi:compilation'
215 _VALID_URL
= r
'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
217 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa',
219 'id': 'dvoe_iz_lartsa',
220 'title': 'Двое из ларца (2006 - 2008)',
222 'playlist_mincount': 24,
224 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1',
226 'id': 'dvoe_iz_lartsa/season1',
227 'title': 'Двое из ларца (2006 - 2008) 1 сезон',
229 'playlist_mincount': 12,
232 def _extract_entries(self
, html
, compilation_id
):
235 'http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), IviIE
.ie_key())
236 for serie
in re
.findall(
237 r
'<a\b[^>]+\bhref=["\']/watch
/%s/(\d
+)["\']' % compilation_id, html)]
239 def _real_extract(self, url):
240 mobj = self._match_valid_url(url)
241 compilation_id = mobj.group('compilationid')
242 season_id = mobj.group('seasonid')
244 if season_id is not None: # Season link
245 season_page = self._download_webpage(
246 url, compilation_id, 'Downloading season %s web page' % season_id)
247 playlist_id = '%s/season%s' % (compilation_id, season_id)
248 playlist_title = self._html_search_meta('title', season_page, 'title')
249 entries = self._extract_entries(season_page, compilation_id)
250 else: # Compilation link
251 compilation_page = self._download_webpage(url, compilation_id, 'Downloading compilation web page')
252 playlist_id = compilation_id
253 playlist_title = self._html_search_meta('title', compilation_page, 'title')
254 seasons = re.findall(
255 r'<a href="/watch
/%s/season(\d
+)' % compilation_id, compilation_page)
256 if not seasons: # No seasons in this compilation
257 entries = self._extract_entries(compilation_page, compilation_id)
260 for season_id in seasons:
261 season_page = self._download_webpage(
262 'http
://www
.ivi
.ru
/watch
/%s/season
%s' % (compilation_id, season_id),
263 compilation_id, 'Downloading season
%s web page
' % season_id)
264 entries.extend(self._extract_entries(season_page, compilation_id))
266 return self.playlist_result(entries, playlist_id, playlist_title)