From 95565c33ec06a200baabab2a5bc7e84f01fe4159 Mon Sep 17 00:00:00 2001 From: JerryYan <792602257@qq.com> Date: Wed, 17 Jul 2019 09:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=8A=B6=E6=80=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87=EF=BC=8C=E6=9B=B4=E6=94=B9liveDownloader=E7=9A=84?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B1=A0=EF=BC=8Capi=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 12 ++++++------ liveDownloader.py | 3 ++- templates/status.html | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) 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 @@