nicolive

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package nicolive provides access way to NicoNama API, corresponding structures and other features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommentOwner added in v0.0.4

func CommentOwner(broadID string, method string, commreq *CommentOwnerRequest, ac *Account) error

CommentOwner sends a comment as the owner.

func Is184UserID added in v0.0.5

func Is184UserID(id string) bool

Is184UserID returns whether the ID is 184

Types

type Account

type Account struct {
	Mail        string `yaml:"mail"`
	Pass        string `yaml:"pass"`
	Usersession string `yaml:"usersession"`
	// contains filtered or unexported fields
}

An Account is a niconico account. It is used to access APIs in this library.

func AccountLoad added in v0.0.4

func AccountLoad(filePath string) (*Account, error)

AccountLoad reads from a file and return new Account.

func NewAccount added in v0.0.4

func NewAccount(mail, pass, usersession string) *Account

NewAccount makes new account with a http client.

func (*Account) Login

func (a *Account) Login() error

Login logs in to niconico and updates its Usersession

func (*Account) Save

func (a *Account) Save(filePath string) error

Save save Account to a file.

func (*Account) String

func (a *Account) String() string

func (*Account) UpdateClient added in v0.0.4

func (a *Account) UpdateClient()

UpdateClient updates Client with its Usersession. If the Usersession of the account is empty string, clear the cookies jar.

type Antenna added in v0.0.2

type Antenna struct {
	Following []string
	// contains filtered or unexported fields
}

Antenna manages starting broadcast antenna connection.

func ConnectAntenna added in v0.0.2

func ConnectAntenna(ctx context.Context, ac *Account, ev EventReceiver) (*Antenna, error)

ConnectAntenna connects to antenna and return new Antenna.

func (*Antenna) Admin added in v0.0.2

func (a *Antenna) Admin() (err error)

Admin gets favorite communities and information to connect.

func (*Antenna) Connect added in v0.0.2

func (a *Antenna) Connect(ctx context.Context, ev EventReceiver) (err error)

Connect connects to antenna

func (*Antenna) Disconnect added in v0.0.2

func (a *Antenna) Disconnect() error

Disconnect quit all routines and disconnect.

func (*Antenna) Login added in v0.0.2

func (a *Antenna) Login() (err error)

Login logs in to the antenna connection.

func (Antenna) Send added in v0.0.2

func (c Antenna) Send(m string) error

type AntennaItem added in v0.0.2

type AntennaItem struct {
	BroadID, CommunityID, UserID string
}

An AntennaItem is a started live broadcast. It's send as a content of an EventTypeAntennaGot event.

type Comment

type Comment struct {
	No          int
	Date        time.Time
	UserID      string
	IsPremium   bool
	IsCommand   bool
	IsStaff     bool
	IsAnonymity bool
	Comment     string
	Mail        string
	Locale      string
	Score       int
}

A Comment is a received comment. It's send as a content of an EventTypeGot event.

type CommentConnection

type CommentConnection struct {
	ConnectedTm time.Time // The time when this connection started
	// contains filtered or unexported fields
}

CommentConnection is a struct to manage sending/receiving comments. This struct automatically Keeping alive and get the PostKey, which is necessary for sending comments.

func CommentConnect added in v0.0.2

func CommentConnect(ctx context.Context, lv LiveWaku, ev EventReceiver) (*CommentConnection, error)

CommentConnect connects to nicolive and start receiving comment. liveWaku should have connection information which is able to get by fetchInformation()

func (CommentConnection) Connect

func (c CommentConnection) Connect(ctx context.Context) error

func (*CommentConnection) Disconnect

func (cc *CommentConnection) Disconnect() error

Disconnect quit all routines and disconnect.

func (*CommentConnection) FetchPostKey

func (cc *CommentConnection) FetchPostKey() (postkey string, err error)

FetchPostKey gets postkey using getpostkey API This function is safe for concurrent use.

func (CommentConnection) Send added in v0.0.2

func (c CommentConnection) Send(m string) error

func (*CommentConnection) SendComment

func (cc *CommentConnection) SendComment(text string, iyayo bool)

SendComment sends comment to current comment connection

type CommentOwnerRequest added in v0.0.4

type CommentOwnerRequest struct {
	Text        string `json:"text"`
	IsPermanent bool   `json:"isPermanent"`
	Color       string `json:"color"`
	UserName    string `json:"userName,omitempty"`
}

CommentOwnerRequest is a request of an owner comment.

type ErrNum

type ErrNum int

ErrNum is an Enum to represent error number to identify.

const (
	ErrOther ErrNum = iota
	ErrSendComment
	ErrOpen
	ErrConnection
	ErrNicoLiveOther
	ErrNotLogin
	ErrClosed
	ErrRequireCommunityMember
	ErrIncorrectAccount
	ErrNetwork
	ErrDBUserNotFound
)

Enum ErrNum

type Error

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

Error is an error struct in nicolive

func ErrFromStdErr

func ErrFromStdErr(e error) Error

ErrFromStdErr returns Error converted from standard error.

func MakeError

func MakeError(errNum ErrNum, description string) Error

MakeError returns Error that is formated as the given info and the code position.

func (Error) Description

func (e Error) Description() string

Description returns description

func (Error) Error

func (e Error) Error() string

func (Error) Type added in v0.0.4

func (e Error) Type() ErrNum

Type returns errorNum for identifying by application. (ie. select messages to the user)

func (Error) TypeString added in v0.0.2

func (e Error) TypeString() string

TypeString returns name of the error type.

func (Error) Where

func (e Error) Where() string

Where returns where

type Event

type Event struct {
	Type    EventTypeNum
	Content interface{}
}

Event is an event

func (*Event) String

func (e *Event) String() string

type EventReceiver

type EventReceiver interface {
	ProceedNicoEvent(*Event)
}

EventReceiver receive events and proceed

type EventTypeNum

type EventTypeNum int

EventTypeNum is an Enum to represent Event.Type

const (
	EventTypeCommentErr EventTypeNum = iota
	EventTypeCommentGot
	EventTypeCommentSend
	EventTypeCommentOpen
	EventTypeCommentClose
	EventTypeWakuEnd
	EventTypeHeartBeatGot
	EventTypeAntennaOpen
	EventTypeAntennaClose
	EventTypeAntennaGot
	EventTypeAntennaErr
)

EventType

type HeartbeatValue

type HeartbeatValue struct {
	WatchCount   string
	CommentCount string
}

HeartbeatValue is struct to hold result of heartbeat API

type LiveWaku

type LiveWaku struct {
	Account *Account
	BroadID string

	Stream struct {
		Title       string
		Description string
		CommunityID string
		OwnerID     string
		OwnerName   string

		OpenTime  time.Time
		StartTime time.Time
		EndTime   time.Time

		BroadcastToken string
	}

	User struct {
		UserID    string
		Name      string
		IsPremium bool
	}

	CommentServer struct {
		Addr   string
		Port   string
		Thread string
	}

	OwnerBroad        bool
	OwnerCommentToken string
}

LiveWaku is a live broadcast(Waku) of Niconama

func (*LiveWaku) FetchHeartBeat

func (l *LiveWaku) FetchHeartBeat() (heartBeatValue *HeartbeatValue, waitTime int, err error)

FetchHeartBeat gets watcher and comment count using heartbeat API This function is safe for concurrent use.

func (*LiveWaku) FetchInformation

func (l *LiveWaku) FetchInformation() (err error)

FetchInformation gets information using getplayerstatus API

func (*LiveWaku) IsUserOwner

func (l *LiveWaku) IsUserOwner() bool

IsUserOwner returns whether the user own this broad

type PublishStatusItem added in v0.0.4

type PublishStatusItem struct {
	Token   string `json:"token"`
	URL     string `json:"url"`
	Stream  string `json:"stream"`
	Ticket  string `json:"ticket"`
	Bitrate string `json:"bitrate"`
}

PublishStatusItem is the response of PublishStatus API

func PublishStatus added in v0.0.4

func PublishStatus(broadID string, a *Account) (*PublishStatusItem, error)

PublishStatus gets a token to comment as owner. This function is safe for concurrent use.

type User added in v0.0.2

type User struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	CreateTime   time.Time `json:"create_time"`
	Is184        bool      `json:"is184"`
	ThumbnailURL string    `json:"thumbnail_url"`
}

User is a niconico user.

func CreateUser added in v0.0.4

func CreateUser(id string, a *Account) (*User, error)

CreateUser gather the user infomation of the given user id and returns pointer to new User struct.

func FetchUserInfo added in v0.0.2

func FetchUserInfo(id string, a *Account) (*User, error)

FetchUserInfo fetches user name and Thumbnail URL from niconico. This function is safe for concurrent use.

func (*User) Equal added in v0.0.2

func (u *User) Equal(x *User) bool

Equal reports whether t and x represent the same User instant.

type UserDB added in v0.0.2

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

UserDB is database of Users.

func NewUserDB added in v0.0.2

func NewUserDB(dirname string) (*UserDB, error)

NewUserDB creates new UserDB.

func (*UserDB) Close added in v0.0.2

func (d *UserDB) Close() error

Close closes the DB.

func (*UserDB) Fetch added in v0.0.2

func (d *UserDB) Fetch(id string) (*User, error)

Fetch fetches a user of given ID from the DB.

func (*UserDB) Remove added in v0.0.2

func (d *UserDB) Remove(id string) error

Remove removes a user of given ID from the DB.

func (*UserDB) Store added in v0.0.2

func (d *UserDB) Store(u *User) error

Store stores a user into the DB.

Jump to

Keyboard shortcuts

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