From ce701816b9df7d26a280aecd8cec7b5a8c9911e1 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 26 Mar 2022 23:15:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E5=B9=95=E5=BD=95=E5=88=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=88=E5=85=BC=E5=AE=B9DanmakuFactory=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common.py | 18 ++++++++++++++++++ liveDownloader.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Common.py b/Common.py index d24b106..25376ef 100644 --- a/Common.py +++ b/Common.py @@ -312,6 +312,18 @@ def loginBilibili(force=False): class downloader(XiGuaLiveApi): __playlist = None + __danmakuFile = None + __danmakuBiasTime = None + + def onChat(self, chat): + if self.__danmakuFile is not None and self.__danmakuFile.writable(): + now = datetime.now() + if self.__danmakuBiasTime is None: + return + ts = (now - self.__danmakuBiasTime).total_seconds() + _c = """{}""".format(ts, now.timestamp()*1000, chat.user.ID, chat.user.name, chat.content) + self.__danmakuFile.write(_c.encode("UTF-8")) + self.__danmakuFile.flush() @property def playlist(self): @@ -357,6 +369,12 @@ class downloader(XiGuaLiveApi): else: self.playlist = None + def initSave(self, f): + if self.__danmakuFile is not None and not self.__danmakuFile.closed: + self.__danmakuFile.close() + self.__danmakuBiasTime = datetime.now() + self.__danmakuFile = open(f, "wb") + api = downloader(config["l_u"]) diff --git a/liveDownloader.py b/liveDownloader.py index 18734dc..b8ae667 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -20,6 +20,7 @@ def download(): except Exception as e: Common.appendError("Download >{}< with Exception [{}]".format(path,e.__str__())) break + Common.api.initSave(path+".xml") Common.appendDownloadStatus("Download >{}< Start".format(path)) f = open(path, "wb") _size = 0 @@ -125,7 +126,7 @@ def run(): if not Common.forceNotEncode: awakeEncode() try: - Common.api.updRoomInfo() + Common.api.getDanmaku() except Exception as e: Common.appendError(e.__str__()) finally: