]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ivi.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
15 class IviIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?ivi\.(?:ru|tv)/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
20 _GEO_COUNTRIES
= ['RU']
21 _LIGHT_KEY
= b
'\xf1\x02\x32\xb7\xbc\x5c\x7a\xe8\xf7\x96\xc1\x33\x2b\x27\xa1\x8c'
22 _LIGHT_URL
= 'https://api.ivi.ru/light/'
27 'url': 'http://www.ivi.ru/watch/53141',
28 'md5': '6ff5be2254e796ed346251d117196cf4',
32 'title': 'Иван Васильевич меняет профессию',
33 'description': 'md5:b924063ea1677c8fe343d8a72ac2195f',
35 'thumbnail': r
're:^https?://.*\.jpg$',
37 'skip': 'Only works from Russia',
41 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/9549',
42 'md5': '221f56b35e3ed815fde2df71032f4b3e',
46 'title': 'Двое из ларца - Дело Гольдберга (1 часть)',
47 'series': 'Двое из ларца',
50 'episode': 'Дело Гольдберга (1 часть)',
53 'thumbnail': r
're:^https?://.*\.jpg$',
55 'skip': 'Only works from Russia',
58 # with MP4-HD720 format
59 'url': 'http://www.ivi.ru/watch/146500',
60 'md5': 'd63d35cdbfa1ea61a5eafec7cc523e1e',
65 'description': 'md5:ffca9372399976a2d260a407cc74cce6',
67 'thumbnail': r
're:^https?://.*\.jpg$',
69 'skip': 'Only works from Russia',
72 'url': 'https://www.ivi.tv/watch/33560/',
73 'only_matching': True,
79 'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi',
80 'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
82 def _real_extract(self
, url
):
83 video_id
= self
._match
_id
(url
)
86 'method': 'da.content.get',
90 'referrer': 'http://www.ivi.ru/watch/%s' % video_id
,
96 for site
in (353, 183):
97 content_data
= (data
% site
).encode()
100 from Cryptodome
.Cipher
import Blowfish
101 from Cryptodome
.Hash
import CMAC
102 pycryptodome_found
= True
105 from Crypto
.Cipher
import Blowfish
106 from Crypto
.Hash
import CMAC
107 pycryptodome_found
= True
109 pycryptodome_found
= False
112 timestamp
= (self
._download
_json
(
113 self
._LIGHT
_URL
, video_id
,
114 'Downloading timestamp JSON', data
=json
.dumps({
115 'method': 'da.timestamp.get',
117 }).encode(), fatal
=False) or {}).get('result')
123 'sign': CMAC
.new(self
._LIGHT
_KEY
, timestamp
.encode() + content_data
, Blowfish
).hexdigest(),
128 video_json
= self
._download
_json
(
129 self
._LIGHT
_URL
, video_id
,
130 'Downloading video JSON', data
=content_data
, query
=query
)
132 error
= video_json
.get('error')
134 origin
= error
.get('origin')
135 message
= error
.get('message') or error
.get('user_message')
136 extractor_msg
= 'Unable to download video %s'
137 if origin
== 'NotAllowedForLocation':
138 self
.raise_geo_restricted(message
, self
._GEO
_COUNTRIES
)
139 elif origin
== 'NoRedisValidData':
140 extractor_msg
= 'Video %s does not exist'
143 elif not pycryptodome_found
:
144 raise ExtractorError('pycryptodomex not found. Please install', expected
=True)
146 extractor_msg
+= ': ' + message
147 raise ExtractorError(extractor_msg
% video_id
, expected
=True)
151 result
= video_json
['result']
152 title
= result
['title']
154 quality
= qualities(self
._KNOWN
_FORMATS
)
157 for f
in result
.get('files', []):
159 content_format
= f
.get('content_format')
162 if (not self
.get_param('allow_unplayable_formats')
163 and ('-MDRM-' in content_format
or '-FPS-' in content_format
)):
167 'format_id': content_format
,
168 'quality': quality(content_format
),
169 'filesize': int_or_none(f
.get('size_in_bytes')),
171 self
._sort
_formats
(formats
)
173 compilation
= result
.get('compilation')
174 episode
= title
if compilation
else None
176 title
= '%s - %s' % (compilation
, title
) if compilation
is not None else title
179 'url': preview
['url'],
180 'id': preview
.get('content_format'),
181 } for preview
in result
.get('preview', []) if preview
.get('url')]
183 webpage
= self
._download
_webpage
(url
, video_id
)
185 season
= self
._search
_regex
(
186 r
'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)',
187 webpage
, 'season', default
=None)
188 season_number
= int_or_none(self
._search
_regex
(
189 r
'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"',
190 webpage
, 'season number', default
=None))
192 episode_number
= int_or_none(self
._search
_regex
(
193 r
'[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)',
194 webpage
, 'episode number', default
=None))
196 description
= self
._og
_search
_description
(webpage
, default
=None) or self
._html
_search
_meta
(
197 'description', webpage
, 'description', default
=None)
202 'series': compilation
,
204 'season_number': season_number
,
206 'episode_number': episode_number
,
207 'thumbnails': thumbnails
,
208 'description': description
,
209 'duration': int_or_none(result
.get('duration')),
214 class IviCompilationIE(InfoExtractor
):
215 IE_DESC
= 'ivi.ru compilations'
216 IE_NAME
= 'ivi:compilation'
217 _VALID_URL
= r
'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
219 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa',
221 'id': 'dvoe_iz_lartsa',
222 'title': 'Двое из ларца (2006 - 2008)',
224 'playlist_mincount': 24,
226 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1',
228 'id': 'dvoe_iz_lartsa/season1',
229 'title': 'Двое из ларца (2006 - 2008) 1 сезон',
231 'playlist_mincount': 12,
234 def _extract_entries(self
, html
, compilation_id
):
237 'http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), IviIE
.ie_key())
238 for serie
in re
.findall(
239 r
'<a\b[^>]+\bhref=["\']/watch
/%s/(\d
+)["\']' % compilation_id, html)]
241 def _real_extract(self, url):
242 mobj = self._match_valid_url(url)
243 compilation_id = mobj.group('compilationid')
244 season_id = mobj.group('seasonid')
246 if season_id is not None: # Season link
247 season_page = self._download_webpage(
248 url, compilation_id, 'Downloading season %s web page' % season_id)
249 playlist_id = '%s/season%s' % (compilation_id, season_id)
250 playlist_title = self._html_search_meta('title', season_page, 'title')
251 entries = self._extract_entries(season_page, compilation_id)
252 else: # Compilation link
253 compilation_page = self._download_webpage(url, compilation_id, 'Downloading compilation web page')
254 playlist_id = compilation_id
255 playlist_title = self._html_search_meta('title', compilation_page, 'title')
256 seasons = re.findall(
257 r'<a href="/watch
/%s/season(\d
+)' % compilation_id, compilation_page)
258 if not seasons: # No seasons in this compilation
259 entries = self._extract_entries(compilation_page, compilation_id)
262 for season_id in seasons:
263 season_page = self._download_webpage(
264 'http
://www
.ivi
.ru
/watch
/%s/season
%s' % (compilation_id, season_id),
265 compilation_id, 'Downloading season
%s web page
' % season_id)
266 entries.extend(self._extract_entries(season_page, compilation_id))
268 return self.playlist_result(entries, playlist_id, playlist_title)