class Commander: """蓝奏网盘命令行""" def __init__(self): self._prompt = '> ' self._disk = LanZouCloud() # self._disk.ignore_limits() self._task_mgr = global_task_mgr self._dir_list = FolderList() self._file_list = FileList() self._path_list = FolderList() self._parent_id = -1 self._parent_name = '' self._work_name = '' self._work_id = -1 self._last_work_id = -1 self._reader_mode = config.reader_mode self._default_dir_pwd = config.default_dir_pwd self._disk.set_max_size(config.max_size) self._disk.set_upload_delay(config.upload_delay) @staticmethod def clear(): clear_screen() @staticmethod def help(): print_help() @staticmethod def update(): check_update() def bye(self): if self._task_mgr.has_alive_task(): info(f"有任务在后台运行, 退出请直接关闭窗口") else: exit_cmd(0) def rmode(self): """适用于屏幕阅读器用户的显示方式""" choice = input("以适宜屏幕阅读器的方式显示(y): ") if choice and choice.lower() == 'y': config.reader_mode = True self._reader_mode = True info("已启用 Reader Mode") else: config.reader_mode = False self._reader_mode = False info("已关闭 Reader Mode") def cdrec(self): """进入回收站模式""" rec = Recovery(self._disk) rec.run() self.refresh() def xghost(self): """扫描并删除幽灵文件夹""" choice = input("需要清理幽灵文件夹吗(y): ") if choice and choice.lower() == 'y': self._disk.clean_ghost_folders() info("清理已完成") else: info("清理操作已取消") def refresh(self, dir_id=None): """刷新当前文件夹和路径信息""" dir_id = self._work_id if dir_id is None else dir_id self._file_list = self._disk.get_file_list(dir_id) self._dir_list = self._disk.get_dir_list(dir_id) self._path_list = self._disk.get_full_path(dir_id) self._prompt = '/'.join(self._path_list.all_name) + ' > ' self._last_work_id = self._work_id self._work_name = self._path_list[-1].name self._work_id = self._path_list[-1].id if dir_id != -1: # 如果存在上级路径 self._parent_name = self._path_list[-2].name self._parent_id = self._path_list[-2].id def login(self): """使用 cookie 登录""" if not config.cookie or self._disk.login_by_cookie( config.cookie) != LanZouCloud.SUCCESS: open_new_tab('https://pc.woozooo.com/') info("请设置 Cookie 内容:") ylogin = input("ylogin="******"phpdisk_info=") if not ylogin or not disk_info: error("请输入正确的 Cookie 信息") return None cookie = {"ylogin": str(ylogin), "phpdisk_info": disk_info} if self._disk.login_by_cookie(cookie) == LanZouCloud.SUCCESS: config.cookie = cookie else: error("登录失败,请检查 Cookie 是否正确") self.refresh() def logout(self): """注销""" clear_screen() self._prompt = '> ' self._disk.logout() self._file_list.clear() self._dir_list.clear() self._path_list = FolderList() self._parent_id = -1 self._work_id = -1 self._last_work_id = -1 self._parent_name = '' self._work_name = '' config.cookie = None def ls(self): """列出文件(夹)""" if self._reader_mode: # 方便屏幕阅读器阅读 for folder in self._dir_list: pwd_str = '有提取码' if folder.has_pwd else '' print(f"{folder.name}/ {folder.desc} {pwd_str}") for file in self._file_list: pwd_str = '有提取码' if file.has_pwd else '' print( f"{file.name} 大小:{file.size} 上传时间:{file.time} 下载次数:{file.downs} {pwd_str}" ) else: # 普通用户显示方式 for folder in self._dir_list: pwd_str = '✦' if folder.has_pwd else '✧' print("#{0:<12}{1:<4}{2}{3}/".format( folder.id, pwd_str, text_align(folder.desc, 28), folder.name)) for file in self._file_list: pwd_str = '✦' if file.has_pwd else '✧' print("#{0:<12}{1:<4}{2:<12}{3:>8}{4:>6} {5}".format( file.id, pwd_str, file.time, file.size, file.downs, file.name)) def cd(self, dir_name): """切换工作目录""" if not dir_name: info('cd .. 返回上级路径, cd - 返回上次路径, cd / 返回根目录') elif dir_name == '..': self.refresh(self._parent_id) elif dir_name == '/': self.refresh(-1) elif dir_name == '-': self.refresh(self._last_work_id) elif dir_name == '.': pass elif folder := self._dir_list.find_by_name(dir_name): self.refresh(folder.id) else:
class Commander: """蓝奏网盘命令行""" def __init__(self): self._prompt = '> ' self._disk = LanZouCloud() self._dir_list = FolderList() self._file_list = FileList() self._path_list = FolderList() self._parent_id = -1 self._parent_name = '' self._work_name = '' self._work_id = -1 self._last_work_id = -1 self._reader_mode = config.reader_mode self._disk.set_max_size(config.max_size) self._is_login = False @staticmethod def clear(): clear_screen() @staticmethod def help(): print_help() @staticmethod def update(): check_update() def rmode(self): """适用于屏幕阅读器用户的显示方式""" choice = input("以适宜屏幕阅读器的方式显示(y): ") if choice and choice.lower() == 'y': config.reader_mode = True self._reader_mode = True info("已启用 Reader Mode") else: config.reader_mode = False self._reader_mode = False info("已关闭 Reader Mode") def cdrec(self): """进入回收站模式""" rec = Recovery(self._disk) rec.run() self.refresh() def refresh(self, dir_id=None): """刷新当前文件夹和路径信息""" dir_id = self._work_id if dir_id is None else dir_id self._file_list = self._disk.get_file_list(dir_id) self._dir_list = self._disk.get_dir_list(dir_id) self._path_list = self._disk.get_full_path(dir_id) self._prompt = '/'.join(self._path_list.all_name) + ' > ' self._last_work_id = self._work_id self._work_name = self._path_list[-1].name self._work_id = self._path_list[-1].id if dir_id != -1: # 如果存在上级路径 self._parent_name = self._path_list[-2].name self._parent_id = self._path_list[-2].id def login(self, username=None, password=None): """登录网盘""" if not config.cookie or self._disk.login_by_cookie( config.cookie) != LanZouCloud.SUCCESS: if username is None: username = input('输入用户名:') if password is None: password = getpass('输入密码:') code = self._disk.login(username, password) if code == LanZouCloud.NETWORK_ERROR: error("登录失败,网络连接异常") return self elif code == LanZouCloud.FAILED: error('登录失败,用户名或密码错误 :(') return self # 登录成功保存用户 cookie config.cookie = self._disk.get_cookie() self.refresh() self._is_login = True print("auth success!\n") return self def clogin(self): """使用 cookie 登录""" open_new_tab('https://pc.woozooo.com/') info("请设置 Cookie 内容:") ylogin = input("ylogin="******"phpdisk_info=") if not ylogin or not disk_info: error("请输入正确的 Cookie 信息") return None cookie = {"ylogin": str(ylogin), "phpdisk_info": disk_info} if self._disk.login_by_cookie(cookie) == LanZouCloud.SUCCESS: config.cookie = cookie self.refresh() self._is_login = True else: error("登录失败,请检查 Cookie 是否正确") def logout(self): """注销""" clear_screen() self._prompt = '> ' self._disk.logout() self._file_list.clear() self._dir_list.clear() self._path_list = FolderList() self._parent_id = -1 self._work_id = -1 self._last_work_id = -1 self._parent_name = '' self._work_name = '' self_is_login = False config.cookie = None def ls(self): """列出文件(夹)""" if self._reader_mode: # 方便屏幕阅读器阅读 for folder in self._dir_list: print(f"{folder.name}/ {folder.desc}") for file in self._file_list: print(f"{file.name} 大小:{file.size} 上传时间:{file.time}") else: # 普通用户显示方式 for folder in self._dir_list: pwd_str = '✦' if folder.has_pwd else '✧' print("#{0:<12}{1:<4}{2}{3}/".format( folder.id, pwd_str, text_align(folder.desc, 24), folder.name)) for file in self._file_list: pwd_str = '✦' if file.has_pwd else '✧' print("#{0:<12}{1:<4}{2:<14}{3:<10}{4}".format( file.id, pwd_str, file.time, file.size, file.name)) def cd(self, dir_name): """切换工作目录""" if not dir_name: info('cd .. 返回上级路径, cd - 返回上次路径, cd / 返回根目录') elif dir_name == '..': self.refresh(self._parent_id) elif dir_name == '/': self.refresh(-1) elif dir_name == '-': self.refresh(self._last_work_id) elif dir_name == '.': pass elif folder := self._dir_list.find_by_name(dir_name): self.refresh(folder.id) else:
class Commander: """蓝奏网盘命令行""" def __init__(self): self._prompt = '> ' self._disk = LanZouCloud() self._is_login = False # self._disk.ignore_limits() self._task_mgr = global_task_mgr self._dir_list = FolderList() self._file_list = FileList() self._path_list = FolderList() self._parent_id = -1 self._parent_name = '' self._work_name = '' self._work_id = -1 self._last_work_id = -1 self._reader_mode = config.reader_mode self._default_dir_pwd = config.default_dir_pwd self._disk.set_max_size(config.max_size) self._disk.set_upload_delay(config.upload_delay) @staticmethod def clear(): clear_screen() @staticmethod def help(): print_help() @staticmethod def update(): check_update() def bye(self): if self._task_mgr.has_alive_task(): info(f"有任务在后台运行, 退出请直接关闭窗口") else: exit_cmd(0) def rmode(self): """适用于屏幕阅读器用户的显示方式""" choice = input("以适宜屏幕阅读器的方式显示(y): ") if choice and choice.lower() == 'y': config.reader_mode = True self._reader_mode = True info("已启用 Reader Mode") else: config.reader_mode = False self._reader_mode = False info("已关闭 Reader Mode") @require_login def cdrec(self): """进入回收站模式""" rec = Recovery(self._disk) rec.run() self.refresh() @require_login def xghost(self): """扫描并删除幽灵文件夹""" choice = input("需要清理幽灵文件夹吗(y): ") if choice and choice.lower() == 'y': self._disk.clean_ghost_folders() info("清理已完成") else: info("清理操作已取消") @require_login def refresh(self, dir_id=None): """刷新当前文件夹和路径信息""" dir_id = self._work_id if dir_id is None else dir_id self._file_list = self._disk.get_file_list(dir_id) self._dir_list = self._disk.get_dir_list(dir_id) self._path_list = self._disk.get_full_path(dir_id) self._prompt = '/'.join(self._path_list.all_name) + ' > ' self._last_work_id = self._work_id self._work_name = self._path_list[-1].name self._work_id = self._path_list[-1].id if dir_id != -1: # 如果存在上级路径 self._parent_name = self._path_list[-2].name self._parent_id = self._path_list[-2].id def login(self): """使用 cookie 登录""" if config.cookie and self._disk.login_by_cookie( config.cookie) == LanZouCloud.SUCCESS: self._is_login = True self.refresh() return auto = input("自动读取浏览器 Cookie 登录(y): ") or "y" if auto != "y": info("请手动设置 Cookie 内容:") ylogin = input("ylogin: "******"" disk_info = input("phpdisk_info: ") or "" cookie = {"ylogin": str(ylogin), "phpdisk_info": disk_info} if not ylogin or not disk_info: error("请输入正确的 Cookie 信息") return else: cookie, browser = load_with_keys('.woozooo.com', ['ylogin', 'phpdisk_info']) if cookie: print() info(f"从 {browser} 读取用户 Cookie 成功") else: info("请在浏览器端登录账号") open_new_tab('https://pc.woozooo.com/') info("浏览器可能等待几秒才将数据写入磁盘, 请稍等") counter = 0 while not cookie: sleep(1) counter += 1 print('.', end='', flush=True) cookie, browser = load_with_keys( '.woozooo.com', ['ylogin', 'phpdisk_info']) if cookie: print() info(f"从 {browser} 读取用户 Cookie 成功") break if counter == 10: # 读取超时 ctn = input("\n暂未读取到浏览器数据, 继续扫描(y) :") or "y" if ctn == "y": counter = 0 continue else: error("自动读取 Cookie 失败") return # 登录蓝奏云 if self._disk.login_by_cookie(cookie) == LanZouCloud.SUCCESS: config.cookie = cookie self._is_login = True self.refresh() else: error("登录失败,请检查 Cookie 是否正确") @require_login def logout(self): """注销""" clear_screen() self._prompt = '> ' self._disk.logout() self._is_login = False self._file_list.clear() self._dir_list.clear() self._path_list = FolderList() self._parent_id = -1 self._work_id = -1 self._last_work_id = -1 self._parent_name = '' self._work_name = '' config.cookie = None info("本地 Cookie 已清除") @require_login def ls(self): """列出文件(夹)""" if self._reader_mode: # 方便屏幕阅读器阅读 for folder in self._dir_list: pwd_str = '有提取码' if folder.has_pwd else '' print(f"{folder.name}/ {folder.desc} {pwd_str}") for file in self._file_list: pwd_str = '有提取码' if file.has_pwd else '' print( f"{file.name} 大小:{file.size} 上传时间:{file.time} 下载次数:{file.downs} {pwd_str}" ) else: # 普通用户显示方式 for folder in self._dir_list: pwd_str = '◆' if folder.has_pwd else '◇' print("#{0:<12}{1:<2}{2}{3}/".format( folder.id, pwd_str, text_align(folder.desc, 28), folder.name)) for file in self._file_list: pwd_str = '◆' if file.has_pwd else '◇' print("#{0:<12}{1:<2}{2:<12}{3:>8}{4:>6}↓ {5}".format( file.id, pwd_str, file.time, file.size, file.downs, file.name)) @require_login def cd(self, dir_name): """切换工作目录""" if not dir_name: info('cd .. 返回上级路径, cd - 返回上次路径, cd / 返回根目录') elif dir_name == '..': self.refresh(self._parent_id) elif dir_name == '/': self.refresh(-1) elif dir_name == '-': self.refresh(self._last_work_id) elif dir_name == '.': pass elif folder := self._dir_list.find_by_name(dir_name): self.refresh(folder.id) else: