ytqueuer

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

README

yt-queuer

Lightweight service and addon to enable queueing and playback of youtube videos on a remote device.

Planned Features

  • Allow control of playback device (play, pause, seek, next). LOE - Low (figure out callback)
  • Allow control of multiple playback devices and queues. LOE - Low (client registration since no hostname in js)
  • Create a browser addon as an alternateive to the Controller page. Add options in standard right-click browser menu. LOE - High

Build

The Makefile build targets will build binary in 'bin/' then copy the binary and any other needed files to 'pkg/'.

Using the default Makefile build target:

make build

Will build ytqueuer for the architecture you are currently on.

OR

You can specify an architecture.

make build GOARCH=amd64

OR

Use a predefined build target for a tested architecture.

make build-arm64

Will build for arm64.

Deploy

Copy

Copy pkg/ to the host you want to run it on. Example:

rsync -avz pkg/ user@host:ytqueuer
Run

From the host, run ytqueuer via whatever method you prefer.

cd ytqueuer
nohup ytqueuer &

ytqueuer will listen on all interfaces.

The first time ytqueuer runs it will create a new 'certs' folder with a self generated key and cert if they do not already exist. ytqueuer must use ssl to allow clipboard access in the controller.

certs/certificate.crt
certs/privatekey.key

Access

From your preferred browser on the host you want to play videos on, go to:

https://localhost:8080

If your playback device is different from the device you are running ytqueuer on, replace 'localhost' with a reachable interface on the ytqueuer host.

The browser should load a default video with 'under construction' tape across it if there is nothing in the queue. The first time you load the page you will need to accept the self-signed cert on the warning page (click on Advanced). You will also need to allow Auto Play in the Address Bar. Once Auto Play has been enabled, the playback page should automatically advance to the first video in the queue.

Control

From a browser on any other device you want to control the queue from, and can reach an interface on the ytqueuer host, go to:

https://<ytqueuer-ip>:8080/controller.html

Controller Page

If there are any videos in the queue they will be displayed in the middle of the page. On the left you will see icons to:

Add - Add a video to the queue.

Add

Add Next - Add a video to played next in queue.

Add Next

Clear Queue - Clear the queue. NO CONFIRMATION

Clear Queue

When using Add and Add Next you need to have a YouTube video URL copied to your clipboard. When you click on the button you will be prompted to Paste which will take a few seconds to highlight. (this is a Firefox security feature to prevent accidental clicks) The Add and Add Next buttons will take the video URL form your clickboard, get the video id and send it to the API.

To the right of each video in the queue you will see a Remove From Queue button. There is also no confirmation on this button.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueEmpty  = fmt.Errorf("queue is empty")
	ErrQueueNoNext = fmt.Errorf("no more videos in queue")
)

Functions

func ClientIP

func ClientIP(r *http.Request) string

func LoggerMiddleware

func LoggerMiddleware(logger *log.Logger) func(http.Handler) http.Handler

func RenderHTML

func RenderHTML(w http.ResponseWriter, status int, s string) error

func RenderJSON

func RenderJSON[T any](w http.ResponseWriter, status int, obj T) error

func renderJSON[T any](w http.ResponseWriter, r *http.Request, status int, obj T) error {

Types

type Details

type Details struct {
	VideoId      string `json:"video_id"`
	Title        string `json:"title"`
	AuthorName   string `json:"author_name"`
	ThumbnailURL string `json:"thumbnail_url"`
	StartSeconds int    `json:"start_seconds"`
}

func NewDetails

func NewDetails(vid string, start int) (Details, error)

type HTTPServer

type HTTPServer struct {
	Addr        string
	Logger      *log.Logger
	Queue       *Queue
	TLSCertFile string
	TLSKeyFile  string

	Handler http.Handler
	// Mux saves the http.ServeMux instance. This provides easier access to the
	// mux without having to enforce a ref type on HTTPServer.Handler everytime.
	// We can now use HTTPServer.Mux.Handle() instead of HTTPServer.Handler.(*http.ServeMux).Handle().
	Mux *http.ServeMux
}

func NewHTTPServer

func NewHTTPServer(logger *log.Logger, addr string, port int, certFile string, keyFile string, q *Queue) HTTPServer

func (*HTTPServer) AddHandler

func (s *HTTPServer) AddHandler() http.Handler

func (*HTTPServer) AddRoutes

func (s *HTTPServer) AddRoutes()

func (*HTTPServer) ClearHandler

func (s *HTTPServer) ClearHandler() http.Handler

func (*HTTPServer) NextHandler

func (s *HTTPServer) NextHandler(peek bool) http.Handler

func (*HTTPServer) PlayNextHandler

func (s *HTTPServer) PlayNextHandler() http.Handler

func (*HTTPServer) QueueHandler

func (s *HTTPServer) QueueHandler() http.Handler

func (*HTTPServer) RemoveHandler

func (s *HTTPServer) RemoveHandler() http.Handler

func (*HTTPServer) Start

func (s *HTTPServer) Start(ctx context.Context, timeoutSec int) error

type Queue

type Queue struct {
	Videos []Details
}

func NewQueue

func NewQueue() Queue

func (*Queue) Add

func (q *Queue) Add(vid string, start int) error

func (*Queue) Clear

func (q *Queue) Clear()

func (*Queue) GetNext

func (q *Queue) GetNext() (Details, error)

func (Queue) PeekNext

func (q Queue) PeekNext() (Details, error)

func (*Queue) PlayNext

func (q *Queue) PlayNext(vid string, start int) error

func (*Queue) Remove

func (q *Queue) Remove(vid string) error

type ReqMetrics

type ReqMetrics struct {
	ClientIP     string        `json:"client_ip"`
	RequestTime  time.Time     `json:"request_time"`
	Method       string        `json:"method"`
	URI          string        `json:"uri"`
	ResponseCode int           `json:"response_code"`
	ResponseSize int64         `json:"response_size"`
	Referer      string        `json:"referer"`
	UserAgent    string        `json:"user_agent"`
	Duration     time.Duration `json:"duration"`
}

func NewReqMetrics

func NewReqMetrics(r *http.Request) ReqMetrics

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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