gopherlink

package module
v0.0.0-...-098a54a Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

README

Gopherlink

Supported Sources

  • Youtube
  • More to come

Installation

Gopherlink is designed to run on Linux. Windows + Mac OS are untested.

Docker is the preffered method of installation, you can use the application this way via the provided Dockerfile.

If you do not wish to use Docker, you can use the application the following way.

Dependencies

In Debian based systems this can be done with

apt-get update && apt-get install -y libopus-dev libopusfile-dev ffmpeg python3

You will have to aquire Go yourself as the Debian repositories do not have it.

You will also have to aquire an executable for yt-dlp, this can be found here.

In Arch based systems you can do this easily via an AUR helper like yay.

yay -Syy opus opusfile ffmpeg python3 yt-dlp go

Building

Gopherlink is written in Go (surprisingly enough) and can be built very easily.

First if you haven't already, you must clone the repository with

git clone https://github.com/damaredayo/gopherlink.git

Then, you will want to enter the directory with cd gopherlink/app at which point you can run

go build -o gopherlink

Which will build the application, it can then be ran via ./gopherlink

Environment Variables

There is currently one environment variable which is the path of yt-dlp.

The name of this environment variable is YTDL_PATH.

Gopherlink will currently NOT work without this.

Usage

Gopherlink uses GRPC currently to communicate over a network. There ARE plans to move away from this (as I hate protobuf with a burning passion).

The protobuf files can be found at https://github.com/damaredayo/gopherlink/tree/master/proto

If you do not wish to use GRPC (I don't blame you) then you can use Gopherlink like a go package instead without having to build the application.

This can be easily done with go get by doing

go get -u github.com/damaredayo/gopherlink

The functions are fairly idiomatic, if you have worked with Lavalink in the past then the basic flow will feel very familiar.

Examples of implementation with both methods will come soon. (I will likely move away from GRPC first.)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSongFound  = fmt.Errorf("no song found")
	IndexNotInRange = fmt.Errorf("index not in range")
)
View Source
var ErrEmptyEndpoint = errors.New("empty endpoint")
View Source
var ErrNilClose = errors.New("nil close channel")
View Source
var (
	ErrNoNextSong = fmt.Errorf("no next song")
)
View Source
var ErrOkIsFalse = errors.New("ok is false")
View Source
var ErrUDPOpen = errors.New("udp connection already open")
View Source
var ErrUDPSmallPacket = errors.New("recv udp packet is small")
View Source
var ErrVoiceWSNil = errors.New("nil voice websocket")
View Source
var ErrWSNotNil = errors.New("websocket not nil")
View Source
var YTDLPath = os.Getenv("YTDL_PATH")

Functions

func AacToPCM

func AacToPCM(in interface{}) (pcm []int16, sampleRate int)

func YoutubeToAAC

func YoutubeToAAC(url string) (aac []byte, info *goutubedl.Info, err error)

func YoutubeToInfo

func YoutubeToInfo(url string) (info *goutubedl.Info, err error)

Types

type Cache

type Cache interface {
	AddSong(url string, aac []byte)
	GetSong(url string) (aac []byte, ok bool)
	AddInfo(url string, info *goutubedl.Info)
	GetInfo(url string) (info *goutubedl.Info, ok bool)
	// The following are internal no matter what
	PreloadSong(url string) error
	GetNextSong() (aac []byte, info *goutubedl.Info, err error)
}

type CacheTypeConst

type CacheTypeConst int
const (
	CacheTypeInternal CacheTypeConst = iota
	CacheTypeRedis
)

type Event

type Event struct {
	Operation int             `json:"op"`
	Sequence  int64           `json:"s"`
	Type      string          `json:"t"`
	RawData   json.RawMessage `json:"d"`
}

type InternalQueue

type InternalQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*InternalQueue) AddSong

func (i *InternalQueue) AddSong(ctx context.Context, song *pb.SongInfo) error

func (*InternalQueue) GetNextSong

func (i *InternalQueue) GetNextSong(ctx context.Context) (*pb.SongInfo, error)

func (*InternalQueue) GetQueue

func (i *InternalQueue) GetQueue(ctx context.Context) ([]*pb.SongInfo, error)

func (*InternalQueue) GetQueueType

func (i *InternalQueue) GetQueueType() QueueTypeConst

func (*InternalQueue) Ready

func (i *InternalQueue) Ready() bool

func (*InternalQueue) RemoveSong

func (i *InternalQueue) RemoveSong(ctx context.Context, song *pb.SongInfo) error

func (*InternalQueue) RemoveSongByIndex

func (i *InternalQueue) RemoveSongByIndex(ctx context.Context, remove int) (*pb.SongInfo, error)

type Np

type Np struct {
	GuildId  string
	Playing  bool
	Duration int64
	Elapsed  int64
	Author   string
	Title    string
}

type Op2

type Op2 struct {
	SSRC  uint32   `json:"ssrc"`
	Port  int      `json:"port"`
	Modes []string `json:"modes"`
	IP    string   `json:"ip"`
}

type Op4

type Op4 struct {
	SecretKey [32]byte `json:"secret_key"`
	Mode      string   `json:"mode"`
}

type Op8

type Op8 struct {
	HeartbeatInterval time.Duration `json:"heartbeat_interval"`
}

type Queue

type Queue struct {
	QueueType
}

type QueueType

type QueueType interface {
	AddSong(ctx context.Context, song *pb.SongInfo) error
	RemoveSong(ctx context.Context, song *pb.SongInfo) error
	RemoveSongByIndex(ctx context.Context, index int) (*pb.SongInfo, error)
	GetQueue(ctx context.Context) ([]*pb.SongInfo, error)
	GetQueueType() QueueTypeConst
	GetNextSong(ctx context.Context) (*pb.SongInfo, error)
	Ready() bool
}

type QueueTypeConst

type QueueTypeConst int
const (
	RedisQueueType QueueTypeConst = iota
	InternalQueueType
)

func (QueueTypeConst) String

func (q QueueTypeConst) String() string

type RedisQueue

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

func (*RedisQueue) AddSong

func (r *RedisQueue) AddSong(ctx context.Context, song *pb.SongInfo) error

func (*RedisQueue) GetNextSong

func (r *RedisQueue) GetNextSong(ctx context.Context) (*pb.SongInfo, error)

func (*RedisQueue) GetQueue

func (r *RedisQueue) GetQueue(ctx context.Context) ([]*pb.SongInfo, error)

func (*RedisQueue) GetQueueType

func (r *RedisQueue) GetQueueType() QueueTypeConst

func (*RedisQueue) Ready

func (r *RedisQueue) Ready() bool

func (*RedisQueue) RemoveSong

func (r *RedisQueue) RemoveSong(ctx context.Context, song *pb.SongInfo) error

func (*RedisQueue) RemoveSongByIndex

func (r *RedisQueue) RemoveSongByIndex(ctx context.Context, index int) (*pb.SongInfo, error)

type VoiceConnection

type VoiceConnection struct {
	Mutex sync.RWMutex

	Ready bool

	UserID    string
	GuildID   string
	ChannelID string

	Deaf     bool
	Mute     bool
	Speaking bool

	Connected    bool
	Reconnecting bool

	SessionID string
	Token     string
	Endpoint  string

	NowPlaying *Np
	Queue      *Queue
	Cache      Cache

	ByteTrack int
	OpusSend  chan []byte

	Playing bool
	Paused  bool
	Volume  float32
	Loop    bool
	// contains filtered or unexported fields
}

func (*VoiceConnection) Close

func (v *VoiceConnection) Close()

func (*VoiceConnection) GetDuration

func (v *VoiceConnection) GetDuration() int64

func (*VoiceConnection) GetElapsed

func (v *VoiceConnection) GetElapsed() int64

func (*VoiceConnection) GetPCMLength

func (v *VoiceConnection) GetPCMLength() int

func (*VoiceConnection) MakeCache

func (v *VoiceConnection) MakeCache(c CacheTypeConst, options interface{}) error

func (*VoiceConnection) MakeQueue

func (v *VoiceConnection) MakeQueue(qtype QueueTypeConst, options interface{}) error

func (*VoiceConnection) MusicPlayer

func (v *VoiceConnection) MusicPlayer(rate int, size int)

func (*VoiceConnection) Open

func (v *VoiceConnection) Open() (err error)

func (*VoiceConnection) SetPCM

func (v *VoiceConnection) SetPCM(pcm []int16)

func (*VoiceConnection) SetQueueType

func (v *VoiceConnection) SetQueueType(q QueueType)

func (*VoiceConnection) SetSpeaking

func (v *VoiceConnection) SetSpeaking(speaking bool) (err error)

func (*VoiceConnection) Skip

func (v *VoiceConnection) Skip() error

func (*VoiceConnection) Stop

func (v *VoiceConnection) Stop() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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