弹幕录制功能(兼容DanmakuFactory)

This commit is contained in:
Jerry Yan 2022-03-26 23:15:19 +08:00
parent d83761afc0
commit ce701816b9
2 changed files with 20 additions and 1 deletions

View File

@ -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 = """<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.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"])

View File

@ -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: