diff --git a/api.py b/api.py index f9c75ef..355becc 100644 --- a/api.py +++ b/api.py @@ -10,7 +10,6 @@ from Struct.Lottery import Lottery import requests import time -s = requests.Session() DEBUG = False @@ -27,6 +26,7 @@ class XiGuaLiveApi: _cursor = "0" _updRoomCount = 0 lottery = None + s = requests.session() def __init__(self, name: str = "永恒de草薙"): """ @@ -153,7 +153,7 @@ class XiGuaLiveApi: :return: """ try: - p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android" + p = self.s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android" "&format=json&keyword={}".format(self.name)) d = p.json() except json.decoder.JSONDecodeError as e: @@ -186,7 +186,7 @@ class XiGuaLiveApi: :return: """ try: - p = s.post("https://i.snssdk.com/videolive/room/enter?version_code=730" + p = self.s.post("https://i.snssdk.com/videolive/room/enter?version_code=730" "&device_platform=android", data="room_id={roomID}&version_code=730" "&device_platform=android".format(roomID=self.roomID), @@ -232,7 +232,7 @@ class XiGuaLiveApi: :param userId: 用户ID :return: XiGuaLiveApi """ - p = s.get("https://live.ixigua.com/api/room?anchorId={room}".format(room=userId)) + p = requests.get("https://live.ixigua.com/api/room?anchorId={room}".format(room=userId)) if DEBUG: print(p.text) d = p.json() @@ -249,7 +249,7 @@ class XiGuaLiveApi: :return: array: 搜索结果 """ ret = [] - p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android" + p = requests.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android" "&format=json&keyword={}".format(keyword)) d = p.json() if "data" in d: @@ -266,7 +266,7 @@ class XiGuaLiveApi: if not self.isValidRoom: self.updRoomInfo() return - p = s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}" + p = self.s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}" "&version_code=730&device_platform=android".format( roomID=self.roomID, cursor=self._cursor diff --git a/liveDownloader.py b/liveDownloader.py index 1ceb8af..2965f3b 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -15,11 +15,12 @@ isDownload = False def download(): global isDownload while Common.api.isLive and not Common.forceNotDownload: + session = requests.session() if not Common.streamUrl: Common.appendError("Download with No StreamUrl Specific") break path = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.flv") - p = requests.get(Common.streamUrl, stream=True) + p = session.get(Common.streamUrl, stream=True, timeout=10) if p.status_code != 200: Common.appendDownloadStatus("Download with Response {}".format(p.status_code)) break diff --git a/templates/status.html b/templates/status.html index 25cc6cb..6991adf 100644 --- a/templates/status.html +++ b/templates/status.html @@ -21,9 +21,9 @@ 磁盘近三天 - - - + + +