菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

Aria2批量下载API接口源码解析

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:python教程 API源码 API接口 Aria2 批量下载

Aria2批量下载API接口源码是一个基于Python的开源项目,它实现了通过API接口控制Aria2进行批量下载的功能。用户可以通过调用这些API接口,实现对Aria2的远程控制,从而实现批量下载文件、断点续传等功能。这个项目的源码结构清晰,易于理解和修改。同时,它还支持多种操作系统,如Windows、Linux和Mac OS等。此外,该项目还提供了详细的文档和示例代码,方便用户快速上手和使用。总之,Aria2批量下载API接口源码是一个非常实用的工具,可以帮助用户高效地进行文件下载和管理。

importrequestsimportjsonclassAria2Download:def__init__(self):self.api="http://localhost:6800/jsonrpc"#消息id,aria2会原样返回这个id,可以自动生成也可以用其他唯一标识self.id="QXJpYU5nXzE2NzUxMzUwMDFfMC42Mzc0MDA5MTc2NjAzNDM="defaddUri(self,url,path,file=None,proxy=None):"""添加任务:paramurl:文件下载地址:parampath:文件保存路径:paramfile:文件保存名称:paramproxy:代{过}{滤}理地址:return:"""data={"id":self.id,"jsonrpc":"2.0","method":"aria2.addUri","params":[[url],{"dir":path,"out":file,"all-proxy":proxy}]}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()#print("addUri",return_json)returnreturn_jsondefgetGlobalStat(self):"""获取全部下载信息:return:"""data={"jsonrpc":"2.0","method":"aria2.getGlobalStat","id":self.id}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()#print("getGlobalStat",return_json)returnreturn_jsondeftellActive(self):"""正在下载:return:"""data={"jsonrpc":"2.0","method":"aria2.tellActive","id":self.id,"params":[["gid","totalLength","completedLength","uploadSpeed","downloadSpeed","connections","numSeeders","seeder","status","errorCode","verifiedLength","verifyIntegrityPending","files","bittorrent","infoHash"]]}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()#print("getGlobalStat",return_json)returnreturn_jsondeftellWaiting(self):"""正在等待:return:"""data={"jsonrpc":"2.0","method":"aria2.tellWaiting","id":self.id,"params":[0,1000,["gid","totalLength","completedLength","uploadSpeed","downloadSpeed","connections","numSeeders","seeder","status","errorCode","verifiedLength","verifyIntegrityPending"]]}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()print("tellWaiting",return_json)returnreturn_jsondeftellStopped(self):"""已完成/已停止:return:"""data={"jsonrpc":"2.0","method":"aria2.tellStopped","id":self.id,"params":[-1,1000,["gid","totalLength","completedLength","uploadSpeed","downloadSpeed","connections","numSeeders","seeder","status","errorCode","verifiedLength","verifyIntegrityPending"]]}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()#print("tellStopped",return_json)returnreturn_jsondeftellStatus(self,gid):"""任务状态:paramgid:任务ID:return:"""data={"jsonrpc":"2.0","method":"aria2.tellStatus","id":self.id,"params":[gid]}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()#print("tellWaiting",return_json)returnreturn_jsondefremoveDownloadResult(self,gid):"""删除下载结束的任务:paramgid:任务ID:return:"""data={"jsonrpc":"2.0","method":"aria2.removeDownloadResult","id":self.id,"params":[gid]}req=requests.post(url=self.api,data=json.dumps(data))return_json=req.json()req.close()#print("removeDownloadResult",return_json)returnreturn_json


评论
建站知识
建站知识
使用技巧
调试安装
运营推广