import requests from urllib import parse import json from Aria2_RPC import Aria2Download import time class AlistDownload: def __init__(self, url): self.headers = { "Accept": "application/json, text/plain, */*", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36", "Content-Type": "application/json;charset=UTF-8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9" } parseresult = parse.urlparse(url) scheme = parseresult.scheme netloc = parseresult.netloc path = parse.unquote(parseresult.path) self.host = f"{scheme}://{netloc}" self.aria2 = Aria2Download() self.get_list(path) print("遍历完成") def post(self, url, data) -> (bool, dict): req_json = {} error_number = 0 while True: status_code = 0 try: req = requests.post(url=url, data=json.dumps(data), headers=self.headers, timeout=15) status_code = req.status_code req_json = req.json() req.close() except: pass if status_code == 200: break elif error_number > 2: break else: error_number += 1 time.sleep(1) if status_code == 200: return True, req_json else: return False, req_json def get_list(self, path): url = self.host + "/api/fs/list" data = {"path": path, "password": "", "page": 1, "per_page": 0, "refresh": False} file_list = [] error_number = 0 while True: req_type, req_json = self.post(url=url, data=data) if req_type is False: return elif req_json.get("code") == 200: break elif error_number > 2: break else: print(req_json) error_number += 1 time.sleep(2) if req_json.get("data") is None: return content = req_json.get("data")["content"] if content is None: return for file_info in content: if file_info["is_dir"] is True: file_download_url = path + "/" + file_info["name"] print("dir", file_download_url) file_list.append({"is_dir": True, "path": file_download_url}) else: file_download_url = self.host + "/d" + path + "/" + file_info["name"] print("file", file_download_url) sign = file_info.get("sign") if sign is not None: file_download_url = file_download_url + "?sign=" + sign file_list.append( {"is_dir": False, "url": file_download_url, "path": path, "file": file_info["name"]}) for file in file_list: if file["is_dir"] is True: self.get_list(file["path"]) else: # D:\download 文件下载的存储地址 self.aria2.addUri(file["url"], r"D:\download" + file["path"], file["file"]) pass if __name__ == '__main__': AlistDownload( "http://此处填入Alist网盘的地址")
python教程
Alist网盘遍历文件并调用Aria2的API进行批量下载
- Alist
-
Alist网盘挂载管理工具桌面版v1.0
软件介绍Alist是一款可以支持多种网盘存储的文件列表程序,可以轻松的将各种网盘全部挂载到网页端上,以文件列表的形式呈现,而且可以自动解析网盘下载链接,无需分享网盘链接或登录就可以实现直接下载...
-
alist+RaiDrive本地硬盘挂载教程
alist+RaiDrive优势为什么我的站长站要用alist+RaiDrive的组合了?大部分网友都用的CloudDrive,网上一搜本地硬盘挂载基本也都是CloudDrive的教程,但是CloudDrive也有不少问题。1、不开源,所有用户数据全部上传到作者的云上,介意个人隐私泄漏的我就有些不...
-
Alist网盘遍历文件并调用Aria2的API进行批量下载
import requestsfrom urllib import parseimport jsonfrom Aria2_RPC import Aria2Downloadimport time class AlistDownload: def __init__(self, url): self.headers = { "Accept": "application/json, text/plain, */*",...
-
Python获取彩云天气实时天气API源码
import requests # 用户输入的秘钥和经纬度(以逗号分隔)api_key = "" # 这里输入用户自己的秘钥location = "...
-
基于Django的RustDesk Api&Web Server源码分享
项目介绍一个 python 实现的 Rustdesk API 接口,支持 WebUI 管理。基于Django的RustDes...
-
批量修改照片文件大小Python脚本
一段批量修改照片文件大小Python脚本,输入和输出图片文件夹,图片你的最大和最小标准,批量调整照片文件大小。# ...
-
文本段落自动分隔格式化Python脚本
我们在做网站时,需要处理大量的文本内容,要求文本段落内容按我们的格式分隔排版,手动一个个的修改就非常浪费时...
-
利用ffmpeg提取视频第一帧保存成图片
做影视采集站的找不到影视封面可以试试这个方法,利用ffmpeg提取视频第一帧保存成图片,这样就省去了找封面图的...