youtubechat

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 13 Imported by: 0

README

Go YouTube Chat

Biblioteca não-oficial em Go para conectar ao chat de Lives do YouTube em tempo real usando a API Innertube.

Status do Monitor Go Reference

Instalação

go get github.com/NPChat/go-youtube-chat

Como Usar

package main

import (
	"context"
	"fmt"
	"github.com/NPChat/go-youtube-chat"
)

func main() {
	// 1. Cria o cliente (Pode passar com ou sem o '@')
	client := youtubechat.New("cazetv")

	// 2. Define o callback de mensagens
	client.OnMessage = func(msg youtubechat.Message) {
		if msg.IsPaid {
			fmt.Printf("[SUPERCHAT - %s] %s: %s\n", msg.Amount, msg.Author, msg.Content)
		} else {
			fmt.Printf("[%s] %s: %s\n", msg.Channel, msg.Author, msg.Content)
		}
	}

	client.OnError = func(err error) {
		fmt.Printf("Erro: %v\n", err)
	}

	// 3. Conecta (Bloqueante)
	fmt.Println("Conectando ao chat...")
	if err := client.Connect(context.Background()); err != nil {
		panic(err)
	}
}

Monitoramento e Manutenção

Se o badge no topo estiver Verde, a lib está funcionando. Se estiver Vermelho, já fomos notificados e estamos arrumando.

Documentation

Overview

Package youtubechat implementa um cliente resiliente e não-oficial para a plataforma de streaming YouTube Live.

O foco principal desta biblioteca é estabilidade e facilidade de uso, contendo mecanismos internos de Polling através da API Innertube e evasão de bloqueios através de mimetismo de User-Agent e gerenciamento de Tokens de Continuação.

Uso Básico

O ponto de entrada principal é a função New(), que cria um cliente configurado para um canal específico (com ou sem o @).

client := youtubechat.New("cazetv")
client.OnMessage = func(msg youtubechat.Message) {
    fmt.Printf("%s disse: %s (SuperChat: %v)", msg.Author, msg.Content, msg.IsPaid)
}
client.Connect(context.Background())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	OnMessage func(msg Message)
	OnError   func(err error)
	// contains filtered or unexported fields
}

func New

func New(channel string) *Client

New inicializa o cliente e higieniza a entrada

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect inicia o bloqueio de polling sincronizado com o Context

type Message

type Message struct {
	ID        string    `json:"id"`
	Content   string    `json:"content"`
	Channel   string    `json:"channel"` // Ex: "cazetv" (sem o @)
	Author    string    `json:"author"`
	Timestamp time.Time `json:"timestamp"`

	// Campos exclusivos do YouTube
	IsPaid bool   `json:"is_paid"`          // True para SuperChats e Memberships
	Amount string `json:"amount,omitempty"` // Ex: "R$ 5,00"
}

Message representa uma mensagem padronizada e limpa do chat.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL