diff --git a/Common.py b/Common.py index 953a411..5f7790c 100644 --- a/Common.py +++ b/Common.py @@ -114,7 +114,7 @@ def appendError(obj): class downloader(XiGuaLiveApi): files = [] - playlist: str = None + playlist = None def updRoomInfo(self): global broadcaster, isBroadcasting, updateTime diff --git a/Struct/Chat.py b/Struct/Chat.py index 729ee78..31269c6 100644 --- a/Struct/Chat.py +++ b/Struct/Chat.py @@ -4,9 +4,9 @@ from .Lottery import Lottery class Chat: - content: str ="" - user: User=None - filterString:list = ["",] + content ="" + user=None + filterString = ["",] isFiltered = False def __init__(self, json=None, lottery:Lottery = None): diff --git a/Struct/Gift.py b/Struct/Gift.py index c856b28..64d11bb 100644 --- a/Struct/Gift.py +++ b/Struct/Gift.py @@ -3,12 +3,12 @@ from .User import User class Gift: - ID:int = 0 - count:int = 0 - roomID:int = 0 - giftList:dict = {} - amount:int = 0 - user:User = None + ID = 0 + count = 0 + roomID = 0 + giftList = {} + amount = 0 + user = None def __init__(self, json=None): if json: diff --git a/Struct/Lottery.py b/Struct/Lottery.py index d2b5ae1..e2d9eb8 100644 --- a/Struct/Lottery.py +++ b/Struct/Lottery.py @@ -5,14 +5,14 @@ from .LuckyUser import LuckyUser class Lottery: - ID: int = 0 + ID = 0 isActive = False content = "" isFinished = False luckyUsers = [] joinedUserCount = 0 prizeName = "" - finish:int = 0 + finish = 0 def __init__(self, json=None): if json: diff --git a/Struct/MemberMsg.py b/Struct/MemberMsg.py index 404a522..2dcdeea 100644 --- a/Struct/MemberMsg.py +++ b/Struct/MemberMsg.py @@ -2,9 +2,9 @@ from .User import User class MemberMsg: - type:int = 0 - content:str = "" - user:User = None + type = 0 + content = "" + user = None def __init__(self, json=None): if json: diff --git a/Struct/User.py b/Struct/User.py index f2253f3..628a234 100644 --- a/Struct/User.py +++ b/Struct/User.py @@ -1,11 +1,11 @@ class User: - ID: int = 0 - name: str = "" - brand: str = "" - level: int = 0 - type: int = 0 - block: bool = False - mute: bool = False + ID = 0 + name = "" + brand = "" + level = 0 + type = 0 + block = False + mute = False def __init__(self, json=None): if json: @@ -47,8 +47,7 @@ class User: else: if self.type != 0: return "[{}{}]{}".format(self.brand, self.level, self.name) - return "<{}{}>{}".format(self.brand,self.level,self.name) + return "<{}{}>{}".format(self.brand, self.level, self.name) def __unicode__(self): return self.__str__() - diff --git a/WebMain.py b/WebMain.py index 15db91c..bd2e5da 100644 --- a/WebMain.py +++ b/WebMain.py @@ -1,3 +1,5 @@ +from time import sleep + from flask import Flask, jsonify, request import Common import threading @@ -39,6 +41,18 @@ def getAllStats(): }}) +@app.route("/stats/broadcast", methods=["GET"]) +def geBroadcastStats(): + return jsonify({"message":"ok","code":200,"status":0,"data":{ + "broadcast": { + "broadcaster": Common.broadcaster.__str__(), + "isBroadcasting": Common.isBroadcasting, + "streamUrl": Common.streamUrl, + "updateTime": Common.updateTime + } + }}) + + @app.route("/stats/download", methods=["GET"]) def geDownloadStats(): return jsonify({"message":"ok","code":200,"status":0,"data":{ @@ -62,7 +76,11 @@ def getUploadStats(): t = threading.Thread(target=RUN, args=(Common.config['l_u'],)) t.setDaemon(True) - -if __name__ == "__main__": - t.start() - app.run() +t.start() +while True: + if t.is_alive(): + sleep(240) + else: + t = threading.Thread(target=RUN, args=(Common.config['l_u'],)) + t.setDaemon(True) + t.start() diff --git a/api.py b/api.py index fd272bb..b905e68 100644 --- a/api.py +++ b/api.py @@ -12,21 +12,21 @@ import time s = requests.Session() -DEBUG: bool = False +DEBUG = False class XiGuaLiveApi: - isLive: bool = False - isValidRoom: bool = False + isLive = False + isValidRoom = False _rawRoomInfo = {} - name: str = "" - roomID: int = 0 - roomTitle: str = "" - roomLiver: User = None - roomPopularity: int = 0 - _cursor:str = "0" - _updRoomCount:int = 0 - lottery:Lottery = None + name = "" + roomID = 0 + roomTitle = "" + roomLiver = None + roomPopularity = 0 + _cursor = "0" + _updRoomCount = 0 + lottery = None def __init__(self, name: str = "永恒de草薙"): self.name = name