diff --git a/README.md b/README.md index 29540f0..e39e25c 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ 1. 确保已安装 Python 3.x。 2. 安装所需的 Python 库: - + ```bash - pip install requests + pip install -r requirements.txt ``` ### 配置文件 @@ -32,26 +32,33 @@ ### 运行脚本 -​ 可以直接下载release的可执行文件运行或运行python脚本。 +``` +可以直接下载release的可执行文件运行或运行python脚本。 +``` -​ 脚本运行: +``` +脚本运行: +``` 1. 克隆或下载本项目代码到本地。 2. 打开终端或命令提示符,进入项目目录。 3. 运行脚本: - + 使用安卓客户端协议 + ```bash python android.py ``` -​ 使用web协议 +``` +使用web协议 +``` - ```bash - python 123pan.py - ``` +```bash + python web.py +``` ### 命令 @@ -59,36 +66,39 @@ - **列出文件**:`ls` - **刷新目录**:`re` - **下载文件**:`download <文件编号>` + + Android下可以直接下载文件夹 - **获取下载链接** `link <文件编号>` - **分享文件**:`share` - **删除文件**:`delete <文件编号>` - **创建文件夹**:`mkdir <文件夹名称>` - **切换目录**:`cd <目录编号>` 或 `cd ..` 返回上一级目录 - **上传文件**:`upload`,然后输入文件路径 +- **直接输入数字**:进入文件夹,或是下载文件 - **退出**:`exit` ### 示例 1. 登录: - + ```bash > log ``` 2. 列出文件: - + ```bash > ls↵ ``` 3. 下载文件: - + ```bash > download 1↵ ``` - + 或直接输入文件编号: - + ```bash >54↵ 1.20.0.01_v8a.apk 193.53M @@ -97,20 +107,32 @@ [██████████████████████████████████████████████████] 100% ok ``` - + 下载文件夹(android): + + ```bash + >download 2 + test + 将打包下载文件夹,输入1开始下载:1 + 打包下载 + 文件 test.zip 已存在,是否要覆盖? + 输入1覆盖,2取消:1 + test.zip 1.78K + [██████████████████████████████████████████████████] 100% + ok + ``` 4. 获取下载链接 - + ```bash >link 32 https://1-180-24-9.pd1.cjjd19.com:30443/(A Long Link) ``` - + 获取下载链接后可以使用IDM下载 5. 分享文件: - + ```bash >share↵ 分享文件的编号:58↵ @@ -123,19 +145,19 @@ ``` 6. 删除文件: - + ```bash > delete 1 ``` 7. 创建文件夹: - + ```bash > mkdir 新建文件夹 ``` 8. 上传文件: - + ```bash >upload 请输入文件路径:C:\(some path)\config @@ -152,4 +174,3 @@ - 请确保在使用过程中网络连接正常。 - 由于使用了模拟安卓客户端协议,可能会有一定的风险,请谨慎使用。 - 本工具仅供学习和研究使用,请勿用于非法用途。 - diff --git a/android.py b/android.py index 96b136b..5b28b17 100644 --- a/android.py +++ b/android.py @@ -212,7 +212,7 @@ class Pan123: down_request_url, headers=self.header_logined, # params={sign[0]: sign[1]}, - data=down_request_data, + data=json.dumps(down_request_data), timeout=10 ) # print(linkRes.text) @@ -230,15 +230,24 @@ class Pan123: return redirect_url - def download(self, file_number): + def download(self, file_number,download_path="download/"): file_detail = self.list[file_number] + if file_detail["Type"] == 1: + print("打包下载") + file_name = file_detail["FileName"] + ".zip" + else: + file_name = file_detail["FileName"] # 文件名 down_load_url = self.link(file_number, showlink=False) - file_name = file_detail["FileName"] # 文件名 - if os.path.exists(file_name): + + if os.path.exists(download_path+file_name): print("文件 " + file_name + " 已存在,是否要覆盖?") sure_download = input("输入1覆盖,2取消:") if sure_download != "1": return + + if not os.path.exists(download_path): + print("文件夹不存在,创建文件夹") + os.makedirs(download_path) down = requests.get(down_load_url, stream=True, timeout=10) file_size = int(down.headers["Content-Length"]) # 文件大小 @@ -252,7 +261,7 @@ class Pan123: time1 = time.time() time_temp = time1 data_count_temp = 0 - with open(file_name, "wb") as f: + with open(download_path+file_name, "wb") as f: for i in down.iter_content(1024): f.write(i) done_block = int((data_count / content_size) * 50) @@ -731,7 +740,7 @@ if __name__ == "__main__": # print(pan.list[int(command) - 1]) name = pan.list[int(command) - 1]["FileName"] print(name + " " + size_print_show) - print("press 1 to download now: ", end="") + print("输入1开始下载: ", end="") sure = input() if sure == "1": pan.download(int(command) - 1) @@ -740,6 +749,12 @@ if __name__ == "__main__": if int(command[9:]) > len(pan.list) or int(command[9:]) < 1: print("输入错误") continue + if pan.list[int(command[9:]) - 1]["Type"] == 1: + print(pan.list[int(command[9:]) - 1]["FileName"]) + print("将打包下载文件夹,输入1开始下载:", end="") + sure = input() + if sure != "1": + continue pan.download(int(command[9:]) - 1) else: print("输入错误") diff --git a/123pan.py b/web.py similarity index 99% rename from 123pan.py rename to web.py index 1a23803..d8cfd4f 100644 --- a/123pan.py +++ b/web.py @@ -655,8 +655,8 @@ class Pan123: pass_word = text["passWord"] authorization = text["authorization"] - except FileNotFoundError or json.decoder.JSONDecodeError: - print("read failed") + except: + print("获取配置失败,重新登录") if user_name == "" or pass_word == "": if input_pwd: