def copy_torrent(self, torrent_path): settings = self.settings if settings.copy_torrent_path and filesystem.exists( settings.copy_torrent_path): dest_path = filesystem.join(self.settings.copy_torrent_path, filesystem.basename(torrent_path)) filesystem.copyfile(torrent_path, dest_path)
def move_file_to(self, path): src = self.get_filename() dirname = filesystem.dirname(path) if not filesystem.exists(dirname): filesystem.makedirs(dirname) filesystem.copyfile(src, path) filesystem.remove(src) self.saved_to = path self.log('{} was moved to {}'.format(src, path))
def _AddTorrent(self, path): if filesystem.exists(path): if path.startswith(r'\\') or '://' in path: tempPath = xbmc.translatePath('special://temp').decode('utf-8') destPath = filesystem.join(tempPath, 't2h.torrent') filesystem.copyfile(path, destPath) path = destPath uri = path2url(path) else: uri = path self.debug('AddTorrent: ' + uri) add_trackers = [] if getSetting('add_tracker'): add_trackers.append(getSetting('add_tracker')) download_path = self.settings.storage_path if download_path == '': download_path = xbmc.translatePath('special://temp') self.debug('download_path: %s' % download_path) self.download_path = download_path encryption = self.debug_assignment( Encryption.ENABLED if getSetting('encryption') == 'true' else Encryption.DISABLED, 'encryption') upload_limit = self.debug_assignment( int(getSetting("upload_limit")) * 1024 if getSetting("upload_limit") != "" else 0, "upload_limit") download_limit = self.debug_assignment( int(getSetting("download_limit")) * 1024 if getSetting("download_limit") != "" else 0, "download_limit") if getSetting("connections_limit") not in ["", 0, "0"]: connections_limit = self.debug_assignment( int(getSetting("connections_limit")), "connections_limit") else: connections_limit = None use_random_port = self.debug_assignment( True if getSetting('use_random_port') == 'true' else False, 'use_random_port') listen_port = self.debug_assignment( int(getSetting("listen_port")) if getSetting("listen_port") != "" else 62881, "listen_port") if listen_port == 6881: use_random_port = True keep_files = getSetting('action_files').decode('utf-8') != u'удалить' args = { 'uri': uri, 'download_path': download_path, 'user_agent': user_agent, 'encryption': encryption, 'upload_kbps': upload_limit, 'download_kbps': download_limit, 'connections_limit': connections_limit, 'keep_incomplete': False, 'keep_complete': keep_files, 'keep_files': keep_files, 'dht_routers': dht_routers, 'use_random_port': use_random_port, 'listen_port': listen_port, 'log_files_progress': True, 'trackers': add_trackers, 'startup_timeout': 1000 } try: if keep_files: args['resume_file'] = filesystem.join( self.settings.torrents_path(), self.info_hash + '.resume') except BaseException as e: log.print_tb(e) if keep_files: args['resume_file'] = filesystem.join( download_path, self.info_hash + '.resume') if args.get('resume_file'): self.debug('resume file is: ' + args['resume_file']) self.engine = Engine(**args)
def copy_torrent(self): debug('Runner: copy torrent') dest_path = filesystem.join(self.settings.copy_torrent_path, filesystem.basename(self.torrent_path)) filesystem.copyfile(self.torrent_path, dest_path)