Skip to content

Instantly share code, notes, and snippets.

@fcicq
Created June 8, 2012 08:12
Show Gist options
  • Select an option

  • Save fcicq/2894419 to your computer and use it in GitHub Desktop.

Select an option

Save fcicq/2894419 to your computer and use it in GitHub Desktop.
Old gougou interface, now obsoleted
# -*- coding: utf-8 -*-
# GPLv2, by fcicq
import urllib2, json, StringIO, gzip, base64
def decodethunderuri(str):
if isinstance(str, unicode): str = str.encode('utf-8')
origstr = str
if str.startswith('thunder://'):
str = str[10:]
if len(str) % 4 != 0: str += '=' * (4- len(str) % 4)
try:
str = base64.b64decode(str)[2:]
rpos = str.rfind('ZZ')
str = str[:rpos].strip()
except:
str = origstr
if str.find('迅雷网邻') != -1: return 'Local'
if str.find('//127.0.0.1') != -1: return 'Local'
if str.find('//192.168.') != -1: return 'Local'
if str.endswith('xln'): return 'Local'
if str.find('.vip.xunlei.com/') != -1: return 'Local1'
if str.find('.sandai.net/') != -1: return 'Local1'
if str.find('.ftn.qq.com/') != -1: return 'Local1'
return str
def gzip_uncompress(str):
data = None
try:
compressedstream = StringIO.StringIO(str)
gzipper = gzip.GzipFile(fileobj=compressedstream)
data = gzipper.read()
except:
data = str
return data
def geturi_resbyuid(uid, pagenum=1, pagesize=20):
return 'http://interfacew.q.gougou.com:8080/get_rlist?uid=%d&version=1&p=%d&n=%d&bk=bkHaveResource' % (uid, pagenum, pagesize)
def geturi_attbyuid(uid, pagenum=1, pagesize=20):
return 'http://interfacew.q.gougou.com:8080/get_all_my_attention_friends?version=1&uid=%s&bk=bkAllUser&page=%d&pagenum=%d' % (uid, pagenum, pagesize)
def getmagnet(sha1str):
# return 'magnet:?xt=urn:btih:' + base64.b32encode(sha1str.decode('hex'))
return 'magnet:?xt=urn:btih:' + sha1str
def stripgougoujson(str):
lpos = str.find('{')
rpos = str.rfind(';if')
return str[lpos:rpos]
def fetch_gougou(uri):
str = gzip_uncompress(urllib2.urlopen(uri).read())
str = stripgougoujson(str)
d = json.loads(str, 'gbk')
return d
def listuser():
uri1 = 'http://www.gougou.com/js/topAuthorize.js?bk=bkAuthorize'
d = fetch_gougou(uri1)
return getuserlist(d)
def getresbyuid(uid, pagenum=1, pagesize=50):
uri = geturi_resbyuid(uid, pagenum, pagesize)
return fetch_gougou(uri)
def getuserlist(d):
res = []
for i in d['data']:
res.append(int(i['userid']))
return res
def getattbyuid(uid, pagenum=1, pagesize=50):
uri = geturi_attbyuid(uid, pagenum, pagesize)
d = fetch_gougou(uri)
return getuserlist(d)
def printresdata(d): # put d['data']
for i in d:
print getmagnet(i['cid']), i['cid'], 'gcid', i['gcid']
print i['rid_name'].encode('utf-8'), i['fname'].encode('utf-8'), i['fsize']
print decodethunderuri(i['res_url'])
print
#print listuser()
l = getattbyuid(FILLTHIS) #FIXME
for i in l:
d = getresbyuid(i)
printresdata(d['data'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment