Try to use sogou proxy if youku videos are blocked #1779

Closed
wants to merge 2 commits into from

2 participants

@yan12125
Collaborator

The core algorithm is from xiaoxia@xiaoxia.org. Use with the permission from XiaoXia. See the comments at 2013/08/18 in http://xiaoxia.org/2011/11/14/update-sogou-proxy-program-with-https-support/

@phihag phihag and 1 other commented on an outdated diff Nov 17, 2013
youtube_dl/extractor/youku.py
+ 'http': 'h0.edu.bj.ie.sogou.com'
+ })
+ opener = compat_urllib_request.build_opener(proxy_handler)
+ old_opener = compat_urllib_request.install_opener(opener)
+ t = hex(int(time.time()))[2:].rstrip('L').zfill(8)
+ proxied_request = compat_urllib_request.Request(info_url)
+ proxied_request.add_header('X-Sogou-Auth', self.x_sogou_auth)
+ proxied_request.add_header('X-Sogou-Tag', self.calc_sogou_hash(t, 'v.youku.com'))
+ proxied_request.add_header('X-Sogou-Timestamp', t)
+ jsondata = self._download_webpage(proxied_request, video_id)
+ config = json.loads(jsondata)
+ error_code = config['data'][0].get('error_code')
+ # XXX: needs a way to restore the original proxy settings
+ compat_urllib_request.install_opener(compat_urllib_request.build_opener(compat_urllib_request.ProxyHandler({})))
+ else:
+ print 'hahaha'
@phihag
Collaborator
phihag added a note Nov 17, 2013

This fails on python 3 and doesn't look too good.

@yan12125
Collaborator

The previous commit (d1c2520) can't be run under python 3 (I use 3.2.3), either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@phihag phihag commented on the diff Nov 17, 2013
youtube_dl/extractor/youku.py
@@ -121,3 +142,50 @@ def _real_extract(self, url):
files_info.append(info)
return files_info
+
+ x_sogou_auth = "9CD285F1E7ADB0BD403C22AD1D545F40/30/853edc6d49ba4e27"
+
+ # http://xiaoxia.org/2011/11/14/update-sogou-proxy-program-with-https-support/
+ def calc_sogou_hash(self, t, host):
@phihag
Collaborator
phihag added a note Nov 17, 2013

What is t here?

@yan12125
Collaborator

t is the timestamp in Beiging time, or GMT+8

There is a detailed discussion of the Sogou proxy's authentication (in Chinese, however):
http://xiaoxia.org/2011/03/10/depressed-research-about-sogou-proxy-server-authentication-protocol/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@phihag
Collaborator

This looks interesting, but I'd rather move the code into a separate sogou extractor.

@phihag
Collaborator

For reference: We support Python 2.6, 2.7 and 3.3+. 3.2 cannot handle 2.x-style character strings, and that makes writing a string-intensive application that supports both 2.x and 3.2 (or even 3.1) very cumbersome.

@yan12125
Collaborator

Thanks for the information. Sorry for the mistake.

@yan12125 yan12125 closed this Nov 3, 2014
@yan12125 yan12125 deleted the yan12125:master branch Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment