Compare commits
8 Commits
v0.0.5.1.3
...
v0.0.5.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9de75788f2 | ||
|
|
76f0c0e658 | ||
|
|
0d8ecb778f | ||
|
|
bbf7a2906a | ||
|
|
1862b83eac | ||
|
|
053ff5291f | ||
|
|
4e47d4a262 | ||
|
|
956c7e2640 |
@@ -16,7 +16,7 @@ Other features:
|
|||||||
instead of web scraping.
|
instead of web scraping.
|
||||||
|
|
||||||
For more detailed information, see [wiki](https://github.com/taizan-hokuto/pytchat/wiki). <br>
|
For more detailed information, see [wiki](https://github.com/taizan-hokuto/pytchat/wiki). <br>
|
||||||
より詳細な解説は[wiki](https://github.com/taizan-hokuto/pytchat/wiki/Home-:)を参照してください。
|
より詳細な解説は[wiki](https://github.com/taizan-hokuto/pytchat/wiki/Home_jp)を参照してください。
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
```python
|
```python
|
||||||
@@ -267,4 +267,4 @@ Structure of author object.
|
|||||||
|
|
||||||
[taizan-hokuto](https://github.com/taizan-hokuto)
|
[taizan-hokuto](https://github.com/taizan-hokuto)
|
||||||
|
|
||||||
[twitter:@taizan205](https://twitter.com/taizan205)
|
[twitter:@taizan205](https://twitter.com/taizan205)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
pytchat is a python library for fetching youtube live chat without using yt api, Selenium, or BeautifulSoup.
|
pytchat is a python library for fetching youtube live chat without using yt api, Selenium, or BeautifulSoup.
|
||||||
"""
|
"""
|
||||||
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
__copyright__ = 'Copyright (C) 2019 taizan-hokuto'
|
||||||
__version__ = '0.0.5.1.3'
|
__version__ = '0.0.5.3'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__author__ = 'taizan-hokuto'
|
__author__ = 'taizan-hokuto'
|
||||||
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ class LiveChatAsync:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
_setup_finished = False
|
_setup_finished = False
|
||||||
_logger = config.logger(__name__)
|
|
||||||
|
|
||||||
def __init__(self, video_id,
|
def __init__(self, video_id,
|
||||||
seektime = 0,
|
seektime = 0,
|
||||||
@@ -233,6 +232,11 @@ class LiveChatAsync:
|
|||||||
self.video_id, self.seektime, self._topchat_only)
|
self.video_id, self.seektime, self._topchat_only)
|
||||||
livechat_json = (await self._get_livechat_json(
|
livechat_json = (await self._get_livechat_json(
|
||||||
continuation, session, headers))
|
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)
|
contents = self._parser.get_contents(livechat_json)
|
||||||
self._first_fetch = False
|
self._first_fetch = False
|
||||||
return contents
|
return contents
|
||||||
@@ -244,8 +248,7 @@ class LiveChatAsync:
|
|||||||
continuation = urllib.parse.quote(continuation)
|
continuation = urllib.parse.quote(continuation)
|
||||||
livechat_json = None
|
livechat_json = None
|
||||||
status_code = 0
|
status_code = 0
|
||||||
url =(
|
url =f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1"
|
||||||
f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1")
|
|
||||||
for _ in range(MAX_RETRY + 1):
|
for _ in range(MAX_RETRY + 1):
|
||||||
async with session.get(url ,headers = headers) as resp:
|
async with session.get(url ,headers = headers) as resp:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ class LiveChat:
|
|||||||
_setup_finished = False
|
_setup_finished = False
|
||||||
#チャット監視中のListenerのリスト
|
#チャット監視中のListenerのリスト
|
||||||
_listeners = []
|
_listeners = []
|
||||||
_logger = config.logger(__name__)
|
|
||||||
|
|
||||||
def __init__(self, video_id,
|
def __init__(self, video_id,
|
||||||
seektime = 0,
|
seektime = 0,
|
||||||
@@ -222,9 +221,15 @@ class LiveChat:
|
|||||||
'''Try to fetch archive chat data.'''
|
'''Try to fetch archive chat data.'''
|
||||||
self._parser.is_replay = True
|
self._parser.is_replay = True
|
||||||
self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation="
|
self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation="
|
||||||
continuation = arcparam.getparam(self.video_id, self.seektime)
|
continuation = arcparam.getparam(
|
||||||
|
self.video_id, self.seektime, self._topchat_only)
|
||||||
livechat_json = ( self._get_livechat_json(
|
livechat_json = ( self._get_livechat_json(
|
||||||
continuation, session, headers))
|
continuation, session, headers))
|
||||||
|
reload_continuation = self._parser.reload_continuation(
|
||||||
|
self._parser.get_contents(livechat_json))
|
||||||
|
if reload_continuation:
|
||||||
|
livechat_json = (self._get_livechat_json(
|
||||||
|
reload_continuation, session, headers))
|
||||||
contents = self._parser.get_contents(livechat_json)
|
contents = self._parser.get_contents(livechat_json)
|
||||||
self._first_fetch = False
|
self._first_fetch = False
|
||||||
return contents
|
return contents
|
||||||
|
|||||||
@@ -66,6 +66,23 @@ class Parser:
|
|||||||
raise ChatParseException('Cannot extract continuation data')
|
raise ChatParseException('Cannot extract continuation data')
|
||||||
return self._create_data(metadata, contents)
|
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):
|
def _create_data(self, metadata, contents):
|
||||||
actions = contents['liveChatContinuation'].get('actions')
|
actions = contents['liveChatContinuation'].get('actions')
|
||||||
if self.is_replay:
|
if self.is_replay:
|
||||||
|
|||||||
Reference in New Issue
Block a user