diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index 48dd526..29ae9d7 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -1,7 +1,6 @@ -import aiohttp, asyncio -import datetime +import aiohttp +import asyncio import json -import random import signal import time import traceback @@ -12,8 +11,8 @@ from asyncio import Queue from .buffer import Buffer from ..parser.live import Parser from .. import config -from ..exceptions import ChatParseException,IllegalFunctionCall -from ..paramgen import liveparam, arcparam +from ..exceptions import ChatParseException, IllegalFunctionCall +from ..paramgen import liveparam, arcparam from ..processors.default.processor import DefaultProcessor from ..processors.combinator import Combinator @@ -58,14 +57,14 @@ class LiveChatAsync: Trueの場合、bufferを使わずにcallbackを呼ぶ。 Trueの場合、callbackの設定が必須 (設定していない場合IllegalFunctionCall例外を発生させる) - - force_replay : bool + + force_replay : bool Trueの場合、ライブチャットが取得できる場合であっても 強制的にアーカイブ済みチャットを取得する。 - + topchat_only : bool Trueの場合、上位チャットのみ取得する。 - + Attributes --------- _is_alive : bool @@ -75,19 +74,19 @@ class LiveChatAsync: _setup_finished = False def __init__(self, video_id, - seektime = 0, - processor = DefaultProcessor(), - buffer = None, - interruptable = True, - callback = None, - done_callback = None, - exception_handler = None, - direct_mode = False, - force_replay = False, - topchat_only = False, - logger = config.logger(__name__), - ): - self.video_id = video_id + seektime=-1, + processor=DefaultProcessor(), + buffer=None, + interruptable=True, + callback=None, + done_callback=None, + exception_handler=None, + direct_mode=False, + force_replay=False, + topchat_only=False, + logger=config.logger(__name__), + ): + self.video_id = video_id self.seektime = seektime if isinstance(processor, tuple): self.processor = Combinator(processor) @@ -98,9 +97,9 @@ class LiveChatAsync: self._done_callback = done_callback self._exception_handler = exception_handler self._direct_mode = direct_mode - self._is_alive = True + self._is_alive = True self._is_replay = force_replay - self._parser = Parser(is_replay = self._is_replay) + self._parser = Parser(is_replay=self._is_replay) self._pauser = Queue() self._pauser.put_nowait(None) self._setup() @@ -115,32 +114,32 @@ class LiveChatAsync: if exception_handler: self._set_exception_handler(exception_handler) if interruptable: - signal.signal(signal.SIGINT, - (lambda a, b:asyncio.create_task( - LiveChatAsync.shutdown(None,signal.SIGINT,b)) - )) - + signal.signal(signal.SIGINT, + (lambda a, b: asyncio.create_task( + LiveChatAsync.shutdown(None, signal.SIGINT, b)) + )) + def _setup(self): - #direct modeがTrueでcallback未設定の場合例外発生。 + # direct modeがTrueでcallback未設定の場合例外発生。 if self._direct_mode: if self._callback is None: raise IllegalFunctionCall( "When direct_mode=True, callback parameter is required.") else: - #direct modeがFalseでbufferが未設定ならばデフォルトのbufferを作成 + # direct modeがFalseでbufferが未設定ならばデフォルトのbufferを作成 if self._buffer is None: - self._buffer = Buffer(maxsize = 20) - #callbackが指定されている場合はcallbackを呼ぶループタスクを作成 + self._buffer = Buffer(maxsize=20) + # callbackが指定されている場合はcallbackを呼ぶループタスクを作成 if self._callback is None: - pass + pass else: - #callbackを呼ぶループタスクの開始 + # callbackを呼ぶループタスクの開始 loop = asyncio.get_event_loop() loop.create_task(self._callback_loop(self._callback)) - #_listenループタスクの開始 + # _listenループタスクの開始 loop = asyncio.get_event_loop() listen_task = loop.create_task(self._startlisten()) - #add_done_callbackの登録 + # add_done_callbackの登録 if self._done_callback is None: listen_task.add_done_callback(self.finish) else: @@ -150,7 +149,7 @@ class LiveChatAsync: """Fetch first continuation parameter, create and start _listen loop. """ - initial_continuation = liveparam.getparam(self.video_id,3) + initial_continuation = liveparam.getparam(self.video_id, 3) await self._listen(initial_continuation) async def _listen(self, continuation): @@ -168,33 +167,33 @@ class LiveChatAsync: continuation = await self._check_pause(continuation) contents = await self._get_contents( continuation, session, headers) - metadata, chatdata = self._parser.parse(contents) + metadata, chatdata = self._parser.parse(contents) timeout = metadata['timeoutMs']/1000 chat_component = { - "video_id" : self.video_id, - "timeout" : timeout, - "chatdata" : chatdata + "video_id": self.video_id, + "timeout": timeout, + "chatdata": chatdata } - time_mark =time.time() + time_mark = time.time() if self._direct_mode: processed_chat = self.processor.process([chat_component]) - if isinstance(processed_chat,tuple): + if isinstance(processed_chat, tuple): await self._callback(*processed_chat) else: await self._callback(processed_chat) else: await self._buffer.put(chat_component) diff_time = timeout - (time.time()-time_mark) - await asyncio.sleep(diff_time) - continuation = metadata.get('continuation') + await asyncio.sleep(diff_time) + continuation = metadata.get('continuation') except ChatParseException as e: self._logger.debug(f"[{self.video_id}]{str(e)}") - return - except (TypeError , json.JSONDecodeError) : + return + except (TypeError, json.JSONDecodeError): self._logger.error(f"{traceback.format_exc(limit = -1)}") return - + self._logger.debug(f"[{self.video_id}]finished fetching chat.") async def _check_pause(self, continuation): @@ -212,16 +211,14 @@ class LiveChatAsync: async def _get_contents(self, continuation, session, headers): '''Get 'continuationContents' from livechat json. - If contents is None at first fetching, + If contents is None at first fetching, try to fetch archive chat data. Return: ------- 'continuationContents' which includes metadata & chatdata. ''' - livechat_json = (await - self._get_livechat_json(continuation, session, headers) - ) + livechat_json = await self._get_livechat_json(continuation, session, headers) contents = self._parser.get_contents(livechat_json) if self._first_fetch: if contents is None or self._is_replay: @@ -230,12 +227,12 @@ class LiveChatAsync: self._fetch_url = "live_chat_replay/get_live_chat_replay?continuation=" continuation = arcparam.getparam( self.video_id, self.seektime, self._topchat_only) - livechat_json = (await self._get_livechat_json( - continuation, session, headers)) + livechat_json = (await self._get_livechat_json( + 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( + livechat_json = (await self._get_livechat_json( reload_continuation, session, headers)) contents = self._parser.get_contents(livechat_json) self._is_replay = True @@ -249,26 +246,26 @@ class LiveChatAsync: continuation = urllib.parse.quote(continuation) livechat_json = None status_code = 0 - url =f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" + url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=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: text = await resp.text() livechat_json = json.loads(text) break - except (ClientConnectorError,json.JSONDecodeError) : + except (ClientConnectorError, json.JSONDecodeError): await asyncio.sleep(1) continue else: self._logger.error(f"[{self.video_id}]" - f"Exceeded retry count. status_code={status_code}") + f"Exceeded retry count. status_code={status_code}") return None return livechat_json - async def _callback_loop(self,callback): + async def _callback_loop(self, callback): """ コンストラクタでcallbackを指定している場合、バックグラウンドで - callbackに指定された関数に一定間隔でチャットデータを投げる。 - + callbackに指定された関数に一定間隔でチャットデータを投げる。 + Parameter --------- callback : func @@ -285,13 +282,13 @@ class LiveChatAsync: async def get(self): """ bufferからデータを取り出し、processorに投げ、 加工済みのチャットデータを返す。 - + Returns : Processorによって加工されたチャットデータ """ if self._callback is None: items = await self._buffer.get() - return self.processor.process(items) + return self.processor.process(items) raise IllegalFunctionCall( "既にcallbackを登録済みのため、get()は実行できません。") @@ -309,13 +306,13 @@ class LiveChatAsync: return if self._pauser.empty(): self._pauser.put_nowait(None) - + def is_alive(self): return self._is_alive - def finish(self,sender): + def finish(self, sender): '''Listener終了時のコールバック''' - try: + try: self.terminate() except CancelledError: self._logger.debug(f'[{self.video_id}]cancelled:{sender}') @@ -325,24 +322,24 @@ class LiveChatAsync: Listenerを終了する。 ''' self._is_alive = False - if self._direct_mode == False: - #bufferにダミーオブジェクトを入れてis_alive()を判定させる - self._buffer.put_nowait({'chatdata':'','timeout':0}) + if self._direct_mode is False: + # bufferにダミーオブジェクトを入れてis_alive()を判定させる + self._buffer.put_nowait({'chatdata': '', 'timeout': 0}) self._logger.info(f'[{self.video_id}]finished.') - + @classmethod def _set_exception_handler(cls, handler): loop = asyncio.get_event_loop() loop.set_exception_handler(handler) - + @classmethod - async def shutdown(cls, event, sig = None, handler=None): + async def shutdown(cls, event, sig=None, handler=None): cls._logger.debug("shutdown...") tasks = [t for t in asyncio.all_tasks() if t is not - asyncio.current_task()] + asyncio.current_task()] [task.cancel() for task in tasks] - cls._logger.debug(f"complete remaining tasks...") - await asyncio.gather(*tasks,return_exceptions=True) + cls._logger.debug("complete remaining tasks...") + await asyncio.gather(*tasks, return_exceptions=True) loop = asyncio.get_event_loop() - loop.stop() \ No newline at end of file + loop.stop() diff --git a/pytchat/core_multithread/livechat.py b/pytchat/core_multithread/livechat.py index 8ce84e8..5003331 100644 --- a/pytchat/core_multithread/livechat.py +++ b/pytchat/core_multithread/livechat.py @@ -1,7 +1,5 @@ import requests -import datetime import json -import random import signal import time import traceback @@ -53,9 +51,9 @@ class LiveChat: direct_mode : bool Trueの場合、bufferを使わずにcallbackを呼ぶ。 Trueの場合、callbackの設定が必須 - (設定していない場合IllegalFunctionCall例外を発生させる) + (設定していない場合IllegalFunctionCall例外を発生させる) - force_replay : bool + force_replay : bool Trueの場合、ライブチャットが取得できる場合であっても 強制的にアーカイブ済みチャットを取得する。 @@ -74,7 +72,7 @@ class LiveChat: _setup_finished = False def __init__(self, video_id, - seektime=0, + seektime=-1, processor=DefaultProcessor(), buffer=None, interruptable=True, @@ -181,7 +179,7 @@ class LiveChat: self._logger.debug(f"[{self.video_id}]{str(e)}") return except (TypeError, json.JSONDecodeError): - self._logger.error(f"{traceback.format_exc(limit = -1)}") + self._logger.error(f"{traceback.format_exc(limit=-1)}") return self._logger.debug(f"[{self.video_id}]finished fetching chat.") @@ -200,7 +198,7 @@ class LiveChat: def _get_contents(self, continuation, session, headers): '''Get 'continuationContents' from livechat json. - If contents is None at first fetching, + If contents is None at first fetching, try to fetch archive chat data. Return: @@ -255,7 +253,7 @@ class LiveChat: def _callback_loop(self, callback): """ コンストラクタでcallbackを指定している場合、バックグラウンドで - callbackに指定された関数に一定間隔でチャットデータを投げる。 + callbackに指定された関数に一定間隔でチャットデータを投げる。 Parameter --------- diff --git a/pytchat/paramgen/arcparam.py b/pytchat/paramgen/arcparam.py index f62cb40..a8048d5 100644 --- a/pytchat/paramgen/arcparam.py +++ b/pytchat/paramgen/arcparam.py @@ -1,111 +1,55 @@ -from base64 import urlsafe_b64encode as b64enc -from functools import reduce -import math -import random -import urllib.parse +from .pb.header_pb2 import Header +from .pb.replay_pb2 import Continuation +from urllib.parse import quote +import base64 ''' Generate continuation parameter of youtube replay chat. -Author: taizan-hokuto (2019) @taizan205 +Author: taizan-hokuto -ver 0.0.1 2019.10.05 +ver 0.0.1 2019.10.05 : Initial release. +ver 0.0.2 2020.05.30 : Use Protocol Buffers. ''' -def _gen_vid(video_id): - """generate video_id parameter. - Parameter - --------- - video_id : str - - Return - --------- - bytes : base64 encoded video_id parameter. - """ - header_magic = b'\x0A\x0F\x1A\x0D\x0A' - header_id = video_id.encode() - header_sep_1 = b'\x1A\x13\xEA\xA8\xDD\xB9\x01\x0D\x0A\x0B' - header_terminator = b'\x20\x01' - - item = [ - header_magic, - _nval(len(header_id)), - header_id, - header_sep_1, - header_id, - header_terminator - ] - - return urllib.parse.quote( - b64enc(reduce(lambda x, y: x+y, item)).decode() - ).encode() +def _gen_vid(video_id) -> str: + header = Header() + header.info.video.id = video_id + header.terminator = 1 + return base64.urlsafe_b64encode(header.SerializeToString()).decode() -def _nval(val): - """convert value to byte array""" - if val < 0: - raise ValueError - buf = b'' - while val >> 7: - m = val & 0xFF | 0x80 - buf += m.to_bytes(1, 'big') - val >>= 7 - buf += val.to_bytes(1, 'big') - return buf +def _build(video_id, seektime, topchat_only) -> str: + chattype = 1 + timestamp = 0 + if topchat_only: + chattype = 4 - -def _build(video_id, seektime, topchat_only): - switch_01 = b'\x04' if topchat_only else b'\x01' + fetch_before_start = 3 if seektime < 0: - times = _nval(0) - switch = b'\x04' + fetch_before_start = 4 elif seektime == 0: - times = _nval(1) - switch = b'\x03' + timestamp = 1 else: - times = _nval(int(seektime*1000000)) - switch = b'\x03' - parity = b'\x00' - - header_magic = b'\xA2\x9D\xB0\xD3\x04' - sep_0 = b'\x1A' - vid = _gen_vid(video_id) - time_tag = b'\x28' - timestamp1 = times - sep_1 = b'\x30\x00\x38\x00\x40\x00\x48' - sep_2 = b'\x52\x1C\x08\x00\x10\x00\x18\x00\x20\x00' - chkstr = b'\x2A\x0E\x73\x74\x61\x74\x69\x63\x63\x68\x65\x63\x6B\x73\x75\x6D\x40' - sep_3 = b'\x00\x58\x03\x60' - sep_4 = b'\x68' + parity + b'\x72\x04\x08' - sep_5 = b'\x10' + parity + b'\x78\x00' - - body = b''.join([ - sep_0, - _nval(len(vid)), - vid, - time_tag, - timestamp1, - sep_1, - switch, - sep_2, - chkstr, - sep_3, - switch_01, - sep_4, - switch_01, - sep_5 - ]) - - return urllib.parse.quote( - b64enc(header_magic + - _nval(len(body)) + - body - ).decode() - ) + timestamp = int(seektime*1000000) + continuation = Continuation() + entity = continuation.entity + entity.header = _gen_vid(video_id) + entity.timestamp = timestamp + entity.s6 = 0 + entity.s7 = 0 + entity.s8 = 0 + entity.s9 = fetch_before_start + entity.s10 = '' + entity.s12 = chattype + entity.chattype.value = chattype + entity.s15 = 0 + return quote( + base64.urlsafe_b64encode(continuation.SerializeToString()).decode()) -def getparam(video_id, seektime=0, topchat_only=False): +def getparam(video_id, seektime=-1, topchat_only=False) -> str: ''' Parameter --------- diff --git a/pytchat/paramgen/arcparam_mining.py b/pytchat/paramgen/arcparam_mining.py index e6694e2..d24deed 100644 --- a/pytchat/paramgen/arcparam_mining.py +++ b/pytchat/paramgen/arcparam_mining.py @@ -1,7 +1,5 @@ from base64 import urlsafe_b64encode as b64enc from functools import reduce -import math -import random import urllib.parse ''' @@ -12,6 +10,7 @@ Author: taizan-hokuto (2019) @taizan205 ver 0.0.1 2019.10.05 ''' + def _gen_vid_long(video_id): """generate video_id parameter. Parameter @@ -23,7 +22,7 @@ def _gen_vid_long(video_id): byte[] : base64 encoded video_id parameter. """ header_magic = b'\x0A\x0F\x1A\x0D\x0A' - header_id = video_id.encode() + header_id = video_id.encode() header_sep_1 = b'\x1A\x13\xEA\xA8\xDD\xB9\x01\x0D\x0A\x0B' header_terminator = b'\x20\x01' @@ -67,15 +66,17 @@ def _gen_vid(video_id): def _nval(val): """convert value to byte array""" - if val<0: raise ValueError + if val < 0: + raise ValueError buf = b'' while val >> 7: m = val & 0xFF | 0x80 - buf += m.to_bytes(1,'big') + buf += m.to_bytes(1, 'big') val >>= 7 - buf += val.to_bytes(1,'big') + buf += val.to_bytes(1, 'big') return buf + def _build(video_id, seektime, topchat_only): switch_01 = b'\x04' if topchat_only else b'\x01' if seektime < 0: @@ -83,11 +84,9 @@ def _build(video_id, seektime, topchat_only): if seektime == 0: times = b'' else: - times =_nval(int(seektime*1000)) + times = _nval(int(seektime*1000)) if seektime > 0: - _len_time = ( b'\x5A' - + (len(times)+1).to_bytes(1,'big') - + b'\x10') + _len_time = b'\x5A' + (len(times)+1).to_bytes(1, 'big') + b'\x10' else: _len_time = b'' @@ -112,15 +111,16 @@ def _build(video_id, seektime, topchat_only): ] body = reduce(lambda x, y: x+y, body) - - return urllib.parse.quote( - b64enc( header_magic + + + return urllib.parse.quote( + b64enc(header_magic + _nval(len(body)) + body ).decode() ) -def getparam(video_id, seektime = 0.0, topchat_only = False): + +def getparam(video_id, seektime=0.0, topchat_only=False): ''' Parameter --------- diff --git a/pytchat/paramgen/liveparam.py b/pytchat/paramgen/liveparam.py index 09d8273..e0525fa 100644 --- a/pytchat/paramgen/liveparam.py +++ b/pytchat/paramgen/liveparam.py @@ -1,19 +1,21 @@ -from base64 import urlsafe_b64encode as b64enc -from functools import reduce -import time +from .pb.header_pb2 import Header +from .pb.live_pb2 import Continuation +from urllib.parse import quote +import base64 import random -import urllib.parse +import time ''' Generate continuation parameter of youtube live chat. -Author: taizan-hokuto (2019) @taizan205 +Author: taizan-hokuto -ver 0.0.1 2019.10.05 +ver 0.0.1 2019.10.05 : Initial release. +ver 0.0.2 2020.05.30 : Use Protocol Buffers. ''' -def _gen_vid(video_id): +def _gen_vid(video_id) -> str: """generate video_id parameter. Parameter --------- @@ -23,130 +25,49 @@ def _gen_vid(video_id): --------- byte[] : base64 encoded video_id parameter. """ - header_magic = b'\x0A\x0F\x0A\x0D\x0A' - header_id = video_id.encode() - header_sep_1 = b'\x1A' - header_sep_2 = b'\x43\xAA\xB9\xC1\xBD\x01\x3D\x0A' - header_suburl = ('https://www.youtube.com/live_chat?v=' - f'{video_id}&is_popout=1').encode() - header_terminator = b'\x20\x02' - - item = [ - header_magic, - _nval(len(header_id)), - header_id, - header_sep_1, - header_sep_2, - _nval(len(header_suburl)), - header_suburl, - header_terminator - ] - - return urllib.parse.quote( - b64enc(reduce(lambda x, y: x+y, item)).decode() - ).encode() + header = Header() + header.info.video.id = video_id + header.terminator = 1 + return base64.urlsafe_b64encode(header.SerializeToString()).decode() -def _tzparity(video_id, times): - t = 0 - for i, s in enumerate(video_id): - ss = ord(s) - if(ss % 2 == 0): - t += ss*(12-i) - else: - t ^= ss*i +def _build(video_id, ts1, ts2, ts3, ts4, ts5, topchat_only) -> str: + chattype = 1 + if topchat_only: + chattype = 4 + continuation = Continuation() + entity = continuation.entity - return ((times ^ t) % 2).to_bytes(1, 'big') + entity.header = _gen_vid(video_id) + entity.timestamp1 = ts1 + entity.s6 = 0 + entity.s7 = 0 + entity.s8 = 1 + entity.body.b1 = 0 + entity.body.b2 = 0 + entity.body.b3 = 0 + entity.body.b4 = 0 + entity.body.b7 = '' + entity.body.b8 = 0 + entity.body.b9 = '' + entity.body.timestamp2 = ts2 + entity.body.b11 = 3 + entity.body.b15 = 0 + entity.timestamp3 = ts3 + entity.timestamp4 = ts4 + entity.s13 = chattype + entity.chattype.value = chattype + entity.s17 = 0 + entity.str19.value = 0 + entity.timestamp5 = ts5 - -def _nval(val): - """convert value to byte array""" - if val < 0: - raise ValueError - buf = b'' - while val >> 7: - m = val & 0xFF | 0x80 - buf += m.to_bytes(1, 'big') - val >>= 7 - buf += val.to_bytes(1, 'big') - return buf - - -def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchat_only): - # _short_type2 - switch_01 = b'\x04' if topchat_only else b'\x01' - parity = _tzparity(video_id, _ts1 ^ _ts2 ^ _ts3 ^ _ts4 ^ _ts5) - - header_magic = b'\xD2\x87\xCC\xC8\x03' - sep_0 = b'\x1A' - vid = _gen_vid(video_id) - time_tag = b'\x28' - timestamp1 = _nval(_ts1) - sep_1 = b'\x30\x00\x38\x00\x40\x02\x4A' - un_len = b'\x2B' - sep_2 = b'\x08'+parity+b'\x10\x00\x18\x00\x20\x00' - chkstr = b'\x2A\x0E\x73\x74\x61\x74\x69\x63\x63\x68\x65\x63\x6B\x73\x75\x6D' - sep_3 = b'\x3A\x00\x40\x00\x4A' - sep_4_len = b'\x02' - sep_4 = b'\x08\x01' - ts_2_start = b'\x50' - timestamp2 = _nval(_ts2) - ts_2_end = b'\x58' - sep_5 = b'\x03' - ts_3_start = b'\x50' - timestamp3 = _nval(_ts3) - ts_3_end = b'\x58' - timestamp4 = _nval(_ts4) - sep_6 = b'\x68' - # switch - sep_7 = b'\x82\x01\x04\x08' - # switch - sep_8 = b'\x10\x00' - sep_9 = b'\x88\x01\x00\xA0\x01' - timestamp5 = _nval(_ts5) - - body = b''.join([ - sep_0, - _nval(len(vid)), - vid, - time_tag, - timestamp1, - sep_1, - un_len, - sep_2, - chkstr, - sep_3, - sep_4_len, - sep_4, - ts_2_start, - timestamp2, - ts_2_end, - sep_5, - ts_3_start, - timestamp3, - ts_3_end, - timestamp4, - sep_6, - switch_01, - sep_7, - switch_01, - sep_8, - sep_9, - timestamp5 - ]) - - return urllib.parse.quote( - b64enc(header_magic + - _nval(len(body)) + - body - ).decode() + return quote( + base64.urlsafe_b64encode(continuation.SerializeToString()).decode() ) def _times(past_sec): - n = int(time.time()) - _ts1 = n - random.uniform(0, 1*3) _ts2 = n - random.uniform(0.01, 0.99) _ts3 = n - past_sec + random.uniform(0, 1) @@ -155,7 +76,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): +def getparam(video_id, past_sec=0, topchat_only=False) -> str: ''' Parameter --------- diff --git a/pytchat/paramgen/pb/__init__.py b/pytchat/paramgen/pb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pytchat/paramgen/pb/header_pb2.py b/pytchat/paramgen/pb/header_pb2.py new file mode 100644 index 0000000..a45550a --- /dev/null +++ b/pytchat/paramgen/pb/header_pb2.py @@ -0,0 +1,159 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: header.proto + +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='header.proto', + package='', + syntax='proto3', + serialized_options=None, + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\x0cheader.proto\"\x13\n\x05Video\x12\n\n\x02id\x18\x01 \x01(\t\"#\n\nHeaderInfo\x12\x15\n\x05video\x18\x01 \x01(\x0b\x32\x06.Video\"7\n\x06Header\x12\x19\n\x04info\x18\x01 \x01(\x0b\x32\x0b.HeaderInfo\x12\x12\n\nterminator\x18\x04 \x01(\x05\x62\x06proto3' +) + + + + +_VIDEO = _descriptor.Descriptor( + name='Video', + full_name='Video', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='id', full_name='Video.id', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=16, + serialized_end=35, +) + + +_HEADERINFO = _descriptor.Descriptor( + name='HeaderInfo', + full_name='HeaderInfo', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='video', full_name='HeaderInfo.video', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=37, + serialized_end=72, +) + + +_HEADER = _descriptor.Descriptor( + name='Header', + full_name='Header', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='info', full_name='Header.info', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='terminator', full_name='Header.terminator', index=1, + number=4, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=74, + serialized_end=129, +) + +_HEADERINFO.fields_by_name['video'].message_type = _VIDEO +_HEADER.fields_by_name['info'].message_type = _HEADERINFO +DESCRIPTOR.message_types_by_name['Video'] = _VIDEO +DESCRIPTOR.message_types_by_name['HeaderInfo'] = _HEADERINFO +DESCRIPTOR.message_types_by_name['Header'] = _HEADER +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +Video = _reflection.GeneratedProtocolMessageType('Video', (_message.Message,), { + 'DESCRIPTOR' : _VIDEO, + '__module__' : 'header_pb2' + # @@protoc_insertion_point(class_scope:Video) + }) +_sym_db.RegisterMessage(Video) + +HeaderInfo = _reflection.GeneratedProtocolMessageType('HeaderInfo', (_message.Message,), { + 'DESCRIPTOR' : _HEADERINFO, + '__module__' : 'header_pb2' + # @@protoc_insertion_point(class_scope:HeaderInfo) + }) +_sym_db.RegisterMessage(HeaderInfo) + +Header = _reflection.GeneratedProtocolMessageType('Header', (_message.Message,), { + 'DESCRIPTOR' : _HEADER, + '__module__' : 'header_pb2' + # @@protoc_insertion_point(class_scope:Header) + }) +_sym_db.RegisterMessage(Header) + + +# @@protoc_insertion_point(module_scope) diff --git a/pytchat/paramgen/pb/live_pb2.py b/pytchat/paramgen/pb/live_pb2.py new file mode 100644 index 0000000..d580cdf --- /dev/null +++ b/pytchat/paramgen/pb/live_pb2.py @@ -0,0 +1,381 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: live.proto + +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='live.proto', + package='live', + syntax='proto3', + serialized_options=None, + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\nlive.proto\x12\x04live\"\x88\x01\n\x04\x42ody\x12\n\n\x02\x62\x31\x18\x01 \x01(\x05\x12\n\n\x02\x62\x32\x18\x02 \x01(\x05\x12\n\n\x02\x62\x33\x18\x03 \x01(\x05\x12\n\n\x02\x62\x34\x18\x04 \x01(\x05\x12\n\n\x02\x62\x37\x18\x07 \x01(\t\x12\n\n\x02\x62\x38\x18\x08 \x01(\x05\x12\n\n\x02\x62\x39\x18\t \x01(\t\x12\x12\n\ntimestamp2\x18\n \x01(\x03\x12\x0b\n\x03\x62\x31\x31\x18\x0b \x01(\x05\x12\x0b\n\x03\x62\x31\x35\x18\x0f \x01(\x05\"\x19\n\x08\x43hatType\x12\r\n\x05value\x18\x01 \x01(\x05\"\x16\n\x05STR19\x12\r\n\x05value\x18\x01 \x01(\x05\"\x8a\x02\n\x12\x43ontinuationEntity\x12\x0e\n\x06header\x18\x03 \x01(\t\x12\x12\n\ntimestamp1\x18\x05 \x01(\x03\x12\n\n\x02s6\x18\x06 \x01(\x05\x12\n\n\x02s7\x18\x07 \x01(\x05\x12\n\n\x02s8\x18\x08 \x01(\x05\x12\x18\n\x04\x62ody\x18\t \x01(\x0b\x32\n.live.Body\x12\x12\n\ntimestamp3\x18\n \x01(\x03\x12\x12\n\ntimestamp4\x18\x0b \x01(\x03\x12\x0b\n\x03s13\x18\r \x01(\x05\x12 \n\x08\x63hattype\x18\x10 \x01(\x0b\x32\x0e.live.ChatType\x12\x0b\n\x03s17\x18\x11 \x01(\x05\x12\x1a\n\x05str19\x18\x13 \x01(\x0b\x32\x0b.live.STR19\x12\x12\n\ntimestamp5\x18\x14 \x01(\x03\";\n\x0c\x43ontinuation\x12+\n\x06\x65ntity\x18\xfa\xc0\x89\x39 \x01(\x0b\x32\x18.live.ContinuationEntityb\x06proto3' +) + + + + +_BODY = _descriptor.Descriptor( + name='Body', + full_name='live.Body', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='b1', full_name='live.Body.b1', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b2', full_name='live.Body.b2', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b3', full_name='live.Body.b3', index=2, + number=3, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b4', full_name='live.Body.b4', index=3, + number=4, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b7', full_name='live.Body.b7', index=4, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b8', full_name='live.Body.b8', index=5, + number=8, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b9', full_name='live.Body.b9', index=6, + number=9, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp2', full_name='live.Body.timestamp2', index=7, + number=10, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b11', full_name='live.Body.b11', index=8, + number=11, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='b15', full_name='live.Body.b15', index=9, + number=15, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=21, + serialized_end=157, +) + + +_CHATTYPE = _descriptor.Descriptor( + name='ChatType', + full_name='live.ChatType', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='value', full_name='live.ChatType.value', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=159, + serialized_end=184, +) + + +_STR19 = _descriptor.Descriptor( + name='STR19', + full_name='live.STR19', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='value', full_name='live.STR19.value', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=186, + serialized_end=208, +) + + +_CONTINUATIONENTITY = _descriptor.Descriptor( + name='ContinuationEntity', + full_name='live.ContinuationEntity', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='header', full_name='live.ContinuationEntity.header', index=0, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp1', full_name='live.ContinuationEntity.timestamp1', index=1, + number=5, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s6', full_name='live.ContinuationEntity.s6', index=2, + number=6, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s7', full_name='live.ContinuationEntity.s7', index=3, + number=7, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s8', full_name='live.ContinuationEntity.s8', index=4, + number=8, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='body', full_name='live.ContinuationEntity.body', index=5, + number=9, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp3', full_name='live.ContinuationEntity.timestamp3', index=6, + number=10, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp4', full_name='live.ContinuationEntity.timestamp4', index=7, + number=11, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s13', full_name='live.ContinuationEntity.s13', index=8, + number=13, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='chattype', full_name='live.ContinuationEntity.chattype', index=9, + number=16, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s17', full_name='live.ContinuationEntity.s17', index=10, + number=17, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='str19', full_name='live.ContinuationEntity.str19', index=11, + number=19, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp5', full_name='live.ContinuationEntity.timestamp5', index=12, + number=20, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=211, + serialized_end=477, +) + + +_CONTINUATION = _descriptor.Descriptor( + name='Continuation', + full_name='live.Continuation', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='entity', full_name='live.Continuation.entity', index=0, + number=119693434, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=479, + serialized_end=538, +) + +_CONTINUATIONENTITY.fields_by_name['body'].message_type = _BODY +_CONTINUATIONENTITY.fields_by_name['chattype'].message_type = _CHATTYPE +_CONTINUATIONENTITY.fields_by_name['str19'].message_type = _STR19 +_CONTINUATION.fields_by_name['entity'].message_type = _CONTINUATIONENTITY +DESCRIPTOR.message_types_by_name['Body'] = _BODY +DESCRIPTOR.message_types_by_name['ChatType'] = _CHATTYPE +DESCRIPTOR.message_types_by_name['STR19'] = _STR19 +DESCRIPTOR.message_types_by_name['ContinuationEntity'] = _CONTINUATIONENTITY +DESCRIPTOR.message_types_by_name['Continuation'] = _CONTINUATION +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +Body = _reflection.GeneratedProtocolMessageType('Body', (_message.Message,), { + 'DESCRIPTOR' : _BODY, + '__module__' : 'live_pb2' + # @@protoc_insertion_point(class_scope:live.Body) + }) +_sym_db.RegisterMessage(Body) + +ChatType = _reflection.GeneratedProtocolMessageType('ChatType', (_message.Message,), { + 'DESCRIPTOR' : _CHATTYPE, + '__module__' : 'live_pb2' + # @@protoc_insertion_point(class_scope:live.ChatType) + }) +_sym_db.RegisterMessage(ChatType) + +STR19 = _reflection.GeneratedProtocolMessageType('STR19', (_message.Message,), { + 'DESCRIPTOR' : _STR19, + '__module__' : 'live_pb2' + # @@protoc_insertion_point(class_scope:live.STR19) + }) +_sym_db.RegisterMessage(STR19) + +ContinuationEntity = _reflection.GeneratedProtocolMessageType('ContinuationEntity', (_message.Message,), { + 'DESCRIPTOR' : _CONTINUATIONENTITY, + '__module__' : 'live_pb2' + # @@protoc_insertion_point(class_scope:live.ContinuationEntity) + }) +_sym_db.RegisterMessage(ContinuationEntity) + +Continuation = _reflection.GeneratedProtocolMessageType('Continuation', (_message.Message,), { + 'DESCRIPTOR' : _CONTINUATION, + '__module__' : 'live_pb2' + # @@protoc_insertion_point(class_scope:live.Continuation) + }) +_sym_db.RegisterMessage(Continuation) + + +# @@protoc_insertion_point(module_scope) diff --git a/pytchat/paramgen/pb/replay_pb2.py b/pytchat/paramgen/pb/replay_pb2.py new file mode 100644 index 0000000..4a85aa3 --- /dev/null +++ b/pytchat/paramgen/pb/replay_pb2.py @@ -0,0 +1,215 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: replay.proto + +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='replay.proto', + package='replay', + syntax='proto3', + serialized_options=None, + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\x0creplay.proto\x12\x06replay\"\x19\n\x08\x43hatType\x12\r\n\x05value\x18\x01 \x01(\x05\"\xb2\x01\n\x12\x43ontinuationEntity\x12\x0e\n\x06header\x18\x03 \x01(\t\x12\x11\n\ttimestamp\x18\x05 \x01(\x03\x12\n\n\x02s6\x18\x06 \x01(\x05\x12\n\n\x02s7\x18\x07 \x01(\x05\x12\n\n\x02s8\x18\x08 \x01(\x05\x12\n\n\x02s9\x18\t \x01(\x05\x12\x0b\n\x03s10\x18\n \x01(\t\x12\x0b\n\x03s12\x18\x0c \x01(\x05\x12\"\n\x08\x63hattype\x18\x0e \x01(\x0b\x32\x10.replay.ChatType\x12\x0b\n\x03s15\x18\x0f \x01(\x05\"=\n\x0c\x43ontinuation\x12-\n\x06\x65ntity\x18\xd4\x83\xb6J \x01(\x0b\x32\x1a.replay.ContinuationEntityb\x06proto3' +) + + + + +_CHATTYPE = _descriptor.Descriptor( + name='ChatType', + full_name='replay.ChatType', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='value', full_name='replay.ChatType.value', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=24, + serialized_end=49, +) + + +_CONTINUATIONENTITY = _descriptor.Descriptor( + name='ContinuationEntity', + full_name='replay.ContinuationEntity', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='header', full_name='replay.ContinuationEntity.header', index=0, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp', full_name='replay.ContinuationEntity.timestamp', index=1, + number=5, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s6', full_name='replay.ContinuationEntity.s6', index=2, + number=6, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s7', full_name='replay.ContinuationEntity.s7', index=3, + number=7, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s8', full_name='replay.ContinuationEntity.s8', index=4, + number=8, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s9', full_name='replay.ContinuationEntity.s9', index=5, + number=9, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s10', full_name='replay.ContinuationEntity.s10', index=6, + number=10, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s12', full_name='replay.ContinuationEntity.s12', index=7, + number=12, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='chattype', full_name='replay.ContinuationEntity.chattype', index=8, + number=14, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='s15', full_name='replay.ContinuationEntity.s15', index=9, + number=15, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=52, + serialized_end=230, +) + + +_CONTINUATION = _descriptor.Descriptor( + name='Continuation', + full_name='replay.Continuation', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='entity', full_name='replay.Continuation.entity', index=0, + number=156074452, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=232, + serialized_end=293, +) + +_CONTINUATIONENTITY.fields_by_name['chattype'].message_type = _CHATTYPE +_CONTINUATION.fields_by_name['entity'].message_type = _CONTINUATIONENTITY +DESCRIPTOR.message_types_by_name['ChatType'] = _CHATTYPE +DESCRIPTOR.message_types_by_name['ContinuationEntity'] = _CONTINUATIONENTITY +DESCRIPTOR.message_types_by_name['Continuation'] = _CONTINUATION +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +ChatType = _reflection.GeneratedProtocolMessageType('ChatType', (_message.Message,), { + 'DESCRIPTOR' : _CHATTYPE, + '__module__' : 'replay_pb2' + # @@protoc_insertion_point(class_scope:replay.ChatType) + }) +_sym_db.RegisterMessage(ChatType) + +ContinuationEntity = _reflection.GeneratedProtocolMessageType('ContinuationEntity', (_message.Message,), { + 'DESCRIPTOR' : _CONTINUATIONENTITY, + '__module__' : 'replay_pb2' + # @@protoc_insertion_point(class_scope:replay.ContinuationEntity) + }) +_sym_db.RegisterMessage(ContinuationEntity) + +Continuation = _reflection.GeneratedProtocolMessageType('Continuation', (_message.Message,), { + 'DESCRIPTOR' : _CONTINUATION, + '__module__' : 'replay_pb2' + # @@protoc_insertion_point(class_scope:replay.Continuation) + }) +_sym_db.RegisterMessage(Continuation) + + +# @@protoc_insertion_point(module_scope) diff --git a/pytchat/paramgen/proto/header.proto b/pytchat/paramgen/proto/header.proto new file mode 100644 index 0000000..54c6176 --- /dev/null +++ b/pytchat/paramgen/proto/header.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +message Video { + string id = 1; +} + +message HeaderInfo { + Video video = 1; +} + +message Header { + HeaderInfo info = 1; + int32 terminator = 4; +} diff --git a/pytchat/paramgen/proto/live.proto b/pytchat/paramgen/proto/live.proto new file mode 100644 index 0000000..783753c --- /dev/null +++ b/pytchat/paramgen/proto/live.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; + +package live; + +message Body { + int32 b1 = 1; + int32 b2 = 2; + int32 b3 = 3; + int32 b4 = 4; + string b7 = 7; + int32 b8 = 8; + string b9 = 9; + int64 timestamp2 = 10; + int32 b11 = 11; + int32 b15 = 15; +} + +message ChatType { + int32 value = 1; +} + +message STR19 { + int32 value = 1; +} + +message ContinuationEntity { + string header = 3; + int64 timestamp1 = 5; + int32 s6 = 6; + int32 s7 = 7; + int32 s8 = 8; + Body body = 9; + int64 timestamp3 = 10; + int64 timestamp4 = 11; + int32 s13 = 13; + ChatType chattype = 16; + int32 s17 = 17; + STR19 str19 = 19; + int64 timestamp5 = 20; +} + +message Continuation { + ContinuationEntity entity = 119693434; +} + diff --git a/pytchat/paramgen/proto/replay.proto b/pytchat/paramgen/proto/replay.proto new file mode 100644 index 0000000..b86a21c --- /dev/null +++ b/pytchat/paramgen/proto/replay.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package replay; + +message ChatType { + int32 value = 1; +} + +message ContinuationEntity { + string header = 3; + int64 timestamp = 5; + int32 s6 = 6; + int32 s7 = 7; + int32 s8 = 8; + int32 s9 = 9; + string s10 = 10; + int32 s12 = 12; + ChatType chattype = 14; + int32 s15 = 15; +} + +message Continuation { + ContinuationEntity entity = 156074452; +} diff --git a/pytchat/parser/live.py b/pytchat/parser/live.py index a37bbaa..aa30562 100644 --- a/pytchat/parser/live.py +++ b/pytchat/parser/live.py @@ -4,27 +4,26 @@ pytchat.parser.live Parser of live chat JSON. """ -import json -from .. exceptions import ( - ResponseContextError, - NoContentsException, +from .. exceptions import ( + ResponseContextError, + NoContentsException, NoContinuationsException, - ChatParseException ) + ChatParseException) + class Parser: __slots__ = ['is_replay'] - - def __init__(self, is_replay): + + def __init__(self, is_replay): self.is_replay = is_replay def get_contents(self, jsn): - if jsn is None: + if jsn is None: raise ChatParseException('Called with none JSON object.') if jsn['response']['responseContext'].get('errors'): - raise ResponseContextError('The video_id would be wrong,' - 'or video is deleted or private.') - contents=jsn['response'].get('continuationContents') + raise ResponseContextError('The video_id would be wrong, or video is deleted or private.') + contents = jsn['response'].get('continuationContents') return contents def parse(self, contents): @@ -40,7 +39,7 @@ class Parser: + metadata : dict + timeout + video_id - + continuation + + continuation + chatdata : List[dict] """ @@ -51,9 +50,9 @@ class Parser: cont = contents['liveChatContinuation']['continuations'][0] if cont is None: raise NoContinuationsException('No Continuation') - metadata = (cont.get('invalidationContinuationData') or - cont.get('timedContinuationData') or - cont.get('reloadContinuationData') or + metadata = (cont.get('invalidationContinuationData') or + cont.get('timedContinuationData') or + cont.get('reloadContinuationData') or cont.get('liveChatReplayContinuationData') ) if metadata is None: @@ -68,30 +67,30 @@ class Parser: 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. + 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. + # chat data exist. return None - #chat data do not exist, get playerSeekContinuationData. + # 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') - if self.is_replay: + if self.is_replay: interval = self._get_interval(actions) - metadata.setdefault("timeoutMs",interval) - """Archived chat has different structures than live chat, + metadata.setdefault("timeoutMs", interval) + """Archived chat has different structures than live chat, so make it the same format.""" chatdata = [action["replayChatItemAction"]["actions"][0] - for action in actions] + for action in actions] else: metadata.setdefault('timeoutMs', 10000) chatdata = actions @@ -102,4 +101,4 @@ class Parser: return 0 start = int(actions[0]["replayChatItemAction"]["videoOffsetTimeMsec"]) last = int(actions[-1]["replayChatItemAction"]["videoOffsetTimeMsec"]) - return (last - start) \ No newline at end of file + return (last - start) diff --git a/pytchat/parser/replay.py b/pytchat/parser/replay.py deleted file mode 100644 index 7399238..0000000 --- a/pytchat/parser/replay.py +++ /dev/null @@ -1,76 +0,0 @@ -import json -from .. import config -from .. exceptions import ( - ResponseContextError, - NoContentsException, - NoContinuationsException ) - - -logger = config.logger(__name__) - -class Parser: - def parse(self, jsn): - """ - このparse関数はReplayChat._listen() 関数から定期的に呼び出される。 - 引数jsnはYoutubeから取得したアーカイブ済みチャットデータの生JSONであり、 - このparse関数によって与えられたJSONを以下に分割して返す。 - + timeout (次のチャットデータ取得までのインターバル) - + chat data(チャットデータ本体) - + continuation (次のチャットデータ取得に必要となるパラメータ). - - ライブ配信のチャットとアーカイブ済み動画のチャットは構造が若干異なっているが、 - ライブチャットと同じデータ形式に変換することにより、 - 同じprocessorでライブとリプレイどちらでも利用できるようにしている。 - - Parameter - ---------- - + jsn : dict - + Youtubeから取得したチャットデータのJSONオブジェクト。 - (pythonの辞書形式に変換済みの状態で渡される) - - Returns - ------- - + metadata : dict - + チャットデータに付随するメタデータ。timeout、 動画ID、continuationパラメータで構成される。 - + chatdata : list[dict] - + チャットデータ本体のリスト。 - """ - if jsn is None: - return {'timeoutMs':0,'continuation':None},[] - if jsn['response']['responseContext'].get('errors'): - raise ResponseContextError('動画に接続できません。' - '動画IDが間違っているか、動画が削除/非公開の可能性があります。') - contents=jsn['response'].get('continuationContents') - #配信が終了した場合、もしくはチャットデータが取得できない場合 - if contents is None: - raise NoContentsException('チャットデータを取得できませんでした。') - - cont = contents['liveChatContinuation']['continuations'][0] - if cont is None: - raise NoContinuationsException('Continuationがありません。') - metadata = cont.get('liveChatReplayContinuationData') - if metadata is None: - unknown = list(cont.keys())[0] - if unknown != "playerSeekContinuationData": - logger.debug(f"Received unknown continuation type:{unknown}") - metadata = cont.get(unknown) - actions = contents['liveChatContinuation'].get('actions') - if actions is None: - #後続のチャットデータなし - return {"continuation":None,"timeout":0,"chatdata":[]} - interval = self.get_interval(actions) - metadata.setdefault("timeoutMs",interval) - """アーカイブ済みチャットはライブチャットと構造が異なっているため、以下の行により - ライブチャットと同じ形式にそろえる""" - chatdata = [action["replayChatItemAction"]["actions"][0] for action in actions] - return metadata, chatdata - - def get_interval(self, actions: list): - if actions is None: - return 0 - start = int(actions[0]["replayChatItemAction"]["videoOffsetTimeMsec"]) - last = int(actions[-1]["replayChatItemAction"]["videoOffsetTimeMsec"]) - return (last - start) - - - diff --git a/requirements.txt b/requirements.txt index ea514b1..c76d992 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ aiohttp +protobuf pytz requests urllib3 \ No newline at end of file diff --git a/tests/test_arcparam.py b/tests/test_arcparam.py index 82f3588..bd0a90f 100644 --- a/tests/test_arcparam.py +++ b/tests/test_arcparam.py @@ -1,28 +1,31 @@ -import pytest -from pytchat.parser.live import Parser +import json +import requests import pytchat.config as config -import requests, json from pytchat.paramgen import arcparam +from pytchat.parser.live import Parser + def test_arcparam_0(mocker): - param = arcparam.getparam("01234567890",-1) - assert param == "op2w0wRyGjxDZzhhRFFvTE1ERXlNelExTmpjNE9UQWFFLXFvM2JrQkRRb0xNREV5TXpRMU5qYzRPVEFnQVElM0QlM0QoADAAOABAAEgEUhwIABAAGAAgACoOc3RhdGljY2hlY2tzdW1AAFgDYAFoAHIECAEQAHgA" + param = arcparam.getparam("01234567890", -1) + assert param == "op2w0wQmGhxDZzhLRFFvTE1ERXlNelExTmpjNE9UQWdBUT09SARgAXICCAE%3D" + def test_arcparam_1(mocker): - param = arcparam.getparam("01234567890", seektime = 100000) - assert param == "op2w0wR3GjxDZzhhRFFvTE1ERXlNelExTmpjNE9UQWFFLXFvM2JrQkRRb0xNREV5TXpRMU5qYzRPVEFnQVElM0QlM0QogNDbw_QCMAA4AEAASANSHAgAEAAYACAAKg5zdGF0aWNjaGVja3N1bUAAWANgAWgAcgQIARAAeAA%3D" + param = arcparam.getparam("01234567890", seektime=100000) + assert param == "op2w0wQtGhxDZzhLRFFvTE1ERXlNelExTmpjNE9UQWdBUT09KIDQ28P0AkgDYAFyAggB" + def test_arcparam_2(mocker): - param = arcparam.getparam("SsjCnHOk-Sk") - url=f"https://www.youtube.com/live_chat_replay/get_live_chat_replay?continuation={param}&pbj=1" - resp = requests.Session().get(url,headers = config.headers) + param = arcparam.getparam("SsjCnHOk-Sk", seektime=100) + url = f"https://www.youtube.com/live_chat_replay/get_live_chat_replay?continuation={param}&pbj=1" + resp = requests.Session().get(url, headers=config.headers) jsn = json.loads(resp.text) parser = Parser(is_replay=True) - contents= parser.get_contents(jsn) + contents = parser.get_contents(jsn) _ , chatdata = parser.parse(contents) test_id = chatdata[0]["addChatItemAction"]["item"]["liveChatTextMessageRenderer"]["id"] assert test_id == "CjoKGkNMYXBzZTdudHVVQ0Zjc0IxZ0FkTnFnQjVREhxDSnlBNHV2bnR1VUNGV0dnd2dvZDd3NE5aZy0w" def test_arcparam_3(mocker): param = arcparam.getparam("01234567890") - assert param == "op2w0wRyGjxDZzhhRFFvTE1ERXlNelExTmpjNE9UQWFFLXFvM2JrQkRRb0xNREV5TXpRMU5qYzRPVEFnQVElM0QlM0QoATAAOABAAEgDUhwIABAAGAAgACoOc3RhdGljY2hlY2tzdW1AAFgDYAFoAHIECAEQAHgA" + assert param == "op2w0wQmGhxDZzhLRFFvTE1ERXlNelExTmpjNE9UQWdBUT09SARgAXICCAE%3D" diff --git a/tests/test_liveparam.py b/tests/test_liveparam.py index 0260fa2..e40a29b 100644 --- a/tests/test_liveparam.py +++ b/tests/test_liveparam.py @@ -5,5 +5,5 @@ def test_liveparam_0(mocker): _ts1= 1546268400 param = liveparam._build("01234567890", *([_ts1*1000000 for i in range(5)]), topchat_only=False) - test_param="0ofMyAPiARp8Q2c4S0RRb0xNREV5TXpRMU5qYzRPVEFhUTZxNXdiMEJQUW83YUhSMGNITTZMeTkzZDNjdWVXOTFkSFZpWlM1amIyMHZiR2wyWlY5amFHRjBQM1k5TURFeU16UTFOamM0T1RBbWFYTmZjRzl3YjNWMFBURWdBZyUzRCUzRCiAuNbVqsrfAjAAOABAAkorCAEQABgAIAAqDnN0YXRpY2NoZWNrc3VtOgBAAEoCCAFQgLjW1arK3wJYA1CAuNbVqsrfAliAuNbVqsrfAmgBggEECAEQAIgBAKABgLjW1arK3wI%3D" + test_param="0ofMyANcGhxDZzhLRFFvTE1ERXlNelExTmpjNE9UQWdBUT09KIC41tWqyt8CQAFKC1CAuNbVqsrfAlgDUIC41tWqyt8CWIC41tWqyt8CaAGCAQIIAZoBAKABgLjW1arK3wI%3D" assert test_param == param \ No newline at end of file