弹幕录制添加礼物记录功能(兼容DanmakuFactory)
This commit is contained in:
parent
ce701816b9
commit
5840b75b24
13
Common.py
13
Common.py
@ -315,6 +315,15 @@ class downloader(XiGuaLiveApi):
|
|||||||
__danmakuFile = None
|
__danmakuFile = None
|
||||||
__danmakuBiasTime = 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 = """<gift ts="{:.2f}" user="{}" giftname="{}" giftcount="{}"></gift>""".format(ts, gift.user.name, gift.name, gift.count)
|
||||||
|
self.__danmakuFile.write(_c.encode("UTF-8"))
|
||||||
|
|
||||||
def onChat(self, chat):
|
def onChat(self, chat):
|
||||||
if self.__danmakuFile is not None and self.__danmakuFile.writable():
|
if self.__danmakuFile is not None and self.__danmakuFile.writable():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@ -323,6 +332,10 @@ class downloader(XiGuaLiveApi):
|
|||||||
ts = (now - self.__danmakuBiasTime).total_seconds()
|
ts = (now - self.__danmakuBiasTime).total_seconds()
|
||||||
_c = """<d p="{:.2f},1,24,16777215,{:.0f},0,{},0" user="{}">{}</d>""".format(ts, now.timestamp()*1000, chat.user.ID, chat.user.name, chat.content)
|
_c = """<d p="{:.2f},1,24,16777215,{:.0f},0,{},0" user="{}">{}</d>""".format(ts, now.timestamp()*1000, chat.user.ID, chat.user.name, chat.content)
|
||||||
self.__danmakuFile.write(_c.encode("UTF-8"))
|
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()
|
self.__danmakuFile.flush()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -47,7 +47,8 @@ class Gift:
|
|||||||
return self.giftList[self.ID]["type"] == 2
|
return self.giftList[self.ID]["type"] == 2
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _getGiftName(self):
|
@property
|
||||||
|
def name(self):
|
||||||
if self.ID in self.giftList:
|
if self.ID in self.giftList:
|
||||||
return self.giftList[self.ID]["name"]
|
return self.giftList[self.ID]["name"]
|
||||||
elif self.backupName is not None:
|
elif self.backupName is not None:
|
||||||
@ -56,13 +57,13 @@ class Gift:
|
|||||||
return "未知礼物[{}]".format(self.ID)
|
return "未知礼物[{}]".format(self.ID)
|
||||||
|
|
||||||
def __str__(self):
|
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):
|
def __unicode__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "西瓜礼物【{}(ID:{})】".format(self._getGiftName(), self.ID)
|
return "西瓜礼物【{}(ID:{})】".format(self.name, self.ID)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def addGift(cls, _gift):
|
def addGift(cls, _gift):
|
||||||
|
Reference in New Issue
Block a user