Compare commits
No commits in common. "a5e34523429370f01798999b628b2688b6023c01" and "4891d5f7b75aa66eee992374dc8406345f8509f9" have entirely different histories.
a5e3452342
...
4891d5f7b7
@ -5,7 +5,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/DexterLB/mpvipc"
|
"github.com/DexterLB/mpvipc"
|
||||||
@ -15,19 +14,23 @@ import (
|
|||||||
|
|
||||||
type MPVSource struct {
|
type MPVSource struct {
|
||||||
process *exec.Cmd
|
process *exec.Cmd
|
||||||
ipcSocketDir string
|
ipcSocket string
|
||||||
Name string
|
Name string
|
||||||
Options []string
|
Options []string
|
||||||
File string
|
File string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
sources.SoundSources["mpv-nig"] = &MPVSource{
|
sources.SoundSources["mpv-1"] = &MPVSource{
|
||||||
Name: "Radio NIG",
|
Name: "Radio 1",
|
||||||
|
ipcSocket: "/tmp/tmpmpv.radio-1",
|
||||||
|
Options: []string{"--no-video", "--no-terminal"},
|
||||||
File: "https://mediaserv38.live-streams.nl:18030/stream",
|
File: "https://mediaserv38.live-streams.nl:18030/stream",
|
||||||
}
|
}
|
||||||
sources.SoundSources["mpv-synthfm"] = &MPVSource{
|
sources.SoundSources["mpv-2"] = &MPVSource{
|
||||||
Name: "Radio Synthetic FM",
|
Name: "Radio 2",
|
||||||
|
ipcSocket: "/tmp/tmpmpv.radio-2",
|
||||||
|
Options: []string{"--no-video", "--no-terminal"},
|
||||||
File: "https://mediaserv38.live-streams.nl:18040/live",
|
File: "https://mediaserv38.live-streams.nl:18040/live",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,20 +47,15 @@ func (s *MPVSource) IsEnabled() bool {
|
|||||||
return s.process != nil
|
return s.process != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MPVSource) ipcSocket() string {
|
|
||||||
return path.Join(s.ipcSocketDir, "mpv.socket")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MPVSource) Enable() (err error) {
|
func (s *MPVSource) Enable() (err error) {
|
||||||
if s.process != nil {
|
if s.process != nil {
|
||||||
return fmt.Errorf("Already running")
|
return fmt.Errorf("Already running")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ipcSocketDir, err = os.MkdirTemp("", "hathoris")
|
var opts []string
|
||||||
|
opts = append(opts, s.Options...)
|
||||||
opts := append([]string{"--no-video", "--no-terminal"}, s.Options...)
|
if s.ipcSocket != "" {
|
||||||
if s.ipcSocketDir != "" {
|
opts = append(opts, "--input-ipc-server="+s.ipcSocket, "--pause")
|
||||||
opts = append(opts, "--input-ipc-server="+s.ipcSocket(), "--pause")
|
|
||||||
}
|
}
|
||||||
opts = append(opts, s.File)
|
opts = append(opts, s.File)
|
||||||
|
|
||||||
@ -72,22 +70,18 @@ func (s *MPVSource) Enable() (err error) {
|
|||||||
s.process.Process.Kill()
|
s.process.Process.Kill()
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.ipcSocketDir != "" {
|
|
||||||
os.RemoveAll(s.ipcSocketDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
s.process = nil
|
s.process = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if s.ipcSocketDir != "" {
|
if s.ipcSocket != "" {
|
||||||
_, err = os.Stat(s.ipcSocket())
|
_, err = os.Stat(s.ipcSocket)
|
||||||
for i := 20; i >= 0 && err != nil; i-- {
|
for i := 20; i >= 0 && err != nil; i-- {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
_, err = os.Stat(s.ipcSocket())
|
_, err = os.Stat(s.ipcSocket)
|
||||||
}
|
}
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
|
||||||
conn := mpvipc.NewConnection(s.ipcSocket())
|
conn := mpvipc.NewConnection(s.ipcSocket)
|
||||||
err = conn.Open()
|
err = conn.Open()
|
||||||
for i := 20; i >= 0 && err != nil; i-- {
|
for i := 20; i >= 0 && err != nil; i-- {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
@ -151,14 +145,12 @@ func (s *MPVSource) FadeOut(conn *mpvipc.Connection, speed int) {
|
|||||||
func (s *MPVSource) Disable() error {
|
func (s *MPVSource) Disable() error {
|
||||||
if s.process != nil {
|
if s.process != nil {
|
||||||
if s.process.Process != nil {
|
if s.process.Process != nil {
|
||||||
if s.ipcSocketDir != "" {
|
conn := mpvipc.NewConnection(s.ipcSocket)
|
||||||
conn := mpvipc.NewConnection(s.ipcSocket())
|
|
||||||
err := conn.Open()
|
err := conn.Open()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
s.FadeOut(conn, 3)
|
s.FadeOut(conn, 3)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
s.process.Process.Kill()
|
s.process.Process.Kill()
|
||||||
}
|
}
|
||||||
@ -168,8 +160,8 @@ func (s *MPVSource) Disable() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MPVSource) CurrentlyPlaying() string {
|
func (s *MPVSource) CurrentlyPlaying() string {
|
||||||
if s.ipcSocketDir != "" {
|
if s.ipcSocket != "" {
|
||||||
conn := mpvipc.NewConnection(s.ipcSocket())
|
conn := mpvipc.NewConnection(s.ipcSocket)
|
||||||
err := conn.Open()
|
err := conn.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to open mpv socket:", err.Error())
|
log.Println("Unable to open mpv socket:", err.Error())
|
||||||
@ -189,11 +181,11 @@ func (s *MPVSource) CurrentlyPlaying() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MPVSource) TogglePause(id string) error {
|
func (s *MPVSource) TogglePause(id string) error {
|
||||||
if s.ipcSocketDir == "" {
|
if s.ipcSocket == "" {
|
||||||
return fmt.Errorf("Not supported")
|
return fmt.Errorf("Not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := mpvipc.NewConnection(s.ipcSocket())
|
conn := mpvipc.NewConnection(s.ipcSocket)
|
||||||
err := conn.Open()
|
err := conn.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -52,7 +52,7 @@ func (s *SPDIFSource) IsActive() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SPDIFSource) IsEnabled() bool {
|
func (s *SPDIFSource) IsEnabled() bool {
|
||||||
return s.processRec != nil || s.processPlay != nil
|
return s.processRec != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SPDIFSource) Enable() error {
|
func (s *SPDIFSource) Enable() error {
|
||||||
@ -80,8 +80,9 @@ func (s *SPDIFSource) Enable() error {
|
|||||||
if s.processPlay != nil && s.processPlay.Process != nil {
|
if s.processPlay != nil && s.processPlay.Process != nil {
|
||||||
s.processPlay.Process.Kill()
|
s.processPlay.Process.Kill()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
pipeR.Close()
|
pipeR.Close()
|
||||||
|
pipeW.Close()
|
||||||
|
}
|
||||||
|
|
||||||
s.processPlay = nil
|
s.processPlay = nil
|
||||||
}()
|
}()
|
||||||
@ -98,7 +99,6 @@ func (s *SPDIFSource) Enable() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
s.processRec.Process.Kill()
|
s.processRec.Process.Kill()
|
||||||
}
|
}
|
||||||
pipeW.Close()
|
|
||||||
|
|
||||||
s.processRec = nil
|
s.processRec = nil
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user