def load_torrent(self, torrent, start=False, verbose=False, verify_load=True): """ 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: MAX_RETRIES = 3 i = 0 while i < MAX_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))
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))
def _manage_torrent_cache(self): """Carry tracker/peer/file lists over to new torrent list.""" for torrent in self._torrent_cache: new_torrent = common.find_torrent(torrent.info_hash, self.torrents) if new_torrent is not None: new_torrent.files = torrent.files new_torrent.peers = torrent.peers new_torrent.trackers = torrent.trackers self._torrent_cache = self.torrents
def find_torrent(self, info_hash): """Frontend for rtorrent.common.find_torrent.""" return (common.find_torrent(info_hash, self.get_torrents()))
def find_torrent(self, info_hash): """Frontend for rtorrent.common.find_torrent.""" return(common.find_torrent(info_hash, self.get_torrents()))