]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ivi.py
4bdf55f934aa63b005ff06e9b088b956f6806a02
6 from .common
import InfoExtractor
13 class IviIE(InfoExtractor
):
16 _VALID_URL
= r
'^https?://(?:www\.)?ivi\.ru/watch(?:/(?P<compilationid>[^/]+))?/(?P<videoid>\d+)'
21 u
'url': u
'http://www.ivi.ru/watch/53141',
22 u
'file': u
'53141.mp4',
23 u
'md5': u
'6ff5be2254e796ed346251d117196cf4',
25 u
'title': u
'Иван Васильевич меняет профессию',
26 u
'description': u
'md5:14d8eda24e9d93d29b5857012c6d6346',
28 u
'thumbnail': u
'http://thumbs.ivi.ru/f20.vcp.digitalaccess.ru/contents/d/1/c3c885163a082c29bceeb7b5a267a6.jpg',
30 u
'skip': u
'Only works from Russia',
34 u
'url': u
'http://www.ivi.ru/watch/dezhurnyi_angel/74791',
35 u
'file': u
'74791.mp4',
36 u
'md5': u
'3e6cc9a848c1d2ebcc6476444967baa9',
38 u
'title': u
'Дежурный ангел - 1 серия',
40 u
'thumbnail': u
'http://thumbs.ivi.ru/f7.vcp.digitalaccess.ru/contents/8/e/bc2f6c2b6e5d291152fdd32c059141.jpg',
42 u
'skip': u
'Only works from Russia',
47 _known_formats
= ['MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi', 'MP4-SHQ']
50 _known_thumbnails
= ['Thumb-120x90', 'Thumb-160', 'Thumb-640x480']
52 def _extract_description(self
, html
):
53 m
= re
.search(r
'<meta name="description" content="(?P<description>[^"]+)"/>', html
)
54 return m
.group('description') if m
is not None else None
56 def _extract_comment_count(self
, html
):
57 m
= re
.search(u
'(?s)<a href="#" id="view-comments" class="action-button dim gradient">\s*Комментарии:\s*(?P<commentcount>\d+)\s*</a>', html
)
58 return int(m
.group('commentcount')) if m
is not None else 0
60 def _real_extract(self
, url
):
61 mobj
= re
.match(self
._VALID
_URL
, url
)
62 video_id
= mobj
.group('videoid')
64 api_url
= 'http://api.digitalaccess.ru/api/json/'
66 data
= {u
'method': u
'da.content.get',
67 u
'params': [video_id
, {u
'site': u
's183',
68 u
'referrer': u
'http://www.ivi.ru/watch/%s' % video_id
,
69 u
'contentid': video_id
74 request
= compat_urllib_request
.Request(api_url
, json
.dumps(data
))
76 video_json_page
= self
._download
_webpage
(request
, video_id
, u
'Downloading video JSON')
77 video_json
= json
.loads(video_json_page
)
79 if u
'error' in video_json
:
80 error
= video_json
[u
'error']
81 if error
[u
'origin'] == u
'NoRedisValidData':
82 raise ExtractorError(u
'Video %s does not exist' % video_id
, expected
=True)
83 raise ExtractorError(u
'Unable to download video %s: %s' % (video_id
, error
[u
'message']), expected
=True)
85 result
= video_json
[u
'result']
87 formats
= [{'url': x
[u
'url'],
88 'format_id': x
[u
'content_format']
89 } for x
in result
[u
'files'] if x
[u
'content_format'] in self
._known
_formats
]
90 formats
.sort(key
=lambda fmt
: self
._known
_formats
.index(fmt
['format_id']))
93 self
._downloader
.report_warning(u
'No media links available for %s' % video_id
)
96 duration
= result
[u
'duration']
97 compilation
= result
[u
'compilation']
98 title
= result
[u
'title']
100 title
= '%s - %s' % (compilation
, title
) if compilation
is not None else title
102 previews
= result
[u
'preview']
103 previews
.sort(key
=lambda fmt
: self
._known
_thumbnails
.index(fmt
['content_format']))
104 thumbnail
= previews
[-1][u
'url'] if len(previews
) > 0 else None
106 video_page
= self
._download
_webpage
(url
, video_id
, u
'Downloading video page')
107 description
= self
._extract
_description
(video_page
)
108 comment_count
= self
._extract
_comment
_count
(video_page
)
113 'thumbnail': thumbnail
,
114 'description': description
,
115 'duration': duration
,
116 'comment_count': comment_count
,
121 class IviCompilationIE(InfoExtractor
):
122 IE_DESC
= u
'ivi.ru compilations'
123 IE_NAME
= u
'ivi:compilation'
124 _VALID_URL
= r
'^https?://(?:www\.)?ivi\.ru/watch/(?!\d+)(?P<compilationid>[a-z\d_-]+)(?:/season(?P<seasonid>\d+))?$'
126 def _extract_entries(self
, html
, compilation_id
):
127 return [self
.url_result('http://www.ivi.ru/watch/%s/%s' % (compilation_id
, serie
), 'Ivi')
128 for serie
in re
.findall(r
'<strong><a href="/watch/%s/(\d+)">(?:[^<]+)</a></strong>' % compilation_id
, html
)]
130 def _real_extract(self
, url
):
131 mobj
= re
.match(self
._VALID
_URL
, url
)
132 compilation_id
= mobj
.group('compilationid')
133 season_id
= mobj
.group('seasonid')
135 if season_id
is not None: # Season link
136 season_page
= self
._download
_webpage
(url
, compilation_id
, u
'Downloading season %s web page' % season_id
)
137 playlist_id
= '%s/season%s' % (compilation_id
, season_id
)
138 playlist_title
= self
._html
_search
_meta
(u
'title', season_page
, u
'title')
139 entries
= self
._extract
_entries
(season_page
, compilation_id
)
140 else: # Compilation link
141 compilation_page
= self
._download
_webpage
(url
, compilation_id
, u
'Downloading compilation web page')
142 playlist_id
= compilation_id
143 playlist_title
= self
._html
_search
_meta
(u
'title', compilation_page
, u
'title')
144 seasons
= re
.findall(r
'<a href="/watch/%s/season(\d+)">[^<]+</a>' % compilation_id
, compilation_page
)
145 if len(seasons
) == 0: # No seasons in this compilation
146 entries
= self
._extract
_entries
(compilation_page
, compilation_id
)
149 for season_id
in seasons
:
150 season_page
= self
._download
_webpage
('http://www.ivi.ru/watch/%s/season%s' % (compilation_id
, season_id
),
151 compilation_id
, u
'Downloading season %s web page' % season_id
)
152 entries
.extend(self
._extract
_entries
(season_page
, compilation_id
))
154 return self
.playlist_result(entries
, playlist_id
, playlist_title
)