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

ChatProcessorのカスタマイズ

taizan-hokuto edited this page Nov 3, 2019 · 19 revisions

pytchatはバックグラウンドでYoutubeから一定間隔でライブチャットデータを取得し、Bufferに一時的に貯めます。
動作モードによりタイミングや経路は異なりますが、いずれもChatProcessorはLiveChatオブジェクトから
定型的なデータ(chat_components:後述)を受け取り、任意の形に加工したデータを返す、という点を押さえておけばokです。

参考:pytchatの動作モード

ChatProcessorは任意に拡張し、コンストラクタのprocessorパラメータで指定することができます。

自作のChatProcessorは、chat_componentsを引数にとるprocessというインターフェースを持たなければなりません。

from .processors.chat_processor import ChatProcessor
class MyProcessor(ChatProcessor):
    def process(self, chat_components):
        #...process chatdata...

chat_components は、video_id、timeout、chatdataをキーに持つ辞書(component)のリストです。

chat_components:[LIST:component]

component = {
    "video_id" : "xxxxxxxxxxx",  #動画ID
    "timeout"  : 7.5231,              #チャットデータのタイムアウト時間
    "chatdata" : {"addChatItemAction":{"item":{"liveChatTextMessageRenderer":[......}}} #Youtubeから取得したチャットデータ
}

Clone this wiki locally