begin slave
This commit is contained in:
50
.gitignore
vendored
Normal file
50
.gitignore
vendored
Normal file
@@ -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
|
||||||
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module eneller/vlc-slave
|
||||||
|
|
||||||
|
go 1.23.5
|
||||||
|
|
||||||
|
// github.com/CedArctic/go-vlc-ctrl v0.5.0
|
||||||
5
internal/utils/defs.go
Normal file
5
internal/utils/defs.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
const Port = ":8080"
|
||||||
|
const HeadernameStream = "Streamsource"
|
||||||
|
const VLCWindowName = "VLC media player"
|
||||||
57
vlcslave/vlc-slave.go
Normal file
57
vlcslave/vlc-slave.go
Normal file
@@ -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 <uri> to playlist and start playback: ?command=in_play&input=<uri>&option=<option>"
|
||||||
|
from file:///usr/share/vlc/lua/http/requests/README.txt
|
||||||
|
*/
|
||||||
|
func openStream(url string) {
|
||||||
|
//TODO run against lua interface to open existing stream from URL
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user