Exemple #1
0
        def downloadURL(self, dest_path, url):
            uiname   = 'bittorrent-console'
            defaults = get_defaults(uiname)
            
            # TODO: Bring these in from the plugin's config?
            config_in  = {
                'save_in':                  dest_path,
                'display_interval':         10,
                'max_upload_rate':          8,
                'start_trackerless_client': True,
                'spew':                     False,
                'max_startup_wait':         2 * 60
            }

            try:
                config, args = configfile.parse_configuration_and_args\
                        (defaults, uiname, [], 0, 0)

                config.update(config_in)
                
                metainfo, errors = GetTorrent.get(url)
                if errors:
                    raise BTFailure(_("Error reading .torrent file: ") +\
                        '\n'.join(errors))

            except BTFailure, e:
                self.log.exception("Problem initializing torrent")
                return []
Exemple #2
0
    def main(self):
        print "TorrentClient.run"
        """Main loop"""
        uiname = 'bittorrent-console'
        defaults = get_defaults(uiname)
        defaults.append((
            'twisted', 0,
            _("Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted"
              )))

        metainfo = None
        config, args = configfile.parse_configuration_and_args(
            defaults, uiname)

        try:
            metainfo, errors = GetTorrent.get(self.torrentfilename)
            if errors:
                raise BTFailure(
                    _("Error reading .torrent file: ") + '\n'.join(errors))
            else:
                self.dl = DLKamaelia(metainfo, config, self)
                self.dl.run()
        except BTFailure, e:
            print str(e)
            sys.exit(1)
    def add_task(self, taskid, torrentfile, singledl_config = {}, sha1=None, is_persistent_tasks = True, expire = 0):
	'''
	    would raise Exception if something is wrong
	'''
        if sha1 and self.dls.has_key(sha1):
            self._logger.error('sha1: %s is already downloading', sha1)
            return self.dls[sha1][0]

        for (hash_info, (dl, f)) in self.dls.items():
            if f == torrentfile:
                status = dl.get_activity()
                self._logger.error('file: %s already downloading, status: %s', f, status)
                return dl

        if torrentfile is not None:
            metainfo, errors = GetTorrent.get(torrentfile)
            if errors:
                raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors))
        else:
            raise BTFailure(_("you must specify a .torrent file"))

	self.check_whether_can_add_task()

        dl = DL(taskid, metainfo, self.config, singledl_config, self.multitorrent, self.doneflag)
        dl.start()

        expire = self.expire_time if expire <= 0 else expire
        self.tasks[dl.hash_info] = {'taskid': taskid, 'torrentfile': torrentfile, 'status':{},'config':singledl_config,
                                    'begintime': int(time.time()), 'expire': expire}
        self.dls[dl.hash_info] = (dl, torrentfile)
        if is_persistent_tasks:
            self.persistent_tasks(self.tasks)
        return dl
    def main(self):
        print "TorrentClient.run"
        """Main loop"""
        uiname = "bittorrent-console"
        defaults = get_defaults(uiname)
        defaults.append(
            (
                "twisted",
                0,
                _(
                    "Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted"
                ),
            )
        )

        metainfo = None
        config, args = configfile.parse_configuration_and_args(defaults, uiname)

        try:
            metainfo, errors = GetTorrent.get(self.torrentfilename)
            if errors:
                raise BTFailure(_("Error reading .torrent file: ") + "\n".join(errors))
            else:
                self.dl = DLKamaelia(metainfo, config, self)
                self.dl.run()
        except BTFailure, e:
            print str(e)
            sys.exit(1)
 def main(self):
     print "TorrentClient.run"
     """Main loop"""
     uiname = 'bittorrent-console'
     defaults = get_defaults(uiname)
     defaults["twisted"] = 0
     metainfo = None
     config, args = configfile.parse_configuration_and_args(defaults, uiname)
     try:
         metainfo, errors = GetTorrent.get( self.torrentfilename )
         if errors:
             raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors))
         else:
             self.dl = DLKamaelia(metainfo, config, self)
             self.dl.run()
     except BTFailure, e:
         print str(e)
         sys.exit(1)
Exemple #6
0
 def main(self):
     print "TorrentClient.run"
     """Main loop"""
     uiname = 'bittorrent-console'
     defaults = get_defaults(uiname)
     defaults["twisted"] = 0
     metainfo = None
     config, args = configfile.parse_configuration_and_args(
         defaults, uiname)
     try:
         metainfo, errors = GetTorrent.get(self.torrentfilename)
         if errors:
             raise BTFailure(
                 _("Error reading .torrent file: ") + '\n'.join(errors))
         else:
             self.dl = DLKamaelia(metainfo, config, self)
             self.dl.run()
     except BTFailure, e:
         print str(e)
         sys.exit(1)
    if len(sys.argv) <= 1:
        printHelp(uiname, defaults)
        sys.exit(1)
    try:
        config, args = configfile.parse_configuration_and_args(defaults,
                                       uiname, sys.argv[1:], 0, 1)

        torrentfile = None
        if len(args):
            torrentfile = args[0]
        for opt in ('responsefile', 'url'):
            if config[opt]:
                print '"--%s"' % opt, _("deprecated, do not use")
                torrentfile = config[opt]
        if torrentfile is not None:
            metainfo, errors = GetTorrent.get(torrentfile)
            if errors:
                raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors))
        else:
            raise BTFailure(_("you must specify a .torrent file"))
    except BTFailure, e:
        print str(e)
        sys.exit(1)

    errlist = []
    dl = DL(metainfo, config, errlist)
    curses_wrapper(dl.run)

    if errlist:
       print _("These errors occurred during execution:")
       for error in errlist:
Exemple #8
0
    if len(sys.argv) <= 1:
        printHelp(uiname, defaults)
        sys.exit(1)
    try:
        config, args = configfile.parse_configuration_and_args(
            defaults, uiname, sys.argv[1:], 0, 1)

        torrentfile = None
        if len(args):
            torrentfile = args[0]
        for opt in ('responsefile', 'url'):
            if config[opt]:
                print '"--%s"' % opt, _("deprecated, do not use")
                torrentfile = config[opt]
        if torrentfile is not None:
            metainfo, errors = GetTorrent.get(torrentfile)
            if errors:
                raise BTFailure(
                    _("Error reading .torrent file: ") + '\n'.join(errors))
        else:
            raise BTFailure(_("you must specify a .torrent file"))
    except BTFailure, e:
        print str(e)
        sys.exit(1)

    errlist = []
    dl = DL(metainfo, config, errlist)
    curses_wrapper(dl.run)

    if errlist:
        print _("These errors occurred during execution:")
    for p in to_add:                # then, parse new and changed torrents
        new_file = new_files[p]
        v = new_file[0]             # new_file[0] is the file's (mod time,sz).
        infohash = new_file[1]
        if infohash in new_parsed:  # duplicate, i.e., have same infohash.
            if p not in blocked or files[p][0] != v:
                errfunc(_("**warning** %s is a duplicate torrent for %s") %
                        (p, new_parsed[infohash]['path']))
            new_blocked.add(p)
            continue

        if NOISY:
            errfunc('adding '+p)

        try:
            metainfo = GetTorrent.get(p)
            new_file[1] = metainfo.infohash

            #ff = open(p, 'rb')
            #d = bdecode(ff.read())
            #check_message(d)
            #h = sha(bencode(d['info'])).digest()
            #new_file[1] = h
            if new_parsed.has_key(metainfo.infohash):
                errfunc(_("**warning** %s is a duplicate torrent for %s") %
                        (p, new_parsed[metainfo.infohash][0]))
                new_blocked.add(p)
                continue
            
            #a = {}
            #a['path'] = p