diff --git a/pytchat/core/pytchat.py b/pytchat/core/pytchat.py index 67dc976..93605e9 100644 --- a/pytchat/core/pytchat.py +++ b/pytchat/core/pytchat.py @@ -95,7 +95,10 @@ class PytchatCore: """Fetch first continuation parameter, create and start _listen loop. """ - self.continuation = liveparam.getparam(self._video_id, past_sec=3) + self.continuation = liveparam.getparam( + self._video_id, + channel_id=util.get_channelid(httpx.Client(http2=True), self._video_id), + past_sec=3) def _get_chat_component(self): ''' Fetch chat data and store them into buffer, diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index 322fd16..655f43c 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -152,7 +152,11 @@ class LiveChatAsync: create and start _listen loop. """ if not self.continuation: - self.continuation = liveparam.getparam(self._video_id, 3) + self.continuation = liveparam.getparam( + self._video_id, + channel_id=util.get_channelid(httpx.Client(http2=True), self._video_id), + past_sec=3) + await self._listen(self.continuation) async def _listen(self, continuation): @@ -210,8 +214,11 @@ class LiveChatAsync: ''' self._pauser.put_nowait(None) if not self._is_replay: - continuation = liveparam.getparam( - self._video_id, 3, self._topchat_only) + async with httpx.AsyncClient(http2=True) as client: + continuation = await liveparam.getparam(self._video_id, + channel_id=util.get_channelid_async(client, self.video_id), + past_sec=3) + return continuation async def _get_contents(self, continuation, client, headers): diff --git a/pytchat/core_multithread/livechat.py b/pytchat/core_multithread/livechat.py index 4125852..153dce1 100644 --- a/pytchat/core_multithread/livechat.py +++ b/pytchat/core_multithread/livechat.py @@ -148,7 +148,10 @@ class LiveChat: create and start _listen loop. """ if not self.continuation: - self.continuation = liveparam.getparam(self._video_id, 3) + self.continuation = liveparam.getparam( + self._video_id, + channel_id=util.get_channelid(httpx.Client(http2=True), self._video_id), + past_sec=3) self._listen(self.continuation) def _listen(self, continuation): @@ -207,7 +210,9 @@ class LiveChat: self._pauser.put_nowait(None) if not self._is_replay: continuation = liveparam.getparam( - self._video_id, 3, self._topchat_only) + self._video_id, channel_id=util.get_channelid(httpx.Client(http2=True), self._video_id), + past_sec=3, topchat_only=self._topchat_only) + return continuation def _get_contents(self, continuation, client, headers): diff --git a/pytchat/paramgen/liveparam.py b/pytchat/paramgen/liveparam.py index 6302832..52997ac 100644 --- a/pytchat/paramgen/liveparam.py +++ b/pytchat/paramgen/liveparam.py @@ -5,11 +5,16 @@ from base64 import urlsafe_b64encode as b64enc from urllib.parse import quote -def _header(video_id) -> str: - return b64enc(enc.rs(1, enc.rs(1, enc.rs(1, video_id))) + enc.nm(4, 1)) +def _header(video_id, channel_id) -> str: + S1_3 = enc.rs(1, video_id) + S1_5 = enc.rs(1, channel_id) + enc.rs(2, video_id) + S1 = enc.rs(3, S1_3) + enc.rs(5, S1_5) + S3 = enc.rs(48687757, enc.rs(1, video_id)) + header_replay = enc.rs(1, S1) + enc.rs(3, S3) + enc.nm(4, 1) + return b64enc(header_replay) -def _build(video_id, ts1, ts2, ts3, ts4, ts5, topchat_only) -> str: +def _build(video_id, channel_id, ts1, ts2, ts3, ts4, ts5, topchat_only) -> str: chattype = 4 if topchat_only else 1 b1 = enc.nm(1, 0) @@ -23,7 +28,7 @@ def _build(video_id, ts1, ts2, ts3, ts4, ts5, topchat_only) -> str: b11 = enc.nm(11, 3) b15 = enc.nm(15, 0) - header = enc.rs(3, _header(video_id)) + header = enc.rs(3, _header(video_id, channel_id)) timestamp1 = enc.nm(5, ts1) s6 = enc.nm(6, 0) s7 = enc.nm(7, 0) @@ -53,7 +58,7 @@ def _times(past_sec): return list(map(lambda x: int(x * 1000000), [_ts1, _ts2, _ts3, _ts4, _ts5])) -def getparam(video_id, past_sec=0, topchat_only=False) -> str: +def getparam(video_id, channel_id, past_sec=0, topchat_only=False) -> str: ''' Parameter --------- @@ -62,4 +67,4 @@ def getparam(video_id, past_sec=0, topchat_only=False) -> str: topchat_only : bool if True, fetch only 'top chat' ''' - return _build(video_id, *_times(past_sec), topchat_only) \ No newline at end of file + return _build(video_id, channel_id, *_times(past_sec), topchat_only) \ No newline at end of file