为android协议添加文件夹打包下载

This commit is contained in:
qing 2024-09-25 11:15:11 +08:00
parent 7d8b00a343
commit 8766e3564f
3 changed files with 66 additions and 30 deletions

View File

@ -23,7 +23,7 @@
2. 安装所需的 Python 库:
```bash
pip install requests
pip install -r requirements.txt
```
### 配置文件
@ -32,9 +32,13 @@
### 运行脚本
可以直接下载release的可执行文件运行或运行python脚本。
```
可以直接下载release的可执行文件运行或运行python脚本。
```
脚本运行:
```
脚本运行:
```
1. 克隆或下载本项目代码到本地。
@ -43,14 +47,17 @@
3. 运行脚本:
使用安卓客户端协议
```bash
python android.py
```
使用web协议
```
使用web协议
```
```bash
python 123pan.py
python web.py
```
### 命令
@ -59,12 +66,15 @@
- **列出文件**`ls`
- **刷新目录**`re`
- **下载文件**`download <文件编号>`
Android下可以直接下载文件夹
- **获取下载链接** `link <文件编号>`
- **分享文件**`share`
- **删除文件**`delete <文件编号>`
- **创建文件夹**`mkdir <文件夹名称>`
- **切换目录**`cd <目录编号>` 或 `cd ..` 返回上一级目录
- **上传文件**`upload`,然后输入文件路径
- **直接输入数字**:进入文件夹,或是下载文件
- **退出**`exit`
### 示例
@ -98,7 +108,19 @@
ok
```
下载文件夹android
```bash
>download 2
test
将打包下载文件夹输入1开始下载:1
打包下载
文件 test.zip 已存在,是否要覆盖?
输入1覆盖2取消1
test.zip 1.78K
[██████████████████████████████████████████████████] 100%
ok
```
4. 获取下载链接
@ -152,4 +174,3 @@
- 请确保在使用过程中网络连接正常。
- 由于使用了模拟安卓客户端协议,可能会有一定的风险,请谨慎使用。
- 本工具仅供学习和研究使用,请勿用于非法用途。

View File

@ -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]
down_load_url = self.link(file_number, showlink=False)
if file_detail["Type"] == 1:
print("打包下载")
file_name = file_detail["FileName"] + ".zip"
else:
file_name = file_detail["FileName"] # 文件名
if os.path.exists(file_name):
down_load_url = self.link(file_number, showlink=False)
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("输入错误")

View File

@ -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: