[youku] handle password-protected videos, fix #73 (again)

This commit is contained in:
Mort Yao 2015-11-24 21:37:40 +01:00
parent 6fdb9ca179
commit d41b8a2a89

View File

@ -118,10 +118,17 @@ class Youku(VideoExtractor):
assert 'stream' in data assert 'stream' in data
except: except:
if 'error' in data: if 'error' in data:
log.wtf('[Failed] ' + data['error']['note']) if data['error']['code'] == -202:
# Password protected
self.password_protected = True
self.password = input(log.sprint('Password: ', log.YELLOW))
api_url += '&pwd={}'.format(self.password)
meta = json.loads(get_html(api_url))
data = meta['data']
else:
log.wtf('[Failed] ' + data['error']['note'])
else: else:
log.wtf('[Failed] Video not found.') log.wtf('[Failed] Video not found.')
# TBD: password protected?
self.title = data['video']['title'] self.title = data['video']['title']
self.ep = data['security']['encrypt_string'] self.ep = data['security']['encrypt_string']
@ -175,8 +182,7 @@ class Youku(VideoExtractor):
if not kwargs['info_only']: if not kwargs['info_only']:
if self.password_protected: if self.password_protected:
password = input(log.sprint('Password: ', log.YELLOW)) m3u8_url += '&password={}'.format(self.password)
m3u8_url += '&password={}'.format(password)
m3u8 = get_html(m3u8_url) m3u8 = get_html(m3u8_url)