From f4dc5e9d4a5f56d0b94bf5994dd651f2ae36d099 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Thu, 2 Jan 2020 20:31:51 +0900 Subject: [PATCH] Delete unnecessary lines --- pytchat/core_async/livechat.py | 37 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index 09e3c5f..16e3367 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -161,19 +161,7 @@ class LiveChatAsync: livechat_json = (await self._get_livechat_json(continuation, session, headers) ) - contents = self._parser.get_contents(livechat_json) - '''switch live or replay''' - if self._first_fetch: - if contents is None: - self._parser.mode = 'REPLAY' - self._fetch_url = ("live_chat_replay/" - "get_live_chat_replay?continuation=") - continuation = arcparam.getparam(self.video_id) - livechat_json = (await self._get_livechat_json( - continuation, session, headers)) - contents = self._parser.get_contents(livechat_json) - self._first_fetch = False - + contents = await self._get_contents(livechat_json, session, headers) metadata, chatdata = self._parser.parse( contents ) timeout = metadata['timeoutMs']/1000 @@ -204,6 +192,29 @@ class LiveChatAsync: logger.debug(f"[{self.video_id}]チャット取得を終了しました。") self.terminate() + async def _get_contents(self, livechat_json, session, headers): + '''Get 'contents' dict from livechat json. + If contents is None at first fetching, + try to fetch archive chat data. + + Return: + ------- + 'contents' dict which includes metadata & chatdata. + ''' + contents = self._parser.get_contents(livechat_json) + if self._first_fetch: + if contents is None: + '''Try to fetch archive chat data.''' + self._parser.mode = 'REPLAY' + self._fetch_url = ("live_chat_replay/" + "get_live_chat_replay?continuation=") + continuation = arcparam.getparam(self.video_id) + livechat_json = (await self._get_livechat_json( + continuation, session, headers)) + contents = self._parser.get_contents(livechat_json) + self._first_fetch = False + return contents + async def _get_livechat_json(self, continuation, session, headers): ''' チャットデータが格納されたjsonデータを取得する。