def start_url(self, uri): if self._th: raise Exception('Torrent is already started') if uri.startswith('http://') or uri.startswith('https://'): self._url = uri stored = self._cache.get_torrent(url=uri) if stored: tp = self.info_from_file(stored) else: tp = {'url': uri} resume_data = self._cache.get_resume(url=uri) if resume_data: tp['resume_data'] = resume_data elif uri.startswith('magnet:'): self._url = uri stored = self._cache.get_torrent(info_hash=CacheBT.hash_from_magnet(uri)) if stored: tp = self.info_from_file(stored) else: tp = {'url': uri} resume_data = self._cache.get_resume(info_hash=CacheBT.hash_from_magnet(uri)) if resume_data: tp['resume_data'] = resume_data elif os.path.isfile(uri): tp = self.info_from_file(uri) else: raise ValueError("Invalid torrent %s" % uri) tp.update(self._torrent_params) self._th = self._ses.add_torrent(tp) for tr in INITIAL_TRACKERS: self._th.add_tracker({'url': tr}) self._th.set_sequential_download(True) time.sleep(1) self._th.force_dht_announce() self._monitor.start() self._dispatcher.do_start(self._th, self._ses)