diff --git a/Common.py b/Common.py index 09a4781..53b074e 100644 --- a/Common.py +++ b/Common.py @@ -7,15 +7,16 @@ import psutil from api import XiGuaLiveApi import json import threading -from bypy import ByPy +from bilibili import * _config_fp = open("config.json", "r", encoding="utf8") config = json.load(_config_fp) _config_fp.close() -bypy = ByPy() doCleanTime = datetime.now() _clean_flag = None +b = Bilibili() + network = [{ "currentTime": datetime.now(), "out": { @@ -35,6 +36,11 @@ network = [{ }] +def loginBilibili(): + res = b.login(config["b_u"], config["b_p"]) + appendOperation("登陆账号,结果为:["+res+"]") + + def updateNetwork(): global network network.append({ @@ -67,12 +73,7 @@ def _doClean(_force=False): doCleanTime = datetime.now() if (datetime.now() - datetime.utcfromtimestamp(os.path.getmtime(_i))).days >= config["exp"]: _clean_flag = True - if config["dow"] == "bypy": - _res = bypy.upload(_i) - if _res == 0: - os.remove(_i) - else: - os.system(config["dow"]) + os.system(config["dow"]) else: break doCleanTime = datetime.now() @@ -146,6 +147,7 @@ downloadStatus = [] encodeStatus = [] errors = [] operations = [] +loginBilibili() def appendOperation(obj): @@ -324,3 +326,13 @@ api = downloader(config["l_u"]) def refreshDownloader(): global api api = downloader(config["l_u"]) + + +def uploadVideo(name): + b.preUpload(VideoPart(name, os.path.basename(name))) + + +def publishVideo(date): + b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"], + source=config["src"], no_reprint=0) + b.clear() \ No newline at end of file diff --git a/WebMain.py b/WebMain.py index 9f12742..d496b3e 100644 --- a/WebMain.py +++ b/WebMain.py @@ -198,6 +198,12 @@ def getUploadStats(): }}) +@app.route("/account/reLogin", methods=["GET"]) +def accountRelogin(): + Common.loginBilibili() + return jsonify({"message":"ok","code":200,"status":0,"data":{}}) + + @app.route("/files/", methods=["GET"]) def fileIndex(): a = [] diff --git a/liveDownloader.py b/liveDownloader.py index e381ed8..b27bf4c 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -3,7 +3,6 @@ import sys import time from datetime import datetime import threading -from bilibili import * import Common import os import requests @@ -93,15 +92,13 @@ def upload(): else: if isinstance(i, bool): if i is True: - b.finishUpload(Common.config["t_t"].format(date), 17, Common.config["tag"], Common.config["des"], - source=Common.config["src"], no_reprint=0) - b.clear() + Common.publishVideo(date) break if not os.path.exists(i): Common.appendError("Upload File Not Exist {}".format(i)) else: try: - b.preUpload(VideoPart(i, os.path.basename(i))) + Common.uploadVideo(i) except Exception as e: Common.appendError(e.__str__()) continue @@ -111,8 +108,6 @@ def upload(): Common.appendUploadStatus("Upload Daemon Quiting") -b = Bilibili() -b.login(Common.config["b_u"], Common.config["b_p"]) t = threading.Thread(target=download, args=()) ut = threading.Thread(target=upload, args=()) et = threading.Thread(target=encode, args=())