def get_trackers(self): """Get list of Tracker instances for given torrent. @return: L{Tracker} instances @rtype: list @note: also assigns return value to self.trackers """ self.trackers = [] retriever_methods = [ m for m in tracker.methods if m.is_retriever() and m.is_available(self._rt_obj) ] # need to leave 2nd arg empty (dunno why) m = rpc.Multicall(self) m.add("t.multicall", self.info_hash, "", *[method.rpc_call + "=" for method in retriever_methods]) results = m.call()[0] # only sent one call, only need first result for result in results: results_dict = {} # build results_dict for m, r in zip(retriever_methods, result): results_dict[m.varname] = rpc.process_result(m, r) self.trackers.append( Tracker(self._rt_obj, self.info_hash, **results_dict)) return (self.trackers)
def close(self): """Close the torrent and it's files""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.close') return mc.call()[-1]
def pause(self): """Pause the torrent""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.pause') return mc.call()[-1]
def resume(self): """Resume the torrent""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.resume') return mc.call()[-1]
def announce(self): """Announce torrent info to tracker(s)""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.tracker_announce') return mc.call()[-1]
def get_trackers(self): """Get list of Tracker instances for given torrent. @return: L{Tracker} instances @rtype: list @note: also assigns return value to self.trackers """ self.trackers = [] retriever_methods = filter(lambda m: m.is_retriever() and m.is_available(self._rt_obj), tracker_methods) mc = rpc.Multicall(self) # need to leave 2nd arg empty (dunno why) mc.add('t.multicall', self.info_hash, '', *[method.rpc_call + '=' for method in retriever_methods]) results = mc.call()[0] # only sent one call, only need first result for result in results: results_dict = {} # build results_dict for mc, r in zip(retriever_methods, result): results_dict[mc.varname] = rpc.process_result(mc, r) self.trackers.append(Tracker(self._rt_obj, self.info_hash, **results_dict)) return self.trackers
def get_torrents(self, view="main"): """Get list of all torrents in specified view @return: list of L{Torrent} instances @rtype: list @todo: add validity check for specified view """ self.torrents = [] methods = torrent.methods retriever_methods = [ m for m in methods if m.is_retriever() and m.is_available(self) ] m = rpc.Multicall(self) m.add("d.multicall", view, "d.get_hash=", *[method.rpc_call + "=" for method in retriever_methods]) results = m.call()[0] # only sent one call, only need first result for result in results: results_dict = {} # build results_dict for m, r in zip(retriever_methods, result[1:]): # result[0] is the info_hash results_dict[m.varname] = rpc.process_result(m, r) self.torrents.append( Torrent(self, info_hash=result[0], **results_dict)) self._manage_torrent_cache() return (self.torrents)
def check_hash(self): """(Re)hash check the torrent""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.check_hash') return mc.call()[-1]
def get_torrents(self, view='main'): """Get list of all torrents in specified view @return: list of L{Torrent} instances @rtype: list @todo: add validity check for specified view """ self.torrents = [] retriever_methods = filter(lambda m: m.is_retriever() and m.is_available(self), torrent_methods) mc = rpc.Multicall(self) if self.method_exists('d.multicall2'): mc.add('d.multicall2', '', view, 'd.hash=', *map(lambda m2: ((getattr(m2, 'aliases') or [''])[-1] or m2.rpc_call) + '=', retriever_methods)) else: mc.add('d.multicall', view, 'd.get_hash=', *map(lambda m1: m1.rpc_call + '=', retriever_methods)) results = mc.call()[0] # only sent one call, only need first result for result in results: self.torrents.append( Torrent(self, info_hash=result[0], **dict((mc.varname, rpc.process_result(mc, r)) for (mc, r) in list(zip(retriever_methods, result[1:]))))) # result[0]=info_hash self._manage_torrent_cache() return self.torrents
def erase(self): """Delete the torrent @note: doesn't delete the downloaded files""" m = rpc.Multicall(self) self.multicall_add(m, "d.erase") return (m.call()[-1])
def stop(self): """"Stop the torrent""" m = rpc.Multicall(self) self.multicall_add(m, "d.try_stop") self.multicall_add(m, "d.is_active") self.active = m.call()[-1] return (self.active)
def erase(self): """Delete the torrent @note: doesn't delete the downloaded files""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.erase') return mc.call()[-1]
def stop(self): """"Stop the torrent""" mc = rpc.Multicall(self) self.multicall_add(mc, 'd.try_stop') self.multicall_add(mc, 'd.is_active') self.active = mc.call()[-1] return self.active
def get_state(self): method = self._get_method(*('d.get_state', 'd.state')) if method: mc = rpc.Multicall(self) self.multicall_add(mc, method) return mc.call()[-1]
def update(self): mc = rpc.Multicall(self) for method in filter( lambda m: m.is_retriever() and m.is_available(self._rt_obj), self.methods): mc.add(method) mc.call()
def accept_seeders(self, accept_seeds): """Enable/disable whether the torrent connects to seeders @param accept_seeds: enable/disable accepting seeders @type accept_seeds: bool""" mc = rpc.Multicall(self) self.multicall_add(mc, ('d.accepting_seeders.disable', 'd.accepting_seeders.enable')[accept_seeds]) return mc.call()[-1]
def set_directory_base(self, d): """Modify base download directory @note: Needs to stop torrent in order to change the directory. Also doesn't restart after directory is set, that must be called separately. """ m = rpc.Multicall(self) self.multicall_add(m, "d.try_stop") self.multicall_add(m, "d.set_directory_base", d)
def set_command(self, *methods): method = self._get_method(*('system.method.set', 'method.set')) if method: methods = [m + '=' for m in methods] mc = rpc.Multicall(self) self.multicall_add(mc, method, self._get_prefix() + 'command', *methods) return mc.call()[-1]
def update(self): """Refresh rTorrent client info @note: All fields are stored as attributes to self. @return: None """ mc = rpc.Multicall(self) for method in filter(lambda m: m.is_retriever() and m.is_available(self), methods): mc.add(method) mc.call()
def update(self): """Refresh peer data @note: All fields are stored as attributes to self. @return: None """ mc = rpc.Multicall(self) for method in filter(lambda fx: fx.is_retriever() and fx.is_available(self._rt_obj), methods): mc.add(method, self.rpc_id) mc.call()
def is_hash_checking_queued(self): """Check if torrent is waiting to be hash checked @note: Variable where the result for this method is stored Torrent.hash_checking_queued""" m = rpc.Multicall(self) self.multicall_add(m, "d.get_hashing") self.multicall_add(m, "d.is_hash_checking") results = m.call() setattr(self, "hashing", results[0]) setattr(self, "hash_checking", results[1]) return (self._is_hash_checking_queued())
def set_directory_base(self, d): """Modify base download directory @note: Needs to stop torrent in order to change the directory. Also doesn't restart after directory is set, that must be called separately. """ method = self._get_method(*('d.set_directory_base', 'd.directory_base.set')) if method: mc = rpc.Multicall(self) self.multicall_add(mc, 'd.try_stop') self.multicall_add(mc, method, d)
def accept_seeders(self, accept_seeds): """Enable/disable whether the torrent connects to seeders @param accept_seeds: enable/disable accepting seeders @type accept_seeds: bool""" if accept_seeds: call = "d.accepting_seeders.enable" else: call = "d.accepting_seeders.disable" m = rpc.Multicall(self) self.multicall_add(m, call) return (m.call()[-1])
def append_tracker(self, tracker): """ Append tracker to current tracker group @param tracker: The tracker url @type tracker: str @return: if successful, 0 @rtype: int """ mc = rpc.Multicall(self) self.multicall_add(mc, 'd.tracker.insert', self.index, tracker) return mc.call()[-1]
def update(self): """Refresh rTorrent client info @note: All fields are stored as attributes to self. @return: None """ multicall = rpc.Multicall(self) retriever_methods = [ m for m in methods if m.is_retriever() and m.is_available(self) ] for method in retriever_methods: multicall.add(method) multicall.call()
def is_hash_checking_queued(self): """Check if torrent is waiting to be hash checked @note: Variable where the result for this method is stored Torrent.hash_checking_queued""" method = self._get_method(*('d.get_hashing', 'd.hashing')) if method: mc = rpc.Multicall(self) self.multicall_add(mc, method) self.multicall_add(mc, 'd.is_hash_checking') results = mc.call() setattr(self, 'hashing', results[0]) setattr(self, 'hash_checking', results[1]) return self._is_hash_checking_queued()
def update(self): """Refresh torrent data @note: All fields are stored as attributes to self. @return: None """ mc = rpc.Multicall(self) for method in filter(lambda m: m.is_retriever() and m.is_available(self._rt_obj), methods): mc.add(method, self.rpc_id) mc.call() # custom functions (only call private methods, since they only check # local variables and are therefore faster) self._call_custom_methods()
def get_custom(self, key): """ Get custom value @param key: the index for the custom field (between 1-5) @type key: int @rtype: str """ self._assert_custom_key_valid(key) m = rpc.Multicall(self) field = "custom{0}".format(key) self.multicall_add(m, "d.get_{0}".format(field)) setattr(self, field, m.call()[-1]) return (getattr(self, field))
def add_tracker(self, group, tracker): """ Add tracker to torrent @param group: The group to add the tracker to @type group: int @param tracker: The tracker url @type tracker: str @return: if successful, 0 @rtype: int """ mc = rpc.Multicall(self) self.multicall_add(mc, 'd.tracker.insert', group, tracker) return mc.call()[-1]
def get_files(self): """Get list of File instances for given torrent. @return: L{File} instances @rtype: list @note: also assigns return value to self.files """ self.files = [] retriever_methods = [ m for m in file.methods if m.is_retriever() and m.is_available(self._rt_obj) ] # 2nd arg can be anything, but it'll return all files in torrent # regardless m = rpc.Multicall(self) m.add("f.multicall", self.info_hash, "", *[method.rpc_call + "=" for method in retriever_methods]) results = m.call()[0] # only sent one call, only need first result offset_method_index = retriever_methods.index( rpc.find_method("f.get_offset")) # make a list of the offsets of all the files, sort appropriately offset_list = sorted([r[offset_method_index] for r in results]) for result in results: results_dict = {} # build results_dict for m, r in zip(retriever_methods, result): results_dict[m.varname] = rpc.process_result(m, r) # get proper index positions for each file (based on the file # offset) f_index = offset_list.index(results_dict["offset"]) self.files.append( File(self._rt_obj, self.info_hash, f_index, **results_dict)) return (self.files)