]>
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', 
  56     _KNOWN_FORMATS 
= ['MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi', 'MP4-SHQ'] 
  58     def _real_extract(self
, url
): 
  59         video_id 
= self
._match
_id
(url
) 
  62             'method': 'da.content.get', 
  66                     'referrer': 'http://www.ivi.ru/watch/%s' % video_id
, 
  72         request 
= sanitized_Request( 
  73             'http://api.digitalaccess.ru/api/json/', json
.dumps(data
)) 
  74         video_json 
= self
._download
_json
( 
  75             request
, video_id
, 'Downloading video JSON') 
  77         if 'error' in video_json
: 
  78             error 
= video_json
['error'] 
  79             if error
['origin'] == 'NoRedisValidData': 
  80                 raise ExtractorError('Video %s does not exist' % video_id
, expected
=True) 
  82                 'Unable to download video %s: %s' % (video_id
, error
['message']), 
  85         result 
= video_json
['result'] 
  89             'format_id': x
['content_format'], 
  90             'preference': self
._KNOWN
_FORMATS
.index(x
['content_format']), 
  91         } for x 
in result
['files'] if x
['content_format'] in self
._KNOWN
_FORMATS
] 
  93         self
._sort
_formats
(formats
) 
  95         title 
= result
['title'] 
  97         duration 
= int_or_none(result
.get('duration')) 
  98         compilation 
= result
.get('compilation') 
  99         episode 
= title 
if compilation 
else None 
 101         title 
= '%s - %s' % (compilation
, title
) if compilation 
is not None else title
 
 104             'url': preview
['url'], 
 105             'id': preview
.get('content_format'), 
 106         } for preview 
in result
.get('preview', []) if preview
.get('url')] 
 108         webpage 
= self
._download
_webpage
(url
, video_id
) 
 110         season 
= self
._search
_regex
( 
 111             r
'<li[^>]+class="season active"[^>]*><a[^>]+>([^<]+)', 
 112             webpage
, 'season', default
=None) 
 113         season_number 
= int_or_none(self
._search
_regex
( 
 114             r
'<li[^>]+class="season active"[^>]*><a[^>]+data-season(?:-index)?="(\d+)"', 
 115             webpage
, 'season number', default
=None)) 
 117         episode_number 
= int_or_none(self
._search
_regex
( 
 118             r
'<meta[^>]+itemprop="episode"[^>]*>\s*<meta[^>]+itemprop="episodeNumber"[^>]+content="(\d+)', 
 119             webpage
, 'episode number', default
=None)) 
 121         description 
= self
._og
_search
_description
(webpage
, default
=None) or self
._html
_search
_meta
( 
 122             'description', webpage
, 'description', default
=None) 
 127             'series': compilation
, 
 129             'season_number': season_number
, 
 131             'episode_number': episode_number
, 
 132             'thumbnails': thumbnails
, 
 133             'description': description
, 
 134             'duration': duration
, 
 139 class IviCompilationIE(InfoExtractor
): 
 140     IE_DESC 
= 'ivi.ru compilations' 
 141     IE_NAME 
= 'ivi:compilation' 
 142     _VALID_URL 
= r
'https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$' 
 144         'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa', 
 146             'id': 'dvoe_iz_lartsa', 
 147             'title': 'Двое из ларца (2006 - 2008)', 
 149         'playlist_mincount': 24, 
 151         'url': 'http://www.ivi.ru/watch/dvoe_iz_lartsa/season1', 
 153             'id': 'dvoe_iz_lartsa/season1', 
 154             'title': 'Двое из ларца (2006 - 2008) 1 сезон', 
 156         'playlist_mincount': 12, 
 159     def _extract_entries(self
, html
, compilation_id
): 
 162                 'http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), IviIE
.ie_key()) 
 163             for serie 
in re
.findall( 
 164                 r
'<a href="/watch/%s/(\d+)"[^>]+data-id="\1"' % compilation_id
, html
)] 
 166     def _real_extract(self
, url
): 
 167         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 168         compilation_id 
= mobj
.group('compilationid') 
 169         season_id 
= mobj
.group('seasonid') 
 171         if season_id 
is not None:  # Season link 
 172             season_page 
= self
._download
_webpage
( 
 173                 url
, compilation_id
, 'Downloading season %s web page' % season_id
) 
 174             playlist_id 
= '%s/season%s' % (compilation_id
, season_id
) 
 175             playlist_title 
= self
._html
_search
_meta
('title', season_page
, 'title') 
 176             entries 
= self
._extract
_entries
(season_page
, compilation_id
) 
 177         else:  # Compilation link 
 178             compilation_page 
= self
._download
_webpage
(url
, compilation_id
, 'Downloading compilation web page') 
 179             playlist_id 
= compilation_id
 
 180             playlist_title 
= self
._html
_search
_meta
('title', compilation_page
, 'title') 
 181             seasons 
= re
.findall( 
 182                 r
'<a href="/watch/%s/season(\d+)' % compilation_id
, compilation_page
) 
 183             if not seasons
:  # No seasons in this compilation 
 184                 entries 
= self
._extract
_entries
(compilation_page
, compilation_id
) 
 187                 for season_id 
in seasons
: 
 188                     season_page 
= self
._download
_webpage
( 
 189                         'http://www.ivi.ru/watch/%s/season%s' % (compilation_id
, season_id
), 
 190                         compilation_id
, 'Downloading season %s web page' % season_id
) 
 191                     entries
.extend(self
._extract
_entries
(season_page
, compilation_id
)) 
 193         return self
.playlist_result(entries
, playlist_id
, playlist_title
)