Scrape patch
In order to scrape some private sites correctly, the query parameters of the announce URL must be present in the scrape URL as well. The following patch changes the scrape code to conform to the BitTorrent Protocol Specification 1.0:
--- scrape.py.orig Thu May 18 11:38:37 2006 +++ scrape.py Thu May 18 12:05:59 2006 @@ -17,22 +17,30 @@ del policy def announce_to_scrape(url): - items = list(urlparse.urlparse(url)) - path = items[2] - return urlparse.urljoin(url, - os.path.basename(path).replace('announce','scrape')) + pos = url.rfind("/") + if pos == -1: + return None + if url[pos:(pos + 9)] != '/announce': + return None + + return url[0:pos] + '/scrape' + url[(pos + 9):] def get_scrape_by_announce_url(announce_url,infohash): seeder,leecher = '?','?' if not announce_url: return seeder,leecher scrape_url = announce_to_scrape(announce_url) + if not scrape_url: + return seeder,leecher len_hash = len(infohash) if len_hash == 40: infohash = binascii.a2b_hex(infohash) - scrape_url += '?info_hash=%s' % urllib.quote(infohash) + if scrape_url.find('?') >= 0: + scrape_url += '&info_hash=%s' % urllib.quote(infohash) + else: + scrape_url += '?info_hash=%s' % urllib.quote(infohash) try: try:
Hope this helps, Sven
- 1733 reads
applied
Post new comment