📄 getscrapedata.py
字号:
from BitTorrent.bencode import *
from BitTorrent.zurllib import urlopen
from sha import sha
import re
import binascii
def getScrapeData(metainfo, parent):
announce = None
# connect scrape at tracker and get data
# save at self.currentpeer, self.currentseed
# if error put '?'
if metainfo is None:
parent.currentseed = "?"
parent.currentpeer = "?"
else:
info = metainfo['info']
info_hash = sha(bencode(info))
if metainfo.has_key('announce'):
announce = metainfo['announce']
else:
announce = None
if metainfo.has_key('announce-list'):
announce_list = metainfo['announce-list']
else:
announce_list = None
if announce is None and announce_list is not None :
announce = annouce_list[0][0]
if announce is not None:
p = re.compile( '(.*/)[^/]+')
surl = p.sub (r'\1', announce)
surl = surl + "scrape?info_hash="
info_hash_hex = info_hash.hexdigest()
hashlen = len(info_hash_hex)
for i in range(0, hashlen):
if (i % 2 == 0):
surl = surl + "%"
surl = surl + info_hash_hex[i]
# connect scrape URL
try :
h = urlopen(surl)
scrapedata = h.read()
h.close()
scrapedata = bdecode(scrapedata)
scrapedata = scrapedata['files']
for i in scrapedata.keys():
if binascii.b2a_hex(i) == info_hash_hex:
parent.currentpeer = str(scrapedata[i]['incomplete'])
parent.currentseed = str(scrapedata[i]['complete'])
break
except:
parent.currentpeer = "?"
parent.currentseed = "?"
else:
parent.currentpeer = "?"
parent.currentseed = "?"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -