diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7cb2e95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# Ignore files without extension (mainly binaries) +* +!/**/ +!*.* +# Created by https://www.toptal.com/developers/gitignore/api/go,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=go,visualstudiocode + +### Go ### +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2a942d7 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module eneller/vlc-slave + +go 1.23.5 + +// github.com/CedArctic/go-vlc-ctrl v0.5.0 \ No newline at end of file diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/internal/utils/defs.go b/internal/utils/defs.go new file mode 100644 index 0000000..c70eaa4 --- /dev/null +++ b/internal/utils/defs.go @@ -0,0 +1,5 @@ +package utils + +const Port = ":8080" +const HeadernameStream = "Streamsource" +const VLCWindowName = "VLC media player" diff --git a/vlcslave/vlc-slave.go b/vlcslave/vlc-slave.go new file mode 100644 index 0000000..8994ed8 --- /dev/null +++ b/vlcslave/vlc-slave.go @@ -0,0 +1,57 @@ +package main + +import ( + "eneller/vlc-slave/internal/utils" + "fmt" + "log" + "log/slog" + "net/http" + "os/exec" +) + +func main() { + slog.Info("VLC-Slave Server listening on port " + utils.Port) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + slog.Info(r.UserAgent()) + focusWindowOrLaunch() + receiveStreamFromClient(*r) + }) + http.HandleFunc("/stream", func(w http.ResponseWriter, r *http.Request) { + slog.Info(r.UserAgent()) + focusWindowOrLaunch() + //TODO handle failure if key cant be found + src := r.Header.Values(utils.HeadernameStream) + if len(src) > 0 { + openStream(src[0]) + } else { + slog.Error(fmt.Sprintf("Received Empty Field for HTTP Header `%s`", utils.HeadernameStream)) + } + }) + // start Server + log.Fatal(http.ListenAndServe(utils.Port, nil)) +} + +func focusWindowOrLaunch() { + // attempt to focus an existing VLC window + //NOTE might also use xdotools here or equivalent wayland tools + cmd := exec.Command("wmctrl", "-a", utils.VLCWindowName) + if err := cmd.Run(); err != nil { + //TODO launch VLC here + slog.Error(fmt.Sprintf("Failed to run command: `%s` ", cmd.String())) + } +} + +func receiveStreamFromClient(request http.Request) { + //TODO supplement with information provided by vlc master + openStream(request.RemoteAddr) +} + +/* +opens a network stream in vlc using a provided url using the following: +"add to playlist and start playback: ?command=in_play&input=&option=