From 5840b75b241c551f1d0040fda13eef029bfa029e Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 27 Mar 2022 10:27:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E5=B9=95=E5=BD=95=E5=88=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=A4=BC=E7=89=A9=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=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 | 13 +++++++++++++ Struct/Gift.py | 7 ++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Common.py b/Common.py index 25376ef..fd10af5 100644 --- a/Common.py +++ b/Common.py @@ -315,6 +315,15 @@ class downloader(XiGuaLiveApi): __danmakuFile = None __danmakuBiasTime = None + def onPresentEnd(self, gift): + 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, gift.user.name, gift.name, gift.count) + self.__danmakuFile.write(_c.encode("UTF-8")) + def onChat(self, chat): if self.__danmakuFile is not None and self.__danmakuFile.writable(): now = datetime.now() @@ -323,6 +332,10 @@ class downloader(XiGuaLiveApi): 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")) + + def getDanmaku(self): + super(downloader, self).getDanmaku() + if self.__danmakuFile is not None and self.__danmakuFile.writable(): self.__danmakuFile.flush() @property diff --git a/Struct/Gift.py b/Struct/Gift.py index e154c99..c7bfc2f 100644 --- a/Struct/Gift.py +++ b/Struct/Gift.py @@ -47,7 +47,8 @@ class Gift: return self.giftList[self.ID]["type"] == 2 return False - def _getGiftName(self): + @property + def name(self): if self.ID in self.giftList: return self.giftList[self.ID]["name"] elif self.backupName is not None: @@ -56,13 +57,13 @@ class Gift: return "未知礼物[{}]".format(self.ID) def __str__(self): - return "{user} 送出的 {count} 个 {name}".format(user=self.user, count=self.count, name=self._getGiftName()) + return "{user} 送出的 {count} 个 {name}".format(user=self.user, count=self.count, name=self.name) def __unicode__(self): return self.__str__() def __repr__(self): - return "西瓜礼物【{}(ID:{})】".format(self._getGiftName(), self.ID) + return "西瓜礼物【{}(ID:{})】".format(self.name, self.ID) @classmethod def addGift(cls, _gift):