Extract method _check_pause()
This commit is contained in:
@@ -149,15 +149,7 @@ class LiveChatAsync:
|
|||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
while(continuation and self._is_alive):
|
while(continuation and self._is_alive):
|
||||||
if self._pauser.empty():
|
continuation = await self._check_pause(continuation)
|
||||||
'''pause'''
|
|
||||||
await self._pauser.get()
|
|
||||||
'''resume:
|
|
||||||
prohibit from blocking by putting None into _pauser.
|
|
||||||
'''
|
|
||||||
self._pauser.put_nowait(None)
|
|
||||||
if self._parser.mode == 'LIVE':
|
|
||||||
continuation = liveparam.getparam(self.video_id,3)
|
|
||||||
contents = await self._get_contents(
|
contents = await self._get_contents(
|
||||||
continuation, session, headers)
|
continuation, session, headers)
|
||||||
metadata, chatdata = self._parser.parse(contents)
|
metadata, chatdata = self._parser.parse(contents)
|
||||||
@@ -190,6 +182,18 @@ class LiveChatAsync:
|
|||||||
logger.debug(f"[{self.video_id}]チャット取得を終了しました。")
|
logger.debug(f"[{self.video_id}]チャット取得を終了しました。")
|
||||||
self.terminate()
|
self.terminate()
|
||||||
|
|
||||||
|
async def _check_pause(self, continuation):
|
||||||
|
if self._pauser.empty():
|
||||||
|
'''pause'''
|
||||||
|
await self._pauser.get()
|
||||||
|
'''resume:
|
||||||
|
prohibit from blocking by putting None into _pauser.
|
||||||
|
'''
|
||||||
|
self._pauser.put_nowait(None)
|
||||||
|
if self._parser.mode == 'LIVE':
|
||||||
|
continuation = liveparam.getparam(self.video_id,3)
|
||||||
|
return continuation
|
||||||
|
|
||||||
async def _get_contents(self, continuation, session, headers):
|
async def _get_contents(self, continuation, session, headers):
|
||||||
'''Get 'contents' dict from livechat json.
|
'''Get 'contents' dict from livechat json.
|
||||||
If contents is None at first fetching,
|
If contents is None at first fetching,
|
||||||
|
|||||||
Reference in New Issue
Block a user