Ejemplo n.º 1
0
    def _getTorrentHash(self, download):
        headers = download.extra_data["headers"] if "headers" in download.extra_data else {}
        response = requests.get(download.url, headers=headers)

        if response.status_code == 200:
            metainfo = bencode.bdecode(response.content)
            info = metainfo["info"]
            return (True, Binary(response.content), hashlib.sha1(bencode.bencode(info)).hexdigest().upper())
        else:
            log.info("Download torrent file for rutorrent failed with url %s" % download.url)
            return (False, None, "")
Ejemplo n.º 2
0
    def _getTorrentHash(self, download):
        headers = download.extra_data[
            'headers'] if 'headers' in download.extra_data else {}
        response = requests.get(download.url, headers=headers)

        if response.status_code == 200:
            metainfo = bencode.bdecode(response.content)
            info = metainfo['info']
            return (True, Binary(response.content),
                    hashlib.sha1(bencode.bencode(info)).hexdigest().upper())
        else:
            log.info("Download torrent file for rutorrent failed with url %s" %
                     download.url)
            return (False, None, '')
Ejemplo n.º 3
0
 def receiver(self):
     while self.isSpiderWorking:
         try:
             (data, address) = self.ufd.recvfrom(65536)
             # print('receive udp packet')
             msg = bdecode(data)
             # print msg
             if msg['y'] == 'r':
                 if 'nodes' in msg['r']:
                     self.process_find_node_response(msg)
             elif msg['y'] == 'q':
                 if msg['q'] == 'ping':
                     self.send_pong(msg, address)
                 elif msg['q'] == 'find_node':
                     self.process_find_node_request(msg, address)
                 elif msg['q'] == 'get_peers':
                     self.process_get_peers_request(msg, address)
                 elif msg['q'] == 'announce_peer':
                     self.process_announce_peer_request(msg, address)
         except:
             pass
Ejemplo n.º 4
0
def getTorrentHash(torrentPath):
    with open(torrentPath, 'rb') as f:
        metainfo = bencode.bdecode(f.read())
    info = metainfo['info']
    return hashlib.sha1(bencode.bencode(info)).hexdigest().upper()
Ejemplo n.º 5
0
def getTorrentHash(torrentPath):
    with open(torrentPath, "rb") as f:
        metainfo = bencode.bdecode(f.read())
    info = metainfo["info"]
    return hashlib.sha1(bencode.bencode(info)).hexdigest().upper()