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: