Lint
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import aiohttp, asyncio
|
import aiohttp
|
||||||
import datetime
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import random
|
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@@ -75,7 +74,7 @@ class LiveChatAsync:
|
|||||||
_setup_finished = False
|
_setup_finished = False
|
||||||
|
|
||||||
def __init__(self, video_id,
|
def __init__(self, video_id,
|
||||||
seektime = 0,
|
seektime=-1,
|
||||||
processor=DefaultProcessor(),
|
processor=DefaultProcessor(),
|
||||||
buffer=None,
|
buffer=None,
|
||||||
interruptable=True,
|
interruptable=True,
|
||||||
@@ -219,9 +218,7 @@ class LiveChatAsync:
|
|||||||
-------
|
-------
|
||||||
'continuationContents' which includes metadata & chatdata.
|
'continuationContents' which includes metadata & chatdata.
|
||||||
'''
|
'''
|
||||||
livechat_json = (await
|
livechat_json = await self._get_livechat_json(continuation, session, headers)
|
||||||
self._get_livechat_json(continuation, session, headers)
|
|
||||||
)
|
|
||||||
contents = self._parser.get_contents(livechat_json)
|
contents = self._parser.get_contents(livechat_json)
|
||||||
if self._first_fetch:
|
if self._first_fetch:
|
||||||
if contents is None or self._is_replay:
|
if contents is None or self._is_replay:
|
||||||
@@ -325,7 +322,7 @@ class LiveChatAsync:
|
|||||||
Listenerを終了する。
|
Listenerを終了する。
|
||||||
'''
|
'''
|
||||||
self._is_alive = False
|
self._is_alive = False
|
||||||
if self._direct_mode == False:
|
if self._direct_mode is False:
|
||||||
# bufferにダミーオブジェクトを入れてis_alive()を判定させる
|
# bufferにダミーオブジェクトを入れてis_alive()を判定させる
|
||||||
self._buffer.put_nowait({'chatdata': '', 'timeout': 0})
|
self._buffer.put_nowait({'chatdata': '', 'timeout': 0})
|
||||||
self._logger.info(f'[{self.video_id}]finished.')
|
self._logger.info(f'[{self.video_id}]finished.')
|
||||||
@@ -342,7 +339,7 @@ class LiveChatAsync:
|
|||||||
asyncio.current_task()]
|
asyncio.current_task()]
|
||||||
[task.cancel() for task in tasks]
|
[task.cancel() for task in tasks]
|
||||||
|
|
||||||
cls._logger.debug(f"complete remaining tasks...")
|
cls._logger.debug("complete remaining tasks...")
|
||||||
await asyncio.gather(*tasks, return_exceptions=True)
|
await asyncio.gather(*tasks, return_exceptions=True)
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.stop()
|
loop.stop()
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
import datetime
|
|
||||||
import json
|
import json
|
||||||
import random
|
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@@ -74,7 +72,7 @@ class LiveChat:
|
|||||||
_setup_finished = False
|
_setup_finished = False
|
||||||
|
|
||||||
def __init__(self, video_id,
|
def __init__(self, video_id,
|
||||||
seektime=0,
|
seektime=-1,
|
||||||
processor=DefaultProcessor(),
|
processor=DefaultProcessor(),
|
||||||
buffer=None,
|
buffer=None,
|
||||||
interruptable=True,
|
interruptable=True,
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from base64 import urlsafe_b64encode as b64enc
|
from base64 import urlsafe_b64encode as b64enc
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
import math
|
|
||||||
import random
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@@ -12,6 +10,7 @@ Author: taizan-hokuto (2019) @taizan205
|
|||||||
ver 0.0.1 2019.10.05
|
ver 0.0.1 2019.10.05
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def _gen_vid_long(video_id):
|
def _gen_vid_long(video_id):
|
||||||
"""generate video_id parameter.
|
"""generate video_id parameter.
|
||||||
Parameter
|
Parameter
|
||||||
@@ -67,7 +66,8 @@ def _gen_vid(video_id):
|
|||||||
|
|
||||||
def _nval(val):
|
def _nval(val):
|
||||||
"""convert value to byte array"""
|
"""convert value to byte array"""
|
||||||
if val<0: raise ValueError
|
if val < 0:
|
||||||
|
raise ValueError
|
||||||
buf = b''
|
buf = b''
|
||||||
while val >> 7:
|
while val >> 7:
|
||||||
m = val & 0xFF | 0x80
|
m = val & 0xFF | 0x80
|
||||||
@@ -76,6 +76,7 @@ def _nval(val):
|
|||||||
buf += val.to_bytes(1, 'big')
|
buf += val.to_bytes(1, 'big')
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
|
||||||
def _build(video_id, seektime, topchat_only):
|
def _build(video_id, seektime, topchat_only):
|
||||||
switch_01 = b'\x04' if topchat_only else b'\x01'
|
switch_01 = b'\x04' if topchat_only else b'\x01'
|
||||||
if seektime < 0:
|
if seektime < 0:
|
||||||
@@ -85,9 +86,7 @@ def _build(video_id, seektime, topchat_only):
|
|||||||
else:
|
else:
|
||||||
times = _nval(int(seektime*1000))
|
times = _nval(int(seektime*1000))
|
||||||
if seektime > 0:
|
if seektime > 0:
|
||||||
_len_time = ( b'\x5A'
|
_len_time = b'\x5A' + (len(times)+1).to_bytes(1, 'big') + b'\x10'
|
||||||
+ (len(times)+1).to_bytes(1,'big')
|
|
||||||
+ b'\x10')
|
|
||||||
else:
|
else:
|
||||||
_len_time = b''
|
_len_time = b''
|
||||||
|
|
||||||
@@ -120,6 +119,7 @@ def _build(video_id, seektime, topchat_only):
|
|||||||
).decode()
|
).decode()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def getparam(video_id, seektime=0.0, topchat_only=False):
|
def getparam(video_id, seektime=0.0, topchat_only=False):
|
||||||
'''
|
'''
|
||||||
Parameter
|
Parameter
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ pytchat.parser.live
|
|||||||
Parser of live chat JSON.
|
Parser of live chat JSON.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
|
||||||
from .. exceptions import (
|
from .. exceptions import (
|
||||||
ResponseContextError,
|
ResponseContextError,
|
||||||
NoContentsException,
|
NoContentsException,
|
||||||
NoContinuationsException,
|
NoContinuationsException,
|
||||||
ChatParseException)
|
ChatParseException)
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
|
|
||||||
__slots__ = ['is_replay']
|
__slots__ = ['is_replay']
|
||||||
@@ -22,8 +22,7 @@ class Parser:
|
|||||||
if jsn is None:
|
if jsn is None:
|
||||||
raise ChatParseException('Called with none JSON object.')
|
raise ChatParseException('Called with none JSON object.')
|
||||||
if jsn['response']['responseContext'].get('errors'):
|
if jsn['response']['responseContext'].get('errors'):
|
||||||
raise ResponseContextError('The video_id would be wrong,'
|
raise ResponseContextError('The video_id would be wrong, or video is deleted or private.')
|
||||||
'or video is deleted or private.')
|
|
||||||
contents = jsn['response'].get('continuationContents')
|
contents = jsn['response'].get('continuationContents')
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user