Exemplo n.º 1
0
    def __init__(self, filepath, destination='/home/simon/Downloads/'):
        self.origin = open(filepath, 'rb').read()
        self.dest = destination
        mf = wsbencode.decode(self.origin)

        #General

        self.info = mf['info']
        self.announce = mf['announce']

        try:
            self.al = mf['announce-list']
        except:
            pass

        self.info_hash = hashlib.sha1(wsbencode.encode(self.info)).digest()

        #Common info

        self.pieces = self.info['pieces']
        self.plen = self.info['piece length']
        try:
            self.private = self.info['private']
        except:
            pass
        self.name = self.info['name']

        self.tlen = 0
        self.fli = []

        #Try multiple or single files
        #optie toevoegen voor delen van torrents door de piece index range te bepalen
        try:
            for i in self.info['files']:
                files = {}
                self.tlen += i['length']
                length = i['length']
                path = i['path'][0]
                if len(i['path']) > 1:
                    path += '/' + i['path'][1]
                files['path'] = path
                files['length'] = length
                files['pir'] = [ self.tlen - length, self.tlen]


                self.fli.append(files)

            self.multiple = True
            try:
                os.mkdir(self.dest + self.name)
            except:
                pass
        except:
            self.tlen = self.info['length']
            path = self.info['name']
            self.fli.append({'path' : path, 'length' : self.tlen})
            self.multiple = False
        self.pc = int(len(self.pieces)/20)
        self.pli = []
        for i in range(self.pc):
            self.pli.append(i)
Exemplo n.º 2
0
 def __init__(self, announce, info_hash, filesize, peer_id=b'-wS0002-'):
     self.announce = announce
     self.peer_id = peer_id + encode(str(randint(100000000000,999999999999)))
     self.payload = {'info_hash' : info_hash ,'peer_id' : peer_id ,'left' : filesize}
     self.response = requests.get(announce, params=self.payload).content
     self.dec_resp = wsbencode.decode(self.response)