2 from __future__ import unicode_literals
7 from .common import InfoExtractor
15 class IviIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?ivi\.ru/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
20 _GEO_COUNTRIES = ['RU']
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',
73 'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi',
74 'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
76 def _real_extract(self, url):
77 video_id = self._match_id(url)
80 'method': 'da.content.get',
84 'referrer': 'http://www.ivi.ru/watch/%s' % video_id,
90 video_json = self._download_json(
91 'http://api.digitalaccess.ru/api/json/', video_id,
92 'Downloading video JSON', data=json.dumps(data))
94 if 'error' in video_json:
95 error = video_json['error']
96 origin = error['origin']
97 if origin == 'NotAllowedForLocation':
98 self.raise_geo_restricted(
99 msg=error['message'], countries=self._GEO_COUNTRIES)
100 elif origin == 'NoRedisValidData':
101 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
102 raise ExtractorError(
103 'Unable to download video %s: %s' % (video_id, error['message']),
106 result = video_json['result']
108 quality = qualities(self._KNOWN_FORMATS)
112 'format_id': x.get('content_format'),
113 'quality': quality(x.get('content_format')),
114 } for x in result['files'] if x.get('url')]
116 self._sort_formats(formats)
118 title = result['title']
120 duration = int_or_none(result.get('duration'))
121 compilation = result.get('compilation')
122 episode = title if compilation else None
124 title = '%s - %s' % (compilation, title) if compilation is not None else title
127 'url': preview['url'],
128 'id': preview.get('content_format'),
129 } for preview in result.get('preview', []) if preview.get('url')]
131 webpage = self._download_webpage(url, video_id)
133 season = self._search_regex(
134 r'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)',
135 webpage, 'season', default=None)
136 season_number = int_or_none(self._search_regex(
137 r'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"',
138 webpage, 'season number', default=None))
140 episode_number = int_or_none(self._search_regex(
141 r'[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)',
142 webpage, 'episode number', default=None))
144 description = self._og_search_description(webpage, default=None) or self._html_search_meta(
145 'description', webpage, 'description', default=None)
150 'series': compilation,
152 'season_number': season_number,
154 'episode_number': episode_number,
155 'thumbnails': thumbnails,
156 'description': description,
157 'duration': duration,
162 class IviCompilationIE(InfoExtractor):
163 IE_DESC = 'ivi.ru compilations'
164 IE_NAME = 'ivi:compilation'
165 _VALID_URL = r'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
167 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa',
169 'id': 'dvoe_iz_lartsa',
170 'title': 'Двое из ларца (2006 - 2008)',
172 'playlist_mincount': 24,
174 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1',
176 'id': 'dvoe_iz_lartsa/season1',
177 'title': 'Двое из ларца (2006 - 2008) 1 сезон',
179 'playlist_mincount': 12,
182 def _extract_entries(self, html, compilation_id):
185 'http://www.ivi.ru/watch/%s/%s' % (compilation_id, serie), IviIE.ie_key())
186 for serie in re.findall(
187 r'<a href="/watch/%s/(\d+)"[^>]+data-id="\1"' % compilation_id, html)]
189 def _real_extract(self, url):
190 mobj = re.match(self._VALID_URL, url)
191 compilation_id = mobj.group('compilationid')
192 season_id = mobj.group('seasonid')
194 if season_id is not None: # Season link
195 season_page = self._download_webpage(
196 url, compilation_id, 'Downloading season %s web page' % season_id)
197 playlist_id = '%s/season%s' % (compilation_id, season_id)
198 playlist_title = self._html_search_meta('title', season_page, 'title')
199 entries = self._extract_entries(season_page, compilation_id)
200 else: # Compilation link
201 compilation_page = self._download_webpage(url, compilation_id, 'Downloading compilation web page')
202 playlist_id = compilation_id
203 playlist_title = self._html_search_meta('title', compilation_page, 'title')
204 seasons = re.findall(
205 r'<a href="/watch/%s/season(\d+)' % compilation_id, compilation_page)
206 if not seasons: # No seasons in this compilation
207 entries = self._extract_entries(compilation_page, compilation_id)
210 for season_id in seasons:
211 season_page = self._download_webpage(
212 'http://www.ivi.ru/watch/%s/season%s' % (compilation_id, season_id),
213 compilation_id, 'Downloading season %s web page' % season_id)
214 entries.extend(self._extract_entries(season_page, compilation_id))
216 return self.playlist_result(entries, playlist_id, playlist_title)