弹幕录制功能(兼容DanmakuFactory)
This commit is contained in:
parent
d83761afc0
commit
ce701816b9
18
Common.py
18
Common.py
@ -312,6 +312,18 @@ def loginBilibili(force=False):
|
|||||||
|
|
||||||
class downloader(XiGuaLiveApi):
|
class downloader(XiGuaLiveApi):
|
||||||
__playlist = None
|
__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
|
@property
|
||||||
def playlist(self):
|
def playlist(self):
|
||||||
@ -357,6 +369,12 @@ class downloader(XiGuaLiveApi):
|
|||||||
else:
|
else:
|
||||||
self.playlist = None
|
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"])
|
api = downloader(config["l_u"])
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ def download():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
Common.appendError("Download >{}< with Exception [{}]".format(path,e.__str__()))
|
Common.appendError("Download >{}< with Exception [{}]".format(path,e.__str__()))
|
||||||
break
|
break
|
||||||
|
Common.api.initSave(path+".xml")
|
||||||
Common.appendDownloadStatus("Download >{}< Start".format(path))
|
Common.appendDownloadStatus("Download >{}< Start".format(path))
|
||||||
f = open(path, "wb")
|
f = open(path, "wb")
|
||||||
_size = 0
|
_size = 0
|
||||||
@ -125,7 +126,7 @@ def run():
|
|||||||
if not Common.forceNotEncode:
|
if not Common.forceNotEncode:
|
||||||
awakeEncode()
|
awakeEncode()
|
||||||
try:
|
try:
|
||||||
Common.api.updRoomInfo()
|
Common.api.getDanmaku()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Common.appendError(e.__str__())
|
Common.appendError(e.__str__())
|
||||||
finally:
|
finally:
|
||||||
|
Reference in New Issue
Block a user