diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index d22145f..a5e439c 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -233,6 +233,11 @@ class LiveChatAsync: self.video_id, self.seektime, self._topchat_only) livechat_json = (await self._get_livechat_json( continuation, session, headers)) + reload_continuation = self._parser.reload_continuation( + self._parser.get_contents(livechat_json)) + if reload_continuation: + livechat_json = (await self._get_livechat_json( + reload_continuation, session, headers)) contents = self._parser.get_contents(livechat_json) self._first_fetch = False return contents diff --git a/pytchat/parser/live.py b/pytchat/parser/live.py index 7429e50..a37bbaa 100644 --- a/pytchat/parser/live.py +++ b/pytchat/parser/live.py @@ -66,6 +66,23 @@ class Parser: raise ChatParseException('Cannot extract continuation data') return self._create_data(metadata, contents) + def reload_continuation(self, contents): + """ + When `seektime = 0` or seektime is abbreviated , + check if fetched chat json has no chat data. + If so, try to fetch playerSeekContinuationData. + This function must be run only first fetching. + """ + cont = contents['liveChatContinuation']['continuations'][0] + if cont.get("liveChatReplayContinuationData"): + #chat data exist. + return None + #chat data do not exist, get playerSeekContinuationData. + init_cont = cont.get("playerSeekContinuationData") + if init_cont: + return init_cont.get("continuation") + raise ChatParseException('Finished chat data') + def _create_data(self, metadata, contents): actions = contents['liveChatContinuation'].get('actions') if self.is_replay: