Пример #1
0
 def _restore_state(self):
     def decode_line(line):
         hashtext = line[:40]
         try:
             infohash = hashtext.decode('hex')
         except:
             raise BTFailure("Invalid state file contents")
         if len(infohash) != 20:
             raise BTFailure("Invalid state file contents")
         try:
             path = os.path.join(self.config['data_dir'], 'metainfo',
                                 hashtext)
             f = file(path, 'rb')
             data = f.read()
             f.close()
         except Exception, e:
             try:
                 f.close()
             except:
                 pass
             self.global_error(ERROR,"Error reading file "+path+" ("+str(e)+
                               "), cannot restore state completely")
             return None
         if infohash in self.torrents:
             raise BTFailure("Invalid state file (duplicate entry)")
         t = TorrentInfo()
         self.torrents[infohash] = t
         try:
             t.metainfo = ConvertedMetainfo(bdecode(data))
         except Exception, e:
             self.global_error(ERROR, "Corrupt data in "+path+
                               " , cannot restore torrent ("+str(e)+")")
             return None
Пример #2
0
    def run(self):
        try:
            self.multitorrent = Multitorrent(self.config, self.doneflag,
                                             self.global_error)
            # raises BTFailure if bad
            metainfo = ConvertedMetainfo(bdecode(self.metainfo))
            torrent_name = metainfo.name_fs
            if self.config['save_as']:
                if self.config['save_in']:
                    raise BTFailure(
                        _("You cannot specify both --save_as and "
                          "--save_in"))
                saveas = self.config['save_as']
            elif self.config['save_in']:
                saveas = os.path.join(self.config['save_in'], torrent_name)
            else:
                saveas = torrent_name

            self.d.set_torrent_values(metainfo.name, os.path.abspath(saveas),
                                      metainfo.total_bytes,
                                      len(metainfo.hashes))
            self.torrent = self.multitorrent.start_torrent(
                metainfo, Preferences(self.config), self, saveas)
        except BTFailure, e:
            print str(e)
            return
Пример #3
0
    def run(self, scrwin):
        def reread():
            self.multitorrent.rawserver.external_add_task(
                self.reread_config, 0)

        self.d = CursesDisplayer(scrwin, self.errlist, self.doneflag, reread)
        try:
            self.multitorrent = Multitorrent(self.config, self.doneflag,
                                             self.global_error)
            # raises BTFailure if bad
            metainfo = ConvertedMetainfo(bdecode(self.metainfo))
            torrent_name = metainfo.name_fs
            if config['save_as']:
                if config['save_in']:
                    raise BTFailure('You cannot specify both --save_as and '
                                    '--save_in')
                saveas = config['save_as']
            elif config['save_in']:
                saveas = os.path.join(config['save_in'], torrent_name)
            else:
                saveas = torrent_name

            self.d.set_torrent_values(metainfo.name, os.path.abspath(saveas),
                                      metainfo.total_bytes,
                                      len(metainfo.hashes))
            self.torrent = self.multitorrent.start_torrent(
                metainfo, self.config, self, saveas)
        except BTFailure, e:
            errlist.append(str(e))
            return
Пример #4
0
 def start_new_torrent(self, data):
     t = TorrentInfo()
     try:
         t.metainfo = ConvertedMetainfo(bdecode(data))
     except Exception, e:
         self.global_error(ERROR, "This is not a valid torrent file. (%s)"
                           % str(e))
         return
Пример #5
0
 def start_new_torrent(self, data, save_as=None):
     t = TorrentInfo(Preferences(self.config))
     try:
         t.metainfo = ConvertedMetainfo(bdecode(data))
     except Exception, e:
         self.global_error(
             ERROR,
             _("This is not a valid torrent file. (%s)") % str(e))
         return
Пример #6
0
 def check_hashcheck_queue(self):
     if self.hashcheck_current is not None or not self.hashcheck_queue:
         return
     self.hashcheck_current = self.hashcheck_queue.pop(0)
     metainfo = self.hashcheck_store[self.hashcheck_current]
     del self.hashcheck_store[self.hashcheck_current]
     filename = self.determine_filename(self.hashcheck_current)
     self.downloads[self.hashcheck_current] = self.multitorrent. \
                       start_torrent(ConvertedMetainfo(metainfo),
                                     self.config, self, filename)
Пример #7
0
    def decodeTorrent(self, data):
        """\
        Converts bencoded raw metadata (as one would find in a .torrent file) into
        a metainfo object (which one can then get the torrent's properties from).
        """

        from BitTorrent.bencode import bdecode, bencode
        metainfo = None
        try:
            b = bdecode(data)
            metainfo = ConvertedMetainfo(b)
        except Exception, e:
            pass