Skip to content

Commit cdafd1d

Browse files
committed
chat: wrap validate in try/catch and close session when over
1 parent b05de76 commit cdafd1d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

internals/chat/client.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ async def create(self):
190190
self.logger.info("Loaded %d cookies", len(cookie_jar))
191191

192192
async def close(self):
193-
await self.session.close()
193+
if self.session and not self.session.closed:
194+
await self.session.close()
194195

195196
async def _session_get(self, url: str, **kwargs):
196197
async with self.session.get(url, **kwargs) as resp:
@@ -639,7 +640,23 @@ async def start(self, writer: JSONWriter, start_at: Optional[int] = None):
639640
if chat_info is None:
640641
self.logger.debug("Unable to get the initial data.")
641642
return
642-
await self._validate_result(chat_info)
643+
try:
644+
await self._validate_result(chat_info)
645+
except VideoUnplayable as exc:
646+
self.logger.error(f"Video unplayable: {exc}")
647+
return
648+
except LoginRequired:
649+
self.logger.error("You need to be logged in to access this chat/video!")
650+
return
651+
except VideoUnavailable as exc:
652+
self.logger.error(f"Video unavailable: {exc}")
653+
return
654+
except ChatDisabled as exc:
655+
self.logger.error(f"Chat disabled: {exc}")
656+
return
657+
except NoChatReplay as exc:
658+
self.logger.error(f"No chat replay available: {exc}")
659+
return
643660

644661
retry_count = 0
645662
max_retries = 5

internals/chat/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ async def main_loop(**context: Dict[str, Any]):
9494
logger.info("Chat downloader for %s was cancelled, flushing...", video.id)
9595
is_async_cancel = True
9696
ChatManager._actives.pop(video.id, None)
97+
await chat_downloader.close()
9798
await jwriter.close()
9899
if not is_async_cancel:
99100
logger.info("Chat downloader for %s finished, sending upload signal", video.id)

0 commit comments

Comments
 (0)