[vimeo] Fix password protected videos

pull/2/head
Sergey M․ 9 years ago
parent 68f3b61f0e
commit 7c84562945

@ -39,10 +39,7 @@ class VimeoBaseInfoExtractor(InfoExtractor):
return return
self.report_login() self.report_login()
webpage = self._download_webpage(self._LOGIN_URL, None, False) webpage = self._download_webpage(self._LOGIN_URL, None, False)
token = self._extract_xsrft(webpage) token, vuid = self._extract_xsrft_and_vuid(webpage)
vuid = self._search_regex(
r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
webpage, 'vuid', group='vuid')
data = urlencode_postdata({ data = urlencode_postdata({
'action': 'login', 'action': 'login',
'email': username, 'email': username,
@ -56,10 +53,14 @@ class VimeoBaseInfoExtractor(InfoExtractor):
login_request.add_header('Referer', self._LOGIN_URL) login_request.add_header('Referer', self._LOGIN_URL)
self._download_webpage(login_request, None, False, 'Wrong login info') self._download_webpage(login_request, None, False, 'Wrong login info')
def _extract_xsrft(self, webpage): def _extract_xsrft_and_vuid(self, webpage):
return self._search_regex( xsrft = self._search_regex(
r'xsrft\s*[=:]\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)', r'xsrft\s*[=:]\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
webpage, 'login token', group='xsrft') webpage, 'login token', group='xsrft')
vuid = self._search_regex(
r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
webpage, 'vuid', group='vuid')
return xsrft, vuid
class VimeoIE(VimeoBaseInfoExtractor): class VimeoIE(VimeoBaseInfoExtractor):
@ -201,7 +202,7 @@ class VimeoIE(VimeoBaseInfoExtractor):
password = self._downloader.params.get('videopassword', None) password = self._downloader.params.get('videopassword', None)
if password is None: if password is None:
raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True) raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
token = self._extract_xsrft(webpage) token, vuid = self._extract_xsrft_and_vuid(webpage)
data = urlencode_postdata({ data = urlencode_postdata({
'password': password, 'password': password,
'token': token, 'token': token,
@ -211,6 +212,7 @@ class VimeoIE(VimeoBaseInfoExtractor):
url = url.replace('http://', 'https://') url = url.replace('http://', 'https://')
password_request = compat_urllib_request.Request(url + '/password', data) password_request = compat_urllib_request.Request(url + '/password', data)
password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
password_request.add_header('Cookie', 'clip_v=1; vuid=%s' % vuid)
password_request.add_header('Referer', url) password_request.add_header('Referer', url)
return self._download_webpage( return self._download_webpage(
password_request, video_id, password_request, video_id,
@ -465,7 +467,7 @@ class VimeoChannelIE(VimeoBaseInfoExtractor):
if password is None: if password is None:
raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True) raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
fields = self._hidden_inputs(login_form) fields = self._hidden_inputs(login_form)
token = self._extract_xsrft(webpage) token, vuid = self._extract_xsrft_and_vuid(webpage)
fields['token'] = token fields['token'] = token
fields['password'] = password fields['password'] = password
post = urlencode_postdata(fields) post = urlencode_postdata(fields)
@ -474,6 +476,7 @@ class VimeoChannelIE(VimeoBaseInfoExtractor):
password_url = compat_urlparse.urljoin(page_url, password_path) password_url = compat_urlparse.urljoin(page_url, password_path)
password_request = compat_urllib_request.Request(password_url, post) password_request = compat_urllib_request.Request(password_url, post)
password_request.add_header('Content-type', 'application/x-www-form-urlencoded') password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
password_request.add_header('Cookie', 'vuid=%s' % vuid)
self._set_cookie('vimeo.com', 'xsrft', token) self._set_cookie('vimeo.com', 'xsrft', token)
return self._download_webpage( return self._download_webpage(

Loading…
Cancel
Save