def start_download(self, torrent): """ Start downloading a particular torrent and add it to download list in Tribler """ dscfg = DownloadStartupConfig() dscfg.set_dest_dir(self.settings.credit_mining_path) dscfg.set_safe_seeding(False) preload = torrent.get('preload', False) if self.session.lm.download_exists(torrent["metainfo"].get_infohash()): self._logger.error("Already downloading %s. Cancel start_download", hexlify(torrent["metainfo"].get_infohash())) return self._logger.info("Starting %s preload %s", hexlify(torrent["metainfo"].get_infohash()), preload) torrent['download'] = self.session.lm.add(torrent['metainfo'], dscfg, hidden=True, share_mode=not preload, checkpoint_disabled=True) torrent['download'].set_priority(torrent.get('prio', 1))
def create_dconfig_from_params(parameters): """ Create a download configuration based on some given parameters. Possible parameters are: - anon_hops: the number of hops for the anonymous download. 0 hops is equivalent to a plain download - safe_seeding: whether the seeding of the download should be anonymous or not (0 = off, 1 = on) - destination: the destination path of the torrent (where it is saved on disk) """ download_config = DownloadStartupConfig() anon_hops = 0 if 'anon_hops' in parameters and len(parameters['anon_hops']) > 0: if parameters['anon_hops'][0].isdigit(): anon_hops = int(parameters['anon_hops'][0]) safe_seeding = False if 'safe_seeding' in parameters and len(parameters['safe_seeding']) > 0 \ and parameters['safe_seeding'][0] == "1": safe_seeding = True if anon_hops > 0 and not safe_seeding: return None, "Cannot set anonymous download without safe seeding enabled" if anon_hops > 0: download_config.set_hops(anon_hops) if safe_seeding: download_config.set_safe_seeding(True) if 'destination' in parameters and len(parameters['destination']) > 0: if not os.path.isdir(parameters['destination'][0]): return None, "Invalid destination directory specified" download_config.set_dest_dir(parameters['destination'][0]) if 'selected_files[]' in parameters: selected_files_list = [ unicode(f, 'utf-8') for f in parameters['selected_files[]'] ] download_config.set_selected_files(selected_files_list) return download_config, None
def create_dconfig_from_params(parameters): """ Create a download configuration based on some given parameters. Possible parameters are: - anon_hops: the number of hops for the anonymous download. 0 hops is equivalent to a plain download - safe_seeding: whether the seeding of the download should be anonymous or not (0 = off, 1 = on) - destination: the destination path of the torrent (where it is saved on disk) """ download_config = DownloadStartupConfig() anon_hops = 0 if 'anon_hops' in parameters and len(parameters['anon_hops']) > 0: if parameters['anon_hops'][0].isdigit(): anon_hops = int(parameters['anon_hops'][0]) safe_seeding = False if 'safe_seeding' in parameters and len(parameters['safe_seeding']) > 0 \ and parameters['safe_seeding'][0] == "1": safe_seeding = True if anon_hops > 0 and not safe_seeding: return None, "Cannot set anonymous download without safe seeding enabled" if anon_hops > 0: download_config.set_hops(anon_hops) if safe_seeding: download_config.set_safe_seeding(True) if 'destination' in parameters and len(parameters['destination']) > 0: dest_dir = cast_to_unicode_utf8(parameters['destination'][0]) download_config.set_dest_dir(dest_dir) if 'selected_files[]' in parameters: selected_files_list = [cast_to_unicode_utf8(f) for f in parameters['selected_files[]']] download_config.set_selected_files(selected_files_list) return download_config, None