Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Merge tag 'fix_param' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
taizan-hokuto committed Feb 10, 2021
2 parents faf875c + 0a9837a commit bc401ac
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 235 deletions.
237 changes: 143 additions & 94 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pytchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup.
"""
__copyright__ = 'Copyright (C) 2019, 2020 taizan-hokuto'
__version__ = '0.5.2'
__version__ = '0.5.3'
__license__ = 'MIT'
__author__ = 'taizan-hokuto'
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
Expand Down
5 changes: 4 additions & 1 deletion pytchat/core/pytchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def _setup(self):
"""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,
Expand Down
13 changes: 10 additions & 3 deletions pytchat/core_async/livechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ async def _startlisten(self):
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):
Expand Down Expand Up @@ -210,8 +214,11 @@ async def _check_pause(self, continuation):
'''
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):
Expand Down
9 changes: 7 additions & 2 deletions pytchat/core_multithread/livechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ def _startlisten(self):
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):
Expand Down Expand Up @@ -207,7 +210,9 @@ def _check_pause(self, continuation):
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):
Expand Down
17 changes: 11 additions & 6 deletions pytchat/paramgen/liveparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
---------
Expand All @@ -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)
return _build(video_id, channel_id, *_times(past_sec), topchat_only)
48 changes: 0 additions & 48 deletions tests/test_livechat.py

This file was deleted.

71 changes: 0 additions & 71 deletions tests/test_livechat_2.py

This file was deleted.

9 changes: 0 additions & 9 deletions tests/test_liveparam.py

This file was deleted.

0 comments on commit bc401ac

Please sign in to comment.