]>
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/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
23 'url': 'http://www.ivi.ru/watch/53141',
24 'md5': '6ff5be2254e796ed346251d117196cf4',
28 'title': 'Иван Васильевич меняет профессию',
29 'description': 'md5:b924063ea1677c8fe343d8a72ac2195f',
31 'thumbnail': 're:^https?://.*\.jpg$',
33 'skip': 'Only works from Russia',
37 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/9549',
38 'md5': '221f56b35e3ed815fde2df71032f4b3e',
42 'title': 'Двое из ларца - Дело Гольдберга (1 часть)',
43 'series': 'Двое из ларца',
46 'episode': 'Дело Гольдберга (1 часть)',
49 'thumbnail': 're:^https?://.*\.jpg$',
51 'skip': 'Only works from Russia',
54 # with MP4-HD720 format
55 'url': 'http://www.ivi.ru/watch/146500',
56 'md5': 'd63d35cdbfa1ea61a5eafec7cc523e1e',
61 'description': 'md5:ffca9372399976a2d260a407cc74cce6',
63 'thumbnail': 're:^https?://.*\.jpg$',
65 'skip': 'Only works from Russia',
71 'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi',
72 'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
74 def _real_extract(self
, url
):
75 video_id
= self
._match
_id
(url
)
78 'method': 'da.content.get',
82 'referrer': 'http://www.ivi.ru/watch/%s' % video_id
,
88 video_json
= self
._download
_json
(
89 'http://api.digitalaccess.ru/api/json/', video_id
,
90 'Downloading video JSON', data
=json
.dumps(data
))
92 if 'error' in video_json
:
93 error
= video_json
['error']
94 if error
['origin'] == 'NoRedisValidData':
95 raise ExtractorError('Video %s does not exist' % video_id
, expected
=True)
97 'Unable to download video %s: %s' % (video_id
, error
['message']),
100 result
= video_json
['result']
102 quality
= qualities(self
._KNOWN
_FORMATS
)
106 'format_id': x
.get('content_format'),
107 'quality': quality(x
.get('content_format')),
108 } for x
in result
['files'] if x
.get('url')]
110 self
._sort
_formats
(formats
)
112 title
= result
['title']
114 duration
= int_or_none(result
.get('duration'))
115 compilation
= result
.get('compilation')
116 episode
= title
if compilation
else None
118 title
= '%s - %s' % (compilation
, title
) if compilation
is not None else title
121 'url': preview
['url'],
122 'id': preview
.get('content_format'),
123 } for preview
in result
.get('preview', []) if preview
.get('url')]
125 webpage
= self
._download
_webpage
(url
, video_id
)
127 season
= self
._search
_regex
(
128 r
'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)',
129 webpage
, 'season', default
=None)
130 season_number
= int_or_none(self
._search
_regex
(
131 r
'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"',
132 webpage
, 'season number', default
=None))
134 episode_number
= int_or_none(self
._search
_regex
(
135 r
'[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)',
136 webpage
, 'episode number', default
=None))
138 description
= self
._og
_search
_description
(webpage
, default
=None) or self
._html
_search
_meta
(
139 'description', webpage
, 'description', default
=None)
144 'series': compilation
,
146 'season_number': season_number
,
148 'episode_number': episode_number
,
149 'thumbnails': thumbnails
,
150 'description': description
,
151 'duration': duration
,
156 class IviCompilationIE(InfoExtractor
):
157 IE_DESC
= 'ivi.ru compilations'
158 IE_NAME
= 'ivi:compilation'
159 _VALID_URL
= r
'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
161 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa',
163 'id': 'dvoe_iz_lartsa',
164 'title': 'Двое из ларца (2006 - 2008)',
166 'playlist_mincount': 24,
168 'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1',
170 'id': 'dvoe_iz_lartsa/season1',
171 'title': 'Двое из ларца (2006 - 2008) 1 сезон',
173 'playlist_mincount': 12,
176 def _extract_entries(self
, html
, compilation_id
):
179 'http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), IviIE
.ie_key())
180 for serie
in re
.findall(
181 r
'<a href="/watch/%s/(\d+)"[^>]+data-id="\1"' % compilation_id
, html
)]
183 def _real_extract(self
, url
):
184 mobj
= re
.match(self
._VALID
_URL
, url
)
185 compilation_id
= mobj
.group('compilationid')
186 season_id
= mobj
.group('seasonid')
188 if season_id
is not None: # Season link
189 season_page
= self
._download
_webpage
(
190 url
, compilation_id
, 'Downloading season %s web page' % season_id
)
191 playlist_id
= '%s/season%s' % (compilation_id
, season_id
)
192 playlist_title
= self
._html
_search
_meta
('title', season_page
, 'title')
193 entries
= self
._extract
_entries
(season_page
, compilation_id
)
194 else: # Compilation link
195 compilation_page
= self
._download
_webpage
(url
, compilation_id
, 'Downloading compilation web page')
196 playlist_id
= compilation_id
197 playlist_title
= self
._html
_search
_meta
('title', compilation_page
, 'title')
198 seasons
= re
.findall(
199 r
'<a href="/watch/%s/season(\d+)' % compilation_id
, compilation_page
)
200 if not seasons
: # No seasons in this compilation
201 entries
= self
._extract
_entries
(compilation_page
, compilation_id
)
204 for season_id
in seasons
:
205 season_page
= self
._download
_webpage
(
206 'http://www.ivi.ru/watch/%s/season%s' % (compilation_id
, season_id
),
207 compilation_id
, 'Downloading season %s web page' % season_id
)
208 entries
.extend(self
._extract
_entries
(season_page
, compilation_id
))
210 return self
.playlist_result(entries
, playlist_id
, playlist_title
)