]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/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']
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 video_json
= self
._download
_json
(
95 'http://api.digitalaccess.ru/api/json/', video_id
,
96 'Downloading video JSON', data
=json
.dumps(data
))
98 if 'error' in video_json
:
99 error
= video_json
['error']
100 origin
= error
['origin']
101 if origin
== 'NotAllowedForLocation':
102 self
.raise_geo_restricted(
103 msg
=error
['message'], countries
=self
._GEO
_COUNTRIES
)
104 elif origin
== 'NoRedisValidData':
105 raise ExtractorError('Video %s does not exist' % video_id
, expected
=True)
106 raise ExtractorError(
107 'Unable to download video %s: %s' % (video_id
, error
['message']),
110 result
= video_json
['result']
112 quality
= qualities(self
._KNOWN
_FORMATS
)
116 'format_id': x
.get('content_format'),
117 'quality': quality(x
.get('content_format')),
118 } for x
in result
['files'] if x
.get('url')]
120 self
._sort
_formats
(formats
)
122 title
= result
['title']
124 duration
= int_or_none(result
.get('duration'))
125 compilation
= result
.get('compilation')
126 episode
= title
if compilation
else None
128 title
= '%s - %s' % (compilation
, title
) if compilation
is not None else title
131 'url': preview
['url'],
132 'id': preview
.get('content_format'),
133 } for preview
in result
.get('preview', []) if preview
.get('url')]
135 webpage
= self
._download
_webpage
(url
, video_id
)
137 season
= self
._search
_regex
(
138 r
'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)',
139 webpage
, 'season', default
=None)
140 season_number
= int_or_none(self
._search
_regex
(
141 r
'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"',
142 webpage
, 'season number', default
=None))
144 episode_number
= int_or_none(self
._search
_regex
(
145 r
'[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)',
146 webpage
, 'episode number', default
=None))
148 description
= self
._og
_search
_description
(webpage
, default
=None) or self
._html
_search
_meta
(
149 'description', webpage
, 'description', default
=None)
154 'series': compilation
,
156 'season_number': season_number
,
158 'episode_number': episode_number
,
159 'thumbnails': thumbnails
,
160 'description': description
,
161 'duration': duration
,
166 class IviCompilationIE(InfoExtractor
):
167 IE_DESC
= 'ivi.ru compilations'
168 IE_NAME
= 'ivi:compilation'
169 _VALID_URL
= r
'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
171 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa',
173 'id': 'dvoe_iz_lartsa',
174 'title': 'Двое из ларца (2006 - 2008)',
176 'playlist_mincount': 24,
178 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1',
180 'id': 'dvoe_iz_lartsa/season1',
181 'title': 'Двое из ларца (2006 - 2008) 1 сезон',
183 'playlist_mincount': 12,
186 def _extract_entries(self
, html
, compilation_id
):
189 'http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), IviIE
.ie_key())
190 for serie
in re
.findall(
191 r
'<a href="/watch/%s/(\d+)"[^>]+data-id="\1"' % compilation_id
, html
)]
193 def _real_extract(self
, url
):
194 mobj
= re
.match(self
._VALID
_URL
, url
)
195 compilation_id
= mobj
.group('compilationid')
196 season_id
= mobj
.group('seasonid')
198 if season_id
is not None: # Season link
199 season_page
= self
._download
_webpage
(
200 url
, compilation_id
, 'Downloading season %s web page' % season_id
)
201 playlist_id
= '%s/season%s' % (compilation_id
, season_id
)
202 playlist_title
= self
._html
_search
_meta
('title', season_page
, 'title')
203 entries
= self
._extract
_entries
(season_page
, compilation_id
)
204 else: # Compilation link
205 compilation_page
= self
._download
_webpage
(url
, compilation_id
, 'Downloading compilation web page')
206 playlist_id
= compilation_id
207 playlist_title
= self
._html
_search
_meta
('title', compilation_page
, 'title')
208 seasons
= re
.findall(
209 r
'<a href="/watch/%s/season(\d+)' % compilation_id
, compilation_page
)
210 if not seasons
: # No seasons in this compilation
211 entries
= self
._extract
_entries
(compilation_page
, compilation_id
)
214 for season_id
in seasons
:
215 season_page
= self
._download
_webpage
(
216 'http://www.ivi.ru/watch/%s/season%s' % (compilation_id
, season_id
),
217 compilation_id
, 'Downloading season %s web page' % season_id
)
218 entries
.extend(self
._extract
_entries
(season_page
, compilation_id
))
220 return self
.playlist_result(entries
, playlist_id
, playlist_title
)