X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fyouku.py;h=fd7eb5a6d52f8c2ec348d3cfc908dee3d4743f0d;hb=15707c7e024f1f29e7abd8ddaa362196ef2d4af6;hp=3a3432be85464ecdee517620b5e0cf9f3534d0d8;hpb=31d9ea4a3e641acfee8852c9324bd414047fce9e;p=youtube-dl.git diff --git a/youtube_dl/extractor/youku.py b/youtube_dl/extractor/youku.py index 3a3432be8..fd7eb5a6d 100644 --- a/youtube_dl/extractor/youku.py +++ b/youtube_dl/extractor/youku.py @@ -2,10 +2,13 @@ from __future__ import unicode_literals import base64 +import random +import string +import time from .common import InfoExtractor from ..compat import ( - compat_urllib_parse, + compat_urllib_parse_urlencode, compat_ord, ) from ..utils import ( @@ -135,12 +138,17 @@ class YoukuIE(InfoExtractor): '_00' + \ '/st/' + self.parse_ext_l(format) + \ '/fileid/' + get_fileid(format, n) + '?' + \ - compat_urllib_parse.urlencode(param) + compat_urllib_parse_urlencode(param) video_urls.append(video_url) video_urls_dict[format] = video_urls return video_urls_dict + @staticmethod + def get_ysuid(): + return '%d%s' % (int(time.time()), ''.join([ + random.choice(string.ascii_letters) for i in range(3)])) + def get_hd(self, fm): hd_id_dict = { '3gp': '0', @@ -189,6 +197,8 @@ class YoukuIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) + self._set_cookie('youku.com', '__ysuid', self.get_ysuid()) + def retrieve_data(req_url, note): headers = { 'Referer': req_url, @@ -204,10 +214,10 @@ class YoukuIE(InfoExtractor): return raw_data['data'] - video_password = self._downloader.params.get('videopassword', None) + video_password = self._downloader.params.get('videopassword') # request basic data - basic_data_url = "http://play.youku.com/play/get.json?vid=%s&ct=12" % video_id + basic_data_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % video_id if video_password: basic_data_url += '&pwd=%s' % video_password @@ -219,6 +229,9 @@ class YoukuIE(InfoExtractor): if error_note is not None and '因版权原因无法观看此视频' in error_note: raise ExtractorError( 'Youku said: Sorry, this video is available in China only', expected=True) + elif error_note and '该视频被设为私密' in error_note: + raise ExtractorError( + 'Youku said: Sorry, this video is private', expected=True) else: msg = 'Youku server reported error %i' % error.get('code') if error_note is not None: