Skip to content

Commit

Permalink
[youku] do not override existing proxy handler (fix #1546, close soim…
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Jan 9, 2017
1 parent f452eec commit 64dca21
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/you_get/extractors/youku.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def prepare(self, **kwargs):
})
else:
proxy_handler = request.ProxyHandler({})
opener = request.build_opener(ssl_context, cookie_handler, proxy_handler)
opener.addheaders = [('Cookie','__ysuid={}'.format(time.time()))]
request.install_opener(opener)
for handler in (ssl_context, cookie_handler, proxy_handler):
request._opener.add_handler(handler)
request._opener.addheaders = [('Cookie','__ysuid={}'.format(time.time()))]

assert self.url or self.vid

Expand All @@ -162,7 +162,7 @@ def prepare(self, **kwargs):
api12_url = kwargs['api12_url'] #86
self.ctype = kwargs['ctype']
self.title = kwargs['title']

else:
api_url = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % self.vid
api12_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % self.vid
Expand Down Expand Up @@ -330,36 +330,36 @@ def extract(self, **kwargs):

def open_download_by_vid(self, client_id, vid, **kwargs):
"""self, str, str, **kwargs->None
Arguments:
client_id: An ID per client. For now we only know Acfun's
such ID.
vid: An video ID for each video, starts with "C".
kwargs['embsig']: Youku COOP's anti hotlinking.
For Acfun, an API call must be done to Acfun's
server, or the "playsign" of the content of sign_url
shall be empty.
Misc:
Override the original one with VideoExtractor.
Author:
Most of the credit are to @ERioK, who gave his POC.
History:
Jul.28.2016 Youku COOP now have anti hotlinking via embsig. """
self.f_code_1 = '10ehfkbv' #can be retrived by running r.translate with the keys and the list e
self.f_code_2 = 'msjv7h2b'

# as in VideoExtractor
self.url = None
self.vid = vid
self.name = "优酷开放平台 (Youku COOP)"

#A little bit of work before self.prepare

#Change as Jul.28.2016 Youku COOP updates its platform to add ant hotlinking
if kwargs['embsig']:
sign_url = "https://api.youku.com/players/custom.json?client_id={client_id}&video_id={video_id}&embsig={embsig}".format(client_id = client_id, video_id = vid, embsig = kwargs['embsig'])
Expand All @@ -371,9 +371,9 @@ def open_download_by_vid(self, client_id, vid, **kwargs):
#to be injected and replace ct10 and 12
api85_url = 'http://play.youku.com/partner/get.json?cid={client_id}&vid={vid}&ct=85&sign={playsign}'.format(client_id = client_id, vid = vid, playsign = playsign)
api86_url = 'http://play.youku.com/partner/get.json?cid={client_id}&vid={vid}&ct=86&sign={playsign}'.format(client_id = client_id, vid = vid, playsign = playsign)

self.prepare(api_url = api85_url, api12_url = api86_url, ctype = 86, **kwargs)

#exact copy from original VideoExtractor
if 'extractor_proxy' in kwargs and kwargs['extractor_proxy']:
unset_proxy()
Expand Down

0 comments on commit 64dca21

Please sign in to comment.