Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix live_status out of sync #46

Merged
merged 1 commit into from Feb 14, 2022

Conversation

satouriko
Copy link
Contributor

@satouriko satouriko commented Feb 3, 2022

This is an attempt to #17

我发现不仅会产生空目录,而且 proc_process 会产生大量异常。这些异常不会影响录播,据我的观察,它们大量发生于一次录播结束的时候,原因是

DDRecorder/MainRunner.py

Lines 66 to 94 in 336cc83

while True:
if not self.prev_live_status and self.bl.live_status:
start = datetime.datetime.now()
self.blr = BiliLiveRecorder(self.config, start)
self.bdr = BiliDanmuRecorder(self.config, start)
record_process = Process(
target=self.blr.run)
danmu_process = Process(
target=self.bdr.run)
danmu_process.start()
record_process.start()
self.current_state.value = int(utils.state.LIVE_STARTED)
self.state_change_time.value = time.time()
self.prev_live_status = True
record_process.join()
danmu_process.join()
self.current_state.value = int(utils.state.PROCESSING_RECORDS)
self.state_change_time.value = time.time()
self.prev_live_status = False
proc_process = Process(target=self.proc, args=(
self.config, self.blr.record_dir, self.bdr.danmu_dir, self.current_state, self.state_change_time))
proc_process.start()
else:
time.sleep(self.config.get('root',{}).get('check_interval',60))

当 record_process 和 danmu_process 退出后,外面的 self.bl.live_status 还没有到更新周期,所以状态还是在播,就会又开始一次录制。它会一直不停地开始录制直到 self.bl.live_status 自轮询更新为止。

尝试修复:通过代理模式继承 bl 的实例,这样内外的状态即是同步的

待测试

@ZhaoWeicheng98
Copy link
Member

我认为一个另一方面比较根本性的解决方案是参考这里https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/live/info.md 有一个接口http://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids 可以批量查询直播状态,可以利用此接口大幅度提升查询效率,从而减少查询时间间隔。

@satouriko satouriko marked this pull request as ready for review February 14, 2022 19:36
@satouriko
Copy link
Contributor Author

经测没有问题,并且确实能够显著减少异常。但是因为 #17 提及的问题仍然会有空目录。还没有测试 1.2.0 版本,不过我大致看了一下,这个 pr 应该还是一个很好的补充。

@ZhaoWeicheng98 ZhaoWeicheng98 merged commit 8352984 into AsaChiri:main Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants