Esempio n. 1
0
    def load_torrent(self, torrent, start=False, verbose=False, verify_load=True, verify_retries=3):
        """
        Loads torrent into rTorrent (with various enhancements)

        @param torrent: can be a url, a path to a local file, or the raw data
        of a torrent file
        @type torrent: str

        @param start: start torrent when loaded
        @type start: bool

        @param verbose: print error messages to rTorrent log
        @type verbose: bool

        @param verify_load: verify that torrent was added to rTorrent successfully
        @type verify_load: bool

        @return: Depends on verify_load:
                 - if verify_load is True, (and the torrent was
                 loaded successfully), it'll return a L{Torrent} instance
                 - if verify_load is False, it'll return None

        @rtype: L{Torrent} instance or None

        @raise AssertionError: If the torrent wasn't successfully added to rTorrent
                               - Check L{TorrentParser} for the AssertionError's
                               it raises


        @note: Because this function includes url verification (if a url was input)
        as well as verification as to whether the torrent was successfully added,
        this function doesn't execute instantaneously. If that's what you're
        looking for, use load_torrent_simple() instead.
        """
        p = self._get_conn()
        tp = TorrentParser(torrent)
        torrent = xmlrpclib.Binary(tp._raw_torrent)
        info_hash = tp.info_hash

        func_name = self._get_load_function("raw", start, verbose)

        # load torrent
        getattr(p, func_name)(torrent)

        if verify_load:
            i = 0
            while i < verify_retries:
                self.get_torrents()
                if info_hash in [t.info_hash for t in self.torrents]:
                    break

                # was still getting AssertionErrors, delay should help
                time.sleep(1)
                i += 1

            assert info_hash in [t.info_hash for t in self.torrents],\
                "Adding torrent was unsuccessful."

        return(find_torrent(info_hash, self.torrents))
Esempio n. 2
0
    def load_torrent(self, torrent, **kwargs):
        """
        Load torrent into rTorrent (with various enhancements).
        @param torrent: can be a url, a path to a local file, or the raw data
        of a torrent file
        @type torrent: str
        @param start: start torrent when loaded
        @type start: bool
        @param verbose: print error messages to rTorrent log
        @type verbose: bool
        @param verify_load: verify that torrent was added to rTorrent successfully
        @type verify_load: bool
        @return: Depends on verify_load:
                 - if verify_load is True, (and the torrent was
                 loaded successfully), it'll return a L{Torrent} instance
                 - if verify_load is False, it'll return None
        @rtype: L{Torrent} instance or None
        @raise AssertionError: If the torrent wasn't successfully added to rTorrent
                               - Check L{TorrentParser} for the AssertionError's
                               it raises
        @note: Because this function includes url verification (if a url was input)
        as well as verification as to whether the torrent was successfully added,
        this function doesn't execute instantaneously. If that's what you're
        looking for, use load_torrent_simple() instead.
        """
        start = kwargs.pop('start', False)
        verbose = kwargs.pop('verbose', False)
        verify_load = kwargs.pop('verify_load', True)
        max_retries = kwargs.pop('max_retries', 5)
        params = kwargs.pop('params', [])
        target = kwargs.pop('target', '')

        p = self._get_conn()
        tp = TorrentParser(torrent)
        torrent = xmlrpc.client.Binary(tp._raw_torrent)
        info_hash = tp.info_hash

        func_name = self._get_load_function('raw', start, verbose)

        getattr(p, func_name)(target, torrent, *params)

        if verify_load:
            i = 0
            while i < max_retries:
                for torrent in self.get_torrents():
                    if torrent.info_hash == info_hash:
                        return True
                time.sleep(1)
                i += 1
            return False

        return True
Esempio n. 3
0
    def load_torrent(self,
                     new_torrent,
                     start=False,
                     verbose=False,
                     verify_load=True):  # @IgnorePep8
        """
        Loads torrent into rTorrent (with various enhancements)

        @param new_torrent: can be a url, a path to a local file, or the raw data
        of a torrent file
        @type new_torrent: str

        @param start: start torrent when loaded
        @type start: bool

        @param verbose: print error messages to rTorrent log
        @type verbose: bool

        @param verify_load: verify that torrent was added to rTorrent successfully
        @type verify_load: bool

        @return: Depends on verify_load:
                 - if verify_load is True, (and the torrent was
                 loaded successfully), it'll return a L{Torrent} instance
                 - if verify_load is False, it'll return None

        @rtype: L{Torrent} instance or None

        @raise AssertionError: If the torrent wasn't successfully added to rTorrent
                               - Check L{TorrentParser} for the AssertionError's
                               it raises


        @note: Because this function includes url verification (if a url was input)
        as well as verification as to whether the torrent was successfully added,
        this function doesn't execute instantaneously. If that's what you're
        looking for, use load_torrent_simple() instead.
        """
        p = self._get_conn()
        tp = TorrentParser(new_torrent)
        new_torrent = xmlrpclib.Binary(tp._raw_torrent)
        info_hash = tp.info_hash

        func_name = self._get_load_function("raw", start, verbose)

        # load torrent
        getattr(p, func_name)(new_torrent)

        if verify_load:
            new_torrent = None
            for i in range(MAX_RETRIES):
                time.sleep(2)
                new_torrent = self.find_torrent(info_hash)
                if new_torrent:
                    break

            assert new_torrent, "Adding torrent was unsuccessful after {0} seconds. (load_torrent)".format(
                MAX_RETRIES * 2)

            # Skip the find_torrent (slow) below when verify_load
            return new_torrent

        return self.find_torrent(info_hash)