chatlog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 7 Imported by: 1

README

chatlog

build status

YouTube Live archive chats fecher. Premiered videos are also supported.

Installation

$ go get github.com/dqn/chatlog

Usage

package main

import (
  "fmt"

  "github.com/dqn/chatlog"
)

func main() {
  c := chatlog.New("VIDEO_ID")

  err := c.HandleChat(func(renderer ChatRenderer) error {
    switch renderer.(type) {
    case *LiveChatViewerEngagementMessageRenderer:
      fmt.Println(renderer.ChatMessage())
      // e.g. "[Live chat replay is on. Messages that appeared when the stream was live will show up here.]"
      return nil

    case *LiveChatTextMessageRenderer:
      fmt.Println(renderer.ChatMessage())
      // e.g. "Alice: hello!"
      return nil

    case *LiveChatMembershipItemRenderer:
      fmt.Println(renderer.ChatMessage())
      // e.g. "[Welcome to Membership!] Bob"
      return nil

    case *LiveChatPaidMessageRenderer:
      fmt.Println(renderer.ChatMessage())
      // e.g. "[$10.00] Carol: bye!"
      return nil

    case *LiveChatPlaceholderItemRenderer:
      fmt.Println(renderer.ChatMessage())
      // (empty)
      return nil
    }
  })

  if err != nil {
    // Handle error.
  }
}

Also can custom message.

var buf bytes.Buffer

buf.WriteString(renderer.AuthorName.SimpleText + "> ")

for _, run := range renderer.Message.Runs {
  if run.Text != "" {
    buf.WriteString(run.Text)
  } else {
    buf.WriteString(run.Emoji.Image.Accessibility.AccessibilityData.Label)
  }
}

fmt.Println(buf.String())

Other

ChatRenderer is actual YouTube private API response structure. See payloads for more details.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessibility

type Accessibility struct {
	AccessibilityData AccessibilityData `json:"accessibilityData"`
}

type AccessibilityData

type AccessibilityData struct {
	Label string `json:"label"`
}

type AddChatItemAction

type AddChatItemAction struct {
	Item     ChatItem `json:"item"`
	ClientID string   `json:"clientId"`
}

type AddLiveChatTickerItemAction

type AddLiveChatTickerItemAction struct {
	Item        LiveChatTickerItem `json:"item"`
	DurationSec string             `json:"durationSec"`
}

type Amount

type Amount struct {
	SimpleText string `json:"simpleText"`
}

type AuthorBadge

type AuthorBadge struct {
	LiveChatAuthorBadgeRenderer LiveChatAuthorBadgeRenderer `json:"liveChatAuthorBadgeRenderer"`
}

type AuthorName

type AuthorName struct {
	SimpleText string `json:"simpleText"`
}

type AuthorPhoto

type AuthorPhoto struct {
	Thumbnails []Thumbnail `json:"thumbnails"`
}

type ChatAction

type ChatAction struct {
	AddChatItemAction           AddChatItemAction           `json:"addChatItemAction"`
	AddLiveChatTickerItemAction AddLiveChatTickerItemAction `json:"addLiveChatTickerItemAction"`
}

type ChatItem

type ChatItem struct {
	LiveChatViewerEngagementMessageRenderer LiveChatViewerEngagementMessageRenderer `json:"liveChatViewerEngagementMessageRenderer"`
	LiveChatTextMessageRenderer             LiveChatTextMessageRenderer             `json:"liveChatTextMessageRenderer"`
	LiveChatMembershipItemRenderer          LiveChatMembershipItemRenderer          `json:"liveChatMembershipItemRenderer"`
	LiveChatPaidMessageRenderer             LiveChatPaidMessageRenderer             `json:"liveChatPaidMessageRenderer"`
	LiveChatPlaceholderItemRenderer         LiveChatPlaceholderItemRenderer         `json:"liveChatPlaceholderItemRenderer"`
}

type ChatRenderer added in v1.1.0

type ChatRenderer interface {
	ChatMessage() string
}

type ChatResponse

type ChatResponse struct {
	Response Response `json:"response"`
}

type Chatlog

type Chatlog struct {
	// contains filtered or unexported fields
}

func New

func New(videoID string) *Chatlog

func (*Chatlog) HandleChat added in v1.1.0

func (c *Chatlog) HandleChat(handler func(renderer ChatRenderer) error) error

type CommandMetadata

type CommandMetadata struct {
	WebCommandMetadata WebCommandMetadata `json:"webCommandMetadata"`
}

type ContextMenuEndpoint

type ContextMenuEndpoint struct {
	ClickTrackingParams             string                          `json:"clickTrackingParams"`
	CommandMetadata                 CommandMetadata                 `json:"commandMetadata"`
	LiveChatItemContextMenuEndpoint LiveChatItemContextMenuEndpoint `json:"liveChatItemContextMenuEndpoint"`
}

type Continuation

type Continuation struct {
	LiveChatReplayContinuationData LiveChatReplayContinuationData `json:"liveChatReplayContinuationData"`
	PlayerSeekContinuationData     PlayerSeekContinuationData     `json:"playerSeekContinuationData"`
}

type ContinuationAction

type ContinuationAction struct {
	ReplayChatItemAction ReplayChatItemAction `json:"replayChatItemAction"`
}

type ContinuationContents

type ContinuationContents struct {
	LiveChatContinuation LiveChatContinuation `json:"liveChatContinuation"`
}

type CustomThumbnail

type CustomThumbnail struct {
	Thumbnails []Thumbnail `json:"thumbnails"`
}

type DetailText

type DetailText struct {
	Runs []Run `json:"runs"`
}

type Emoji

type Emoji struct {
	EmojiID       string   `json:"emojiId"`
	Shortcuts     []string `json:"shortcuts"`
	SearchTerms   []string `json:"searchTerms"`
	Image         Image    `json:"image"`
	IsCustomEmoji bool     `json:"isCustomEmoji"`
}

type Error

type Error struct {
	Domain               string `json:"domain"`
	Code                 string `json:"code"`
	DebugInfo            string `json:"debugInfo"`
	ExternalErrorMessage string `json:"externalErrorMessage"`
}

type HeaderSubtext

type HeaderSubtext struct {
	Runs []Run `json:"runs"`
}

type Icon

type Icon struct {
	IconType string `json:"iconType"`
}

type Image

type Image struct {
	Thumbnails    []Thumbnail   `json:"thumbnails"`
	Accessibility Accessibility `json:"accessibility"`
}

type LiveChatAuthorBadgeRenderer

type LiveChatAuthorBadgeRenderer struct {
	Icon            Icon            `json:"icon"`
	CustomThumbnail CustomThumbnail `json:"customThumbnail"`
	Tooltip         string          `json:"tooltip"`
	Accessibility   Accessibility   `json:"accessibility"`
}

type LiveChatContinuation

type LiveChatContinuation struct {
	Continuations []Continuation       `json:"continuations"`
	Actions       []ContinuationAction `json:"actions"`
}

type LiveChatItemContextMenuEndpoint

type LiveChatItemContextMenuEndpoint struct {
	Params string `json:"params"`
}

type LiveChatMembershipItemRenderer

type LiveChatMembershipItemRenderer struct {
	ID                       string              `json:"id"`
	TimestampUsec            string              `json:"timestampUsec"`
	AuthorExternalChannelID  string              `json:"authorExternalChannelId"`
	HeaderSubtext            HeaderSubtext       `json:"headerSubtext"`
	AuthorName               AuthorName          `json:"authorName"`
	AuthorPhoto              AuthorPhoto         `json:"authorPhoto"`
	AuthorBadges             []AuthorBadge       `json:"authorBadges"`
	ContextMenuEndpoint      ContextMenuEndpoint `json:"contextMenuEndpoint"`
	ContextMenuAccessibility Accessibility       `json:"contextMenuAccessibility"`
}

func (*LiveChatMembershipItemRenderer) ChatMessage added in v1.1.0

func (r *LiveChatMembershipItemRenderer) ChatMessage() string

type LiveChatPaidMessageRenderer

type LiveChatPaidMessageRenderer struct {
	ID                       string              `json:"id"`
	TimestampUsec            string              `json:"timestampUsec"`
	AuthorName               AuthorName          `json:"authorName"`
	AuthorPhoto              AuthorPhoto         `json:"authorPhoto"`
	PurchaseAmountText       PurchaseAmountText  `json:"purchaseAmountText"`
	Message                  Message             `json:"message"`
	HeaderBackgroundColor    int                 `json:"headerBackgroundColor"`
	HeaderTextColor          int                 `json:"headerTextColor"`
	BodyBackgroundColor      int                 `json:"bodyBackgroundColor"`
	BodyTextColor            int                 `json:"bodyTextColor"`
	AuthorExternalChannelID  string              `json:"authorExternalChannelId"`
	AuthorNameTextColor      int                 `json:"authorNameTextColor"`
	ContextMenuEndpoint      ContextMenuEndpoint `json:"contextMenuEndpoint"`
	TimestampColor           int                 `json:"timestampColor"`
	ContextMenuAccessibility Accessibility       `json:"contextMenuAccessibility"`
	TimestampText            TimestampText       `json:"timestampText"`
	TrackingParams           string              `json:"trackingParams"`
}

func (*LiveChatPaidMessageRenderer) ChatMessage added in v1.1.0

func (r *LiveChatPaidMessageRenderer) ChatMessage() string

type LiveChatPlaceholderItemRenderer

type LiveChatPlaceholderItemRenderer struct {
	ID            string `json:"id"`
	TimestampUsec string `json:"timestampUsec"`
}

func (*LiveChatPlaceholderItemRenderer) ChatMessage added in v1.1.0

func (r *LiveChatPlaceholderItemRenderer) ChatMessage() string

type LiveChatReplayContinuationData

type LiveChatReplayContinuationData struct {
	TimeUntilLastMessageMsec int    `json:"timeUntilLastMessageMsec"`
	Continuation             string `json:"continuation"`
}

type LiveChatTextMessageRenderer

type LiveChatTextMessageRenderer struct {
	ID                       string              `json:"id"`
	TimestampUsec            string              `json:"timestampUsec"`
	Message                  Message             `json:"message"`
	AuthorName               AuthorName          `json:"authorName"`
	AuthorPhoto              AuthorPhoto         `json:"authorPhoto"`
	Icon                     Icon                `json:"icon"`
	ContextMenuEndpoint      ContextMenuEndpoint `json:"contextMenuEndpoint"`
	AuthorBadges             []AuthorBadge       `json:"authorBadges"`
	AuthorExternalChannelID  string              `json:"authorExternalChannelId"`
	ContextMenuAccessibility Accessibility       `json:"contextMenuAccessibility"`
	TimestampText            TimestampText       `json:"timestampText"`
}

func (*LiveChatTextMessageRenderer) ChatMessage added in v1.1.0

func (r *LiveChatTextMessageRenderer) ChatMessage() string

type LiveChatTickerItem

type LiveChatTickerItem struct {
	LiveChatTickerPaidMessageItemRenderer LiveChatTickerPaidMessageItemRenderer `json:"liveChatTickerPaidMessageItemRenderer"`
	LiveChatTickerSponsorItemRenderer     LiveChatTickerSponsorItemRenderer     `json:"liveChatTickerSponsorItemRenderer"`
	DurationSec                           string                                `json:"durationSec"`
}

type LiveChatTickerPaidMessageItemRenderer

type LiveChatTickerPaidMessageItemRenderer struct {
	ID                      string           `json:"id"`
	Amount                  Amount           `json:"amount"`
	AmountTextColor         int              `json:"amountTextColor"`
	StartBackgroundColor    int              `json:"startBackgroundColor"`
	EndBackgroundColor      int              `json:"endBackgroundColor"`
	AuthorPhoto             AuthorPhoto      `json:"authorPhoto"`
	DurationSec             int              `json:"durationSec"`
	ShowItemEndpoint        ShowItemEndpoint `json:"showItemEndpoint"`
	AuthorExternalChannelID string           `json:"authorExternalChannelId"`
	FullDurationSec         int              `json:"fullDurationSec"`
	TrackingParams          string           `json:"trackingParams"`
}

type LiveChatTickerSponsorItemRenderer

type LiveChatTickerSponsorItemRenderer struct {
	ID                      string           `json:"id"`
	DetailText              DetailText       `json:"detailText"`
	DetailTextColor         int              `json:"detailTextColor"`
	StartBackgroundColor    int              `json:"startBackgroundColor"`
	EndBackgroundColor      int              `json:"endBackgroundColor"`
	SponsorPhoto            SponsorPhoto     `json:"sponsorPhoto"`
	DurationSec             int              `json:"durationSec"`
	ShowItemEndpoint        ShowItemEndpoint `json:"showItemEndpoint"`
	AuthorExternalChannelID string           `json:"authorExternalChannelId"`
	FullDurationSec         int              `json:"fullDurationSec"`
}

type LiveChatViewerEngagementMessageRenderer

type LiveChatViewerEngagementMessageRenderer struct {
	ID            string  `json:"id"`
	TimestampUsec string  `json:"timestampUsec"`
	Icon          Icon    `json:"icon"`
	Message       Message `json:"message"`
}

func (*LiveChatViewerEngagementMessageRenderer) ChatMessage added in v1.1.0

type Message

type Message struct {
	Runs []Run `json:"runs"`
}

type PlayerSeekContinuationData

type PlayerSeekContinuationData struct {
	Continuation string `json:"continuation"`
}

type PurchaseAmountText

type PurchaseAmountText struct {
	SimpleText string `json:"simpleText"`
}

type Renderer

type Renderer struct {
	LiveChatPaidMessageRenderer    LiveChatPaidMessageRenderer    `json:"liveChatPaidMessageRenderer"`
	LiveChatMembershipItemRenderer LiveChatMembershipItemRenderer `json:"liveChatMembershipItemRenderer"`
}

type ReplayChatItemAction

type ReplayChatItemAction struct {
	Actions             []ChatAction `json:"actions"`
	VideoOffsetTimeMsec string       `json:"videoOffsetTimeMsec"`
}

type Response

type Response struct {
	ResponseContext      ResponseContext      `json:"responseContext"`
	ContinuationContents ContinuationContents `json:"continuationContents"`
}

type ResponseContext

type ResponseContext struct {
	Errors struct{ Error []Error } `json:"errors"`
}

type Run

type Run struct {
	Text  string `json:"text"`
	Emoji Emoji  `json:"emoji"`
}

type ShowItemEndpoint

type ShowItemEndpoint struct {
	ClickTrackingParams      string                   `json:"clickTrackingParams"`
	CommandMetadata          CommandMetadata          `json:"commandMetadata"`
	ShowLiveChatItemEndpoint ShowLiveChatItemEndpoint `json:"showLiveChatItemEndpoint"`
}

type ShowLiveChatItemEndpoint

type ShowLiveChatItemEndpoint struct {
	Renderer Renderer `json:"renderer"`
}

type SponsorPhoto

type SponsorPhoto struct {
	Thumbnails []Thumbnail `json:"thumbnails"`
}

type Thumbnail

type Thumbnail struct {
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type TimestampText

type TimestampText struct {
	SimpleText string `json:"simpleText"`
}

type WebCommandMetadata

type WebCommandMetadata struct {
	IgnoreNavigation bool `json:"ignoreNavigation"`
}

Jump to

Keyboard shortcuts

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