def set_torrent_complete(mod): metadata_file = MetadataFile(mod.foldername) metadata_file.read_data(ignore_open_errors=True) metadata_file.set_dirty(False) metadata_file.set_torrent_url(mod.torrent_url) metadata_file.set_torrent_content(mod.torrent_content) metadata_file.set_torrent_resume_data('') metadata_file.set_force_creator_complete(True) metadata_file.write_data()
def prepare_libtorrent_params(self, mod, force_sync=False, just_seed=False): """Prepare mod for download over bittorrent. This effectively downloads the .torrent file if its contents are not already cached. Also set all the parameters required by libtorrent. """ # TODO: Add the check: mod name == torrent directory name # === Metadata handling === metadata_file = MetadataFile(mod.foldername) metadata_file.read_data( ignore_open_errors=True ) # In case the mod does not exist, we would get an error # Clear the force clean flag metadata_file.set_force_creator_complete(False) # A little bit of a workaround. If we intend to seed, we can assume the data is all right. # This way, if the torrent is closed before checking_resume_data is finished, and the post- # download hook is not fired, the torrent is not left in a state marked as dirty. if not just_seed and not force_sync: metadata_file.set_dirty( True ) # Set as dirty in case this process is not terminated cleanly # If the torrent url changed, invalidate the resume data old_torrent_url = metadata_file.get_torrent_url() if old_torrent_url != mod.torrent_url or force_sync: metadata_file.set_torrent_resume_data('') metadata_file.set_torrent_content('') # print "Setting torrent url to {}".format(mod.torrent_url) metadata_file.set_torrent_url(mod.torrent_url) metadata_file.write_data() # End of metadata handling # === Torrent parameters === params = { 'save_path': encode_utf8(mod.parent_location), 'storage_mode': libtorrent.storage_mode_t. storage_mode_allocate, # Reduce fragmentation on disk 'flags': torrent_utils.create_add_torrent_flags(just_seed) } torrent_info, torrent_content = self.get_mod_torrent_metadata( mod, metadata_file) params['ti'] = torrent_info # Cache it for future requests metadata_file.set_torrent_content(torrent_content) metadata_file.write_data() # Add optional resume data resume_data = metadata_file.get_torrent_resume_data() if resume_data: # Quick resume torrent from data saved last time the torrent was run params['resume_data'] = resume_data mod.libtorrent_params = params if not just_seed: # Ensure the mod directory is correct (no bad links and read-write) # This should have been already done with preparer.py but it doesn't # hurt to do that again in case something changed in the meantime. torrent_utils.prepare_mod_directory(mod.get_full_path())