opendj

package module
v0.0.0-...-c3c4030 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

README

GoDoc Go Report Card

opendj

a simple library that makes it easy to implement a plug.dj clone

This library needs ffmpeg and youtube-dl to work!
It should be able to stream anything you can use the following command on

$ youtube-dl -f bestaudio -g {url}

example usage

package main

import (
	"fmt"
	"github.com/SoMuchForSubtlety/opendj"
)

func main() {
	var dj opendj.Dj
	// add a handler that gets called when a new song plays
	dj.AddNewSongHandler(newSong)

	// create a QueueEntry
	// please don't actually do this manually
	var song opendj.Media
	song.Title = "BADBADNOTGOOD - CAN'T LEAVE THE NIGHT"
	song.URL = "https://www.youtube.com/watch?v=caY0MEok19I"
	song.Duration = 282000000000

	var entry opendj.QueueEntry
	entry.Media = song
	entry.Owner = "MyUsername"

	// add the entry to the queue
	dj.AddEntry(entry)

	// start playing to your favourite RTMP server
	dj.Play("http://example.org/rtmp/23rhwogvf984hgtw")
}

func newSong(entry opendj.QueueEntry) {
	fmt.Printf("now playing %s", entry.Media.Title)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorEmptyQueue = errors.New("can't pop from empty queue")

Functions

This section is empty.

Types

type Dj

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

Dj stores the queue and handlers

func NewDj

func NewDj(queue []QueueEntry) (dj *Dj)

NewDj initializes and returns a new Dj struct.

func (*Dj) AddEndOfSongHandler

func (dj *Dj) AddEndOfSongHandler(f func(QueueEntry, error))

AddEndOfSongHandler adds a function that will be called every time a song stops playing. It gets passed the QueueEntry that finished playing and any errors encountered during playback.

func (*Dj) AddEntry

func (dj *Dj) AddEntry(newEntry QueueEntry)

AddEntry adds the passed QueueEntry at the end of the queue.

func (*Dj) AddNewSongHandler

func (dj *Dj) AddNewSongHandler(f func(QueueEntry))

AddNewSongHandler adds a function that will be called every time a new song starts playing.

func (*Dj) AddPlaybackErrorHandler

func (dj *Dj) AddPlaybackErrorHandler(f func(error))

AddPlaybackErrorHandler adds a function that will be called every time an error occurs during playback.

In effect this mean it will be called every time ffmpeg or yt-dlp exit with an error. Sometimes ffmpeg can exit with code 1 even though the song was streamed successfully.

func (*Dj) ChangeIndex

func (dj *Dj) ChangeIndex(newEntry QueueEntry, index int) error

ChangeIndex swaps the QueueEntry the index for the provided one

returns an error if the index is out of range

func (*Dj) CurrentlyPlaying

func (dj *Dj) CurrentlyPlaying() (entry QueueEntry, progress time.Duration, err error)

CurrentlyPlaying returns the song that is currently being played and for how long it has been playing.

Returns an error if there is nothing playing.

func (*Dj) DurationUntilUser

func (dj *Dj) DurationUntilUser(nick string) (durations []time.Duration)

DurationUntilUser returns a slice of all the durations to the songs in the queue that belong to the given user.

func (*Dj) EntryAtIndex

func (dj *Dj) EntryAtIndex(index int) (QueueEntry, error)

EntryAtIndex returns the QueueEntry at the given index or error if the index is out of range

func (*Dj) InsertEntry

func (dj *Dj) InsertEntry(newEntry QueueEntry, index int) error

InsertEntry inserts the passed QueueEntry into the queue at the given index.

if the index is too high it has the same effect as AddEntry(). returns an error if the index is < 0.

func (*Dj) Play

func (dj *Dj) Play(rtmpServer string)

Play starts the playback to the given RTMP server.

If nothing is in the playlist it waits for new content to be added. Any encoutered errors are handled by the errorHandler.

func (*Dj) Queue

func (dj *Dj) Queue() []QueueEntry

Queue return the current queue as a list of queue entries.

func (*Dj) RemoveIndex

func (dj *Dj) RemoveIndex(index int) error

RemoveIndex removes the element the given index from the queue

returns an error if the index is out of range.

func (*Dj) UserPosition

func (dj *Dj) UserPosition(nick string) (positions []int)

UserPosition returns a slice of all the position in the queue that belong to the given user.

type Media

type Media struct {
	Title    string
	URL      string
	Duration time.Duration
}

Media represents a video or song that can be streamed.

this can be anything youtube-dl supports.

type QueueEntry

type QueueEntry struct {
	Media      Media
	Owner      string
	Dedication string
}

A QueueEntry represents media and metadata the can be ented into a queue.

Jump to

Keyboard shortcuts

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