diff --git a/README.md b/README.md index 76c91a2..6e76549 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,26 @@ [![GitHub Stars](https://img.shields.io/github/stars/666wcy/ARPT-Bot.svg?color=inactived&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/linuxserver/docker-qbittorrent) [![Docker Pulls](https://img.shields.io/docker/pulls/benchao/arpt.svg?color=inactived&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=pulls&logo=docker)](https://hub.docker.com/repository/docker/benchao/arpt) [![GitHub Release](https://img.shields.io/docker/v/benchao/arpt?color=inactived&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=最新版本&logo=docker)](https://github.com/linuxserver/docker-qbittorrent/releases) # 更新说明 +v2.0.9 + +此版本后支持自动更新,Python文件的变动只需重启即可更新,其它硬性更新才会通过docker更新版本 + +修复aria2面板添加的任务与conf文件的配置冲突导致本地文件被删除 [#18](https://github.com/666wcy/ARPT-Bot/issues/18)[#16](https://github.com/666wcy/ARPT-Bot/issues/16) + +修复odprivate命令失效(与后续指令冲突导致失效) [#17](https://github.com/666wcy/ARPT-Bot/issues/17) + +修复默认面板账号密码为默认,存在安全隐患,修改为账号:`admin`,密码:你设置的`Aria2_secret`的值 + +
+历史记录 + v2.0.8 修复rclone剩余时间显示问题 @@ -18,8 +31,6 @@ v2.0.8 同步原作者[更新](https://github.com/gaowanliang/OneDriveShareLinkPushAria2/commit/a8dd447040ccd0aca89a3e2680a871200ca8c446),修复od分享链接文件数直到30的问题,感谢原作者 -
-历史记录 v2.0.7 diff --git a/bot/config.py b/bot/config.py index 3cafad3..185799b 100644 --- a/bot/config.py +++ b/bot/config.py @@ -4,6 +4,7 @@ from pyrogram import Client import base64 import os +import requests import json @@ -11,6 +12,59 @@ Aria2_port="8080" Aria2_secret=os.environ.get('Aria2_secret') +def change_password(): + + + login_url = "http://127.0.0.1:9184/api/login" + + login_data = {"username": "admin", "password": "admin", "recaptcha": ""} + + html = requests.post(url=login_url, json=login_data) + if html.status_code!=200: + print(f"登录失败:{html.text}") + return + + change_url = "http://127.0.0.1:9184/api/users/1" + + print(html.text) + headers = {} + headers['Cookie'] = f"auth={html.text}" + + zh_data = { + "data": { + "hideDotfiles": False, + "id": 1, + "locale": "zh-cn", + "singleClick": False + }, + "what": "user", + "which": [ + "locale", + "hideDotfiles", + "singleClick" + ] + } + + change_result = requests.put(url=change_url, json=zh_data, headers=headers) + + if change_result.status_code==403: + headers['X-Auth']=html.text + change_result = requests.put(url=change_url, json=zh_data, headers=headers) + + print(change_result.text) + + change_data = {"data": {"id": 1, "password": str(Aria2_secret)}, "what": "user", "which": ["password"]} + + change_result = requests.put(url=change_url, json=change_data, headers=headers) + + if change_result.status_code == 403: + headers['X-Auth'] = html.text + change_result = requests.put(url=change_url, json=change_data, headers=headers) + + print(change_result.text) + +change_password() + try: App_title=os.environ.get('Title') if App_title ==None: @@ -25,7 +79,7 @@ Rclone_share=False except: Rclone_share=False - + print(f"是否rclone_share:{Rclone_share}") try: @@ -65,6 +119,7 @@ ari2_ng_url=f"https://{App_title}.herokuapp.com/ng/#!/settings/rpc/set/https/{App_title}.herokuapp.com/443/jsonrpc/{base64_message}" client.send_message(chat_id=int(Telegram_user_id), text=f"Bot上线!!!\nAria2NG快捷面板:{ari2_ng_url}") + Bot_info=client.get_me() BOT_name=Bot_info.username diff --git a/bot/main.py b/bot/main.py index 9be4d19..b701fca 100644 --- a/bot/main.py +++ b/bot/main.py @@ -95,7 +95,8 @@ async def help(client, message): /nhentaisearch 搜索词 - 在nhentai中搜索本子,支持ZIP上传到网盘和发送到TG ********** 其它相关 ********** -/downtgfile - 发送TG文件并上传至网盘 +/ + - 发送TG文件并上传至网盘 发送 /downtgfile 后按提示发送文件即可 @@ -410,7 +411,10 @@ def start_bot(): more_magnet, filters=filters.text & filters.create(chexk_group) & filters.private ) - + print(f"检查odprivate_download_handler -{App_title}-") + if App_title == "": + print("添加odprivate_download_handler") + client.add_handler(odprivate_download_handler, group=1) client.add_handler(search_all_photo_handler, group=0) client.add_handler(start_download_video_handler, group=0) @@ -468,8 +472,6 @@ def start_bot(): client.add_handler(start_more_magnet_handler, group=1) - if App_title == "": - client.add_handler(odprivate_download_handler, group=1) diff --git a/bot/modules/control.py b/bot/modules/control.py index afb9640..c46a7fc 100644 --- a/bot/modules/control.py +++ b/bot/modules/control.py @@ -207,8 +207,7 @@ async def downloadFiles(client,info,password,originalPath, req, layers, start=1, filesData = json.loads(pat.group(1)) for i in filesData: if i['FSObjType'] == "1": - print("\t" * layers, "文件夹:", - i['FileLeafRef'], "\t独特ID:", i["UniqueId"], "正在进入") + _query = query.copy() _query['id'] = os.path.join( _query['id'], i['FileLeafRef']).replace("\\", "/") @@ -225,12 +224,11 @@ async def downloadFiles(client,info,password,originalPath, req, layers, start=1, else: fileCount += 1 if num == -1 or start <= fileCount + _id < start + num: - print("\t" * layers, "文件 [%d]:%s\t独特ID:%s\t正在推送" % - (fileCount + _id, i['FileLeafRef'], i["UniqueId"])) + cc = downloadURL + (i["UniqueId"][1:-1].lower()) download_path = f"/root/Download{str(query['id']).split('Documents', 1)[1]}" dd = dict(out=i["FileLeafRef"], header=headerStr, dir=download_path) - print(cc, dd) + aria2Link = "http://localhost:8080/jsonrpc" aria2Secret = os.environ.get('Aria2_secret') jsonreq = json.dumps({'jsonrpc': '2.0', 'id': 'qwer', @@ -246,9 +244,7 @@ async def downloadFiles(client,info,password,originalPath, req, layers, start=1, except Exception as e: print(f"修改信息失败:{e}") time.sleep(0.5) - else: - print("\t" * layers, "文件 [%d]:%s\t独特ID:%s\t非目标文件" % - (fileCount + _id, i['FileLeafRef'], i["UniqueId"])) + return fileCount async def odshare_download(client, message): @@ -269,264 +265,267 @@ async def odshare_download(client, message): async def login_of_share(client,info,link,admin,password): + try: - url = "http://portal.office.com/onedrive" - # browser = await launch(headless=False,options={'args': ['--no-sandbox']}) - browser = await launch(options={'args': ['--no-sandbox']}) - page = await browser.newPage() - print(admin,password) - - await page.goto(url, {'waitUntil': 'networkidle0'}) - - - await page.type("input[id='i0116']", admin) - await client.edit_message_text(text=f"已输入账号", chat_id=info.chat.id, - message_id=info.message_id, - parse_mode='markdown') - - await page.click("#idSIButton9") - await asyncio.sleep(3) - - await page.type("input[id='i0118']", password) - - print("密码输入完成,正在跳转") - + url = "http://portal.office.com/onedrive" + # browser = await launch(headless=False,options={'args': ['--no-sandbox']}) + browser = await launch(options={'args': ['--no-sandbox']}) + page = await browser.newPage() + print(admin,password) - await page.click("#idSIButton9") - await client.edit_message_text(text=f"密码输入完成,正在跳转", chat_id=info.chat.id, - message_id=info.message_id, - parse_mode='markdown') - await asyncio.sleep(3) + await page.goto(url, {'waitUntil': 'networkidle0'}) - # await page.click("input[value='登录']") - # await page.keyboard.press('Enter') - await asyncio.wait([ - page.click("#idSIButton9"), - page.waitForNavigation({'timeout': 50000}), - ]) - await client.edit_message_text(text=f"选择保持登录状态", chat_id=info.chat.id, - message_id=info.message_id, - parse_mode='markdown') - await asyncio.sleep(5) - while not await page.querySelector('.od-ItemContent-title'): - pass + await page.type("input[id='i0116']", admin) + await client.edit_message_text(text=f"已输入账号", chat_id=info.chat.id, + message_id=info.message_id, + parse_mode='markdown') - url = await page.evaluate('window.location.href', force_expr=True) - print(url) + await page.click("#idSIButton9") + await asyncio.sleep(3) - res = await page.goto(link, {'waitUntil': 'networkidle0'}) + await page.type("input[id='i0118']", password) - url = await page.evaluate('window.location.href', force_expr=True) - print(url) + print("密码输入完成,正在跳转") - print("点击完成") - print(res.request.headers) + await page.click("#idSIButton9") + await client.edit_message_text(text=f"密码输入完成,正在跳转", chat_id=info.chat.id, + message_id=info.message_id, + parse_mode='markdown') + await asyncio.sleep(3) - header = res.request.headers + # await page.click("input[value='登录']") + # await page.keyboard.press('Enter') - _cookie = await page.cookies() - pheader = "" - for __cookie in _cookie: - coo = "{}={};".format(__cookie.get("name"), __cookie.get("value")) - pheader += coo + await asyncio.wait([ + page.click("#idSIButton9"), + page.waitForNavigation({'timeout': 50000}), + ]) + await client.edit_message_text(text=f"选择保持登录状态", chat_id=info.chat.id, + message_id=info.message_id, + parse_mode='markdown') + await asyncio.sleep(5) + while not await page.querySelector('.od-ItemContent-title'): + pass - header['cookie'] = pheader - reqf = requests.get(url, headers=header) - print(reqf) - if reqf.status_code!=200: - return header,"" - await browser.close() - return header,url + url = await page.evaluate('window.location.href', force_expr=True) + print(url) -async def odpriva_downloadFiles(client,info,admin,password,originalPath, req, layers, start=1, num=-1, _id=0): - header={} - if req == None: - req = requests.session() - header, originalPath = await login_of_share(client,info,originalPath, admin=admin, password=password) - if originalPath=="": - await client.edit_message_text(text=f"登录错误", chat_id=info.chat.id, - message_id=info.message_id, - parse_mode='markdown') - return - # print(header) + res = await page.goto(link, {'waitUntil': 'networkidle0'}) - reqf = req.get(originalPath, headers=header) - if "-my" not in originalPath: - isSharepoint = True - print("sharepoint 链接") - else: - isSharepoint = False + url = await page.evaluate('window.location.href', force_expr=True) + print(url) - # f=open() - if ',"FirstRow"' not in reqf.text: - print("\t" * layers, "这个文件夹没有文件") - return 0 - filesData = [] + print("点击完成") - redirectURL = reqf.url - redirectSplitURL = redirectURL.split("/") - query = dict(urllib.parse.parse_qsl( - urllib.parse.urlsplit(redirectURL).query)) - downloadURL = "/".join(redirectSplitURL[:-1]) + "/download.aspx?UniqueId=" - if isSharepoint: - pat = re.search('templateUrl":"(.*?)"', reqf.text) + print(res.request.headers) - downloadURL = pat.group(1) - downloadURL = urllib.parse.urlparse(downloadURL) - downloadURL = "{}://{}{}".format(downloadURL.scheme, - downloadURL.netloc, downloadURL.path).split("/") - downloadURL = "/".join(downloadURL[:-1]) + \ - "/download.aspx?UniqueId=" - print(downloadURL) + header = res.request.headers - # print(reqf.headers) + _cookie = await page.cookies() + pheader = "" + for __cookie in _cookie: + coo = "{}={};".format(__cookie.get("name"), __cookie.get("value")) + pheader += coo - s2 = urllib.parse.urlparse(redirectURL) - header["referer"] = redirectURL - #header["cookie"] = reqf.headers["set-cookie"] - header["authority"] = s2.netloc + header['cookie'] = pheader + reqf = requests.get(url, headers=header) + print(reqf) + if reqf.status_code!=200: + return header,"" + await browser.close() + return header,url + except Exception as e: + print(f"login_of_share {e}") + await client.send_message(chat_id=info.chat.id, text=f"login_of_share {e}", parse_mode='markdown') - headerStr = "" - for key, value in header.items(): - # print(key+':'+str(value)) - headerStr += key + ':' + str(value) + "\n" - fileCount = 0 - # print(headerStr) +async def odpriva_downloadFiles(client,info,admin,password,originalPath, req, layers, start=1, num=-1, _id=0): + try: + header={} + if req == None: + req = requests.session() + header, originalPath = await login_of_share(client,info,originalPath, admin=admin, password=password) + if originalPath=="": + await client.edit_message_text(text=f"登录错误", chat_id=info.chat.id, + message_id=info.message_id, + parse_mode='markdown') + return + # print(header) - relativeFolder = "" - rootFolder = query["id"] - for i in rootFolder.split("/"): - if i != "Documents": - relativeFolder += i + "/" + reqf = req.get(originalPath, headers=header) + if "-my" not in originalPath: + isSharepoint = True + print("sharepoint 链接") else: - relativeFolder += i - break - relativeUrl = parse.quote(relativeFolder).replace( - "/", "%2F").replace("_", "%5F").replace("-", "%2D") - rootFolderUrl = parse.quote(rootFolder).replace( - "/", "%2F").replace("_", "%5F").replace("-", "%2D") - - graphqlVar = '{"query":"query (\n $listServerRelativeUrl: String!,$renderListDataAsStreamParameters: RenderListDataAsStreamParameters!,$renderListDataAsStreamQueryString: String!\n )\n {\n \n legacy {\n \n renderListDataAsStream(\n listServerRelativeUrl: $listServerRelativeUrl,\n parameters: $renderListDataAsStreamParameters,\n queryString: $renderListDataAsStreamQueryString\n )\n }\n \n \n perf {\n executionTime\n overheadTime\n parsingTime\n queryCount\n validationTime\n resolvers {\n name\n queryCount\n resolveTime\n waitTime\n }\n }\n }","variables":{"listServerRelativeUrl":"%s","renderListDataAsStreamParameters":{"renderOptions":5707527,"allowMultipleValueFilterForTaxonomyFields":true,"addRequiredFields":true,"folderServerRelativeUrl":"%s"},"renderListDataAsStreamQueryString":"@a1=\'%s\'&RootFolder=%s&TryNewExperienceSingle=TRUE"}}' % (relativeFolder, rootFolder, relativeUrl, rootFolderUrl) - - - # print(graphqlVar) - s2 = urllib.parse.urlparse(redirectURL) - tempHeader = copy.deepcopy(header) - tempHeader["referer"] = redirectURL - tempHeader["cookie"] = reqf.headers["set-cookie"] - tempHeader["authority"] = s2.netloc - tempHeader["content-type"] = "application/json;odata=verbose" - # print(redirectSplitURL) - - graphqlReq = req.post( - "/".join(redirectSplitURL[:-3]) + "/_api/v2.1/graphql", data=graphqlVar.encode('utf-8'), headers=tempHeader) - graphqlReq = json.loads(graphqlReq.text) - # print(graphqlReq) - if "NextHref" in graphqlReq["data"]["legacy"]["renderListDataAsStream"]["ListData"]: - nextHref = graphqlReq[ - "data"]["legacy"]["renderListDataAsStream"]["ListData"][ - "NextHref"] + "&@a1=%s&TryNewExperienceSingle=TRUE" % ( - "%27" + relativeUrl + "%27") - filesData.extend(graphqlReq[ - "data"]["legacy"]["renderListDataAsStream"]["ListData"]["Row"]) - # print(filesData) - - listViewXml = graphqlReq[ - "data"]["legacy"]["renderListDataAsStream"]["ViewMetadata"]["ListViewXml"] - renderListDataAsStreamVar = '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":1216519,"ViewXml":"%s","AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}' % ( - listViewXml).replace('"', '\\"') - # print(renderListDataAsStreamVar, nextHref,1) - - # print(listViewXml) + isSharepoint = False + + # f=open() + if ',"FirstRow"' not in reqf.text: + print("\t" * layers, "这个文件夹没有文件") + return 0 + + filesData = [] + redirectURL = reqf.url + redirectSplitURL = redirectURL.split("/") + query = dict(urllib.parse.parse_qsl( + urllib.parse.urlsplit(redirectURL).query)) + downloadURL = "/".join(redirectSplitURL[:-1]) + "/download.aspx?UniqueId=" + if isSharepoint: + pat = re.search('templateUrl":"(.*?)"', reqf.text) + + downloadURL = pat.group(1) + downloadURL = urllib.parse.urlparse(downloadURL) + downloadURL = "{}://{}{}".format(downloadURL.scheme, + downloadURL.netloc, downloadURL.path).split("/") + downloadURL = "/".join(downloadURL[:-1]) + \ + "/download.aspx?UniqueId=" + + + # print(reqf.headers) + + s2 = urllib.parse.urlparse(redirectURL) + header["referer"] = redirectURL + #header["cookie"] = reqf.headers["set-cookie"] + header["authority"] = s2.netloc + + headerStr = "" + for key, value in header.items(): + # print(key+':'+str(value)) + headerStr += key + ':' + str(value) + "\n" + relativeFolder = "" + rootFolder = query["id"] + for i in rootFolder.split("/"): + if i != "Documents": + relativeFolder += i + "/" + else: + relativeFolder += i + break + relativeUrl = parse.quote(relativeFolder).replace( + "/", "%2F").replace("_", "%5F").replace("-", "%2D") + rootFolderUrl = parse.quote(rootFolder).replace( + "/", "%2F").replace("_", "%5F").replace("-", "%2D") + + graphqlVar = '{"query":"query (\n $listServerRelativeUrl: String!,$renderListDataAsStreamParameters: RenderListDataAsStreamParameters!,$renderListDataAsStreamQueryString: String!\n )\n {\n \n legacy {\n \n renderListDataAsStream(\n listServerRelativeUrl: $listServerRelativeUrl,\n parameters: $renderListDataAsStreamParameters,\n queryString: $renderListDataAsStreamQueryString\n )\n }\n \n \n perf {\n executionTime\n overheadTime\n parsingTime\n queryCount\n validationTime\n resolvers {\n name\n queryCount\n resolveTime\n waitTime\n }\n }\n }","variables":{"listServerRelativeUrl":"%s","renderListDataAsStreamParameters":{"renderOptions":5707527,"allowMultipleValueFilterForTaxonomyFields":true,"addRequiredFields":true,"folderServerRelativeUrl":"%s"},"renderListDataAsStreamQueryString":"@a1=\'%s\'&RootFolder=%s&TryNewExperienceSingle=TRUE"}}' % ( + relativeFolder, rootFolder, relativeUrl, rootFolderUrl) + + # print(graphqlVar) + s2 = urllib.parse.urlparse(redirectURL) + tempHeader = copy.deepcopy(header) + tempHeader["referer"] = redirectURL + #tempHeader["cookie"] = reqf.headers["set-cookie"] + tempHeader["authority"] = s2.netloc + tempHeader["content-type"] = "application/json;odata=verbose" + # print(redirectSplitURL) graphqlReq = req.post( - "/".join( - redirectSplitURL[:-3]) + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream" + nextHref, - data=renderListDataAsStreamVar.encode('utf-8'), headers=tempHeader) + "/".join(redirectSplitURL[:-3]) + "/_api/v2.1/graphql", data=graphqlVar.encode('utf-8'), headers=tempHeader) graphqlReq = json.loads(graphqlReq.text) # print(graphqlReq) + if "NextHref" in graphqlReq["data"]["legacy"]["renderListDataAsStream"]["ListData"]: + nextHref = graphqlReq[ + "data"]["legacy"]["renderListDataAsStream"]["ListData"][ + "NextHref"] + "&@a1=%s&TryNewExperienceSingle=TRUE" % ( + "%27" + relativeUrl + "%27") + filesData.extend(graphqlReq[ + "data"]["legacy"]["renderListDataAsStream"]["ListData"]["Row"]) + # print(filesData) + + listViewXml = graphqlReq[ + "data"]["legacy"]["renderListDataAsStream"]["ViewMetadata"]["ListViewXml"] + renderListDataAsStreamVar = '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":1216519,"ViewXml":"%s","AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}' % ( + listViewXml).replace('"', '\\"') + # print(renderListDataAsStreamVar, nextHref,1) + + # print(listViewXml) - while "NextHref" in graphqlReq["ListData"]: - nextHref = graphqlReq["ListData"]["NextHref"] + "&@a1=%s&TryNewExperienceSingle=TRUE" % ( - "%27" + relativeUrl + "%27") - filesData.extend(graphqlReq["ListData"]["Row"]) graphqlReq = req.post( - "/".join(redirectSplitURL[ - :-3]) + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream" + nextHref, + "/".join( + redirectSplitURL[:-3]) + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream" + nextHref, data=renderListDataAsStreamVar.encode('utf-8'), headers=tempHeader) - # print(graphqlReq.text) graphqlReq = json.loads(graphqlReq.text) # print(graphqlReq) - filesData.extend(graphqlReq["ListData"]["Row"]) - else: - filesData = filesData.extend(graphqlReq[ - "data"]["legacy"]["renderListDataAsStream"]["ListData"]["Row"]) - - if filesData==None: - pat = re.search( - 'g_listData = {"wpq":"","Templates":{},"ListData":{ "Row" : ([\s\S]*?),"FirstRow"', reqf.text) - filesData = json.loads(pat.group(1)) - for i in filesData: - if i['FSObjType'] == "1": - print("\t" * layers, "文件夹:", - i['FileLeafRef'], "\t独特ID:", i["UniqueId"], "正在进入") - _query = query.copy() - _query['id'] = os.path.join( - _query['id'], i['FileLeafRef']).replace("\\", "/") - if not isSharepoint: - originalPath = "/".join(redirectSplitURL[:-1]) + \ - "/onedrive.aspx?" + urllib.parse.urlencode(_query) - else: - originalPath = "/".join(redirectSplitURL[:-1]) + \ - "/AllItems.aspx?" + urllib.parse.urlencode(_query) - - fileCount += await odpriva_downloadFiles(client, info,admin,password, originalPath, req, layers + 1, _id=fileCount, start=start, - num=num) + while "NextHref" in graphqlReq["ListData"]: + nextHref = graphqlReq["ListData"]["NextHref"] + "&@a1=%s&TryNewExperienceSingle=TRUE" % ( + "%27" + relativeUrl + "%27") + filesData.extend(graphqlReq["ListData"]["Row"]) + graphqlReq = req.post( + "/".join(redirectSplitURL[ + :-3]) + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream" + nextHref, + data=renderListDataAsStreamVar.encode('utf-8'), headers=tempHeader) + # print(graphqlReq.text) + graphqlReq = json.loads(graphqlReq.text) + # print(graphqlReq) + filesData.extend(graphqlReq["ListData"]["Row"]) else: - fileCount += 1 - if num == -1 or start <= fileCount + _id < start + num: - print("\t" * layers, "文件 [%d]:%s\t独特ID:%s\t正在推送" % - (fileCount + _id, i['FileLeafRef'], i["UniqueId"])) - cc = downloadURL + (i["UniqueId"][1:-1].lower()) - download_path = f"/root/Download{str(query['id']).split('Documents', 1)[1]}" - dd = dict(out=i["FileLeafRef"], header=headerStr, dir=download_path) - print(cc, dd) - aria2Link = "http://localhost:8080/jsonrpc" - aria2Secret = os.environ.get('Aria2_secret') - jsonreq = json.dumps({'jsonrpc': '2.0', 'id': 'qwer', - 'method': 'aria2.addUri', - "params": ["token:" + aria2Secret, [cc], dd]}) - - c = requests.post(aria2Link, data=jsonreq) + filesData = filesData.extend(graphqlReq[ + "data"]["legacy"]["renderListDataAsStream"]["ListData"]["Row"]) + + fileCount = 0 + # print(headerStr) + if filesData == None: + pat = re.search( + 'g_listData = {"wpq":"","Templates":{},"ListData":{ "Row" : ([\s\S]*?),"FirstRow"', reqf.text) + filesData = json.loads(pat.group(1)) + for i in filesData: + if i['FSObjType'] == "1": + + _query = query.copy() + _query['id'] = os.path.join( + _query['id'], i['FileLeafRef']).replace("\\", "/") + if not isSharepoint: + originalPath = "/".join(redirectSplitURL[:-1]) + \ + "/onedrive.aspx?" + urllib.parse.urlencode(_query) + else: + originalPath = "/".join(redirectSplitURL[:-1]) + \ + "/AllItems.aspx?" + urllib.parse.urlencode(_query) - text = f"推送下载:`{i['FileLeafRef']}`\n下载路径:`{download_path}`\n推送结果:`{c.text}`" - try: - await client.edit_message_text(text=text, chat_id=info.chat.id, message_id=info.message_id, - parse_mode='markdown') - except Exception as e: - print(f"修改信息失败:{e}") - time.sleep(0.5) + fileCount += await odpriva_downloadFiles(client, info,admin,password, originalPath, req, layers + 1, _id=fileCount, start=start, + num=num) else: - print("\t" * layers, "文件 [%d]:%s\t独特ID:%s\t非目标文件" % - (fileCount + _id, i['FileLeafRef'], i["UniqueId"])) - return fileCount + fileCount += 1 + if num == -1 or start <= fileCount + _id < start + num: + print("\t" * layers, "文件 [%d]:%s\t独特ID:%s\t正在推送" % + (fileCount + _id, i['FileLeafRef'], i["UniqueId"])) + cc = downloadURL + (i["UniqueId"][1:-1].lower()) + download_path = f"/root/Download{str(query['id']).split('Documents', 1)[1]}" + dd = dict(out=i["FileLeafRef"], header=headerStr, dir=download_path) + print(cc, dd) + aria2Link = "http://localhost:8080/jsonrpc" + aria2Secret = os.environ.get('Aria2_secret') + jsonreq = json.dumps({'jsonrpc': '2.0', 'id': 'qwer', + 'method': 'aria2.addUri', + "params": ["token:" + aria2Secret, [cc], dd]}) + + c = requests.post(aria2Link, data=jsonreq) + + text = f"推送下载:`{i['FileLeafRef']}`\n下载路径:`{download_path}`\n推送结果:`{c.text}`" + try: + await client.edit_message_text(text=text, chat_id=info.chat.id, message_id=info.message_id, + parse_mode='markdown') + except Exception as e: + print(f"修改信息失败:{e}") + time.sleep(0.5) + + return fileCount + except Exception as e: + print(f"odpriva_downloadFiles {e}") + await client.send_message(chat_id=info.chat.id, text=f"odpriva_downloadFiles {e}", parse_mode='markdown') async def odprivate_download(client, message): try: try: - login_info=str(message.text).split(" ") - print(login_info) + print(f"odprivate_download{login_info}") admin=login_info[1] password=login_info[2] odprivate_url=login_info[3] - except: + except Exception as e: + print(e) text="身份信息获取失败\n" \ "使用方法为:/odprivate 邮箱 密码 链接" await client.send_message(chat_id=message.chat.id, text=text, parse_mode='markdown') @@ -538,6 +537,17 @@ async def odprivate_download(client, message): print(f"odprivate error {e}") await client.send_message(chat_id=message.chat.id, text=f"odprivate error {e}", parse_mode='markdown') +def run_shell(gid,file_num,file_dir): + shell = f"bash upload.sh \"{gid}\" \"{file_num}\" '{file_dir}' " + + print(shell) + cmd = subprocess.Popen(shell, stdin=subprocess.PIPE, stderr=sys.stderr, close_fds=True, + stdout=subprocess.PIPE, universal_newlines=True, shell=True, bufsize=1) + while True: + time.sleep(2) + if subprocess.Popen.poll(cmd) == 0: # 判断子进程是否结束 + print("上传结束") + return def check_upload(api, gid): @@ -570,16 +580,11 @@ def check_upload(api, gid): print(f"上传该任务:{file_dir}") sys.stdout.flush() - shell=f"bash upload.sh \"{gid}\" \"{file_num}\" '{file_dir}' " - print(shell) - cmd = subprocess.Popen(shell, stdin=subprocess.PIPE, stderr=sys.stderr, close_fds=True, - stdout=subprocess.PIPE, universal_newlines=True, shell=True, bufsize=1) - while True: - time.sleep(2) - if subprocess.Popen.poll(cmd) == 0: # 判断子进程是否结束 - print("上传结束") - return + + t1 = threading.Thread(target=run_shell, args=(gid,file_num,file_dir)) + t1.start() + async def run_await_rclone(dir,title,info,file_num,client, message,gid): global task diff --git a/config/aria2.conf b/config/aria2.conf index 1728ca8..d9255f9 100644 --- a/config/aria2.conf +++ b/config/aria2.conf @@ -279,7 +279,7 @@ peer-id-prefix=-qB4250- # 下载停止后执行的命令 # 从 正在下载 到 删除、错误、完成 时触发。暂停被标记为未开始下载,故与此项无关。 -on-download-stop=/root/.aria2/delete.sh +#on-download-stop=/root/.aria2/delete.sh # 下载完成后执行的命令 # 此项未定义则执行 下载停止后执行的命令 (on-download-stop) diff --git a/start.sh b/start.sh index 9b373cd..9ec7d05 100644 --- a/start.sh +++ b/start.sh @@ -17,6 +17,11 @@ wget git.io/tracker.sh chmod 0777 /tracker.sh /bin/bash tracker.sh "/root/.aria2/aria2.conf" +rm -rf /bot +git clone https://github.com/666wcy/ARPT-Bot.git +mkdir /bot/ +mv /ARPT-Bot/bot/* /bot/ + #python3 /bot/nginx.py nginx -c /etc/nginx/nginx.conf nginx -s reload