feat: Adding mpc list
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
//"fmt"
|
//"fmt"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@@ -50,12 +51,16 @@ func menuController(conn net.Conn) {
|
|||||||
out = infoSong(conn)
|
out = infoSong(conn)
|
||||||
case "next":
|
case "next":
|
||||||
out = nextSong(conn)
|
out = nextSong(conn)
|
||||||
|
case "addsong":
|
||||||
|
addSong(conn)
|
||||||
}
|
}
|
||||||
|
if out != "" {
|
||||||
_, err = conn.Write([]byte(out))
|
_, err = conn.Write([]byte(out))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error al enviar la informacion", err)
|
log.Println("Error al enviar la informacion", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func playSong(conn net.Conn) string {
|
func playSong(conn net.Conn) string {
|
||||||
cmd := exec.Command("mpc", "play")
|
cmd := exec.Command("mpc", "play")
|
||||||
@@ -92,3 +97,25 @@ func nextSong(conn net.Conn) string {
|
|||||||
}
|
}
|
||||||
return string(output)
|
return string(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addSong(conn net.Conn) {
|
||||||
|
defer conn.Close()
|
||||||
|
cmd := exec.Command("mpc", "listall")
|
||||||
|
cmd.Stdout = conn
|
||||||
|
cmd.Run()
|
||||||
|
if tcpConn, ok := conn.(*net.TCPConn); ok {
|
||||||
|
tcpConn.CloseWrite()
|
||||||
|
}
|
||||||
|
bufSong := make([]byte, 1024)
|
||||||
|
n, err := conn.Read(bufSong)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error al recibir cancion", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%s, agregado por %s", strings.TrimSpace(string(bufSong[:n])), conn.RemoteAddr())
|
||||||
|
cmdmpc := exec.Command("bash", "-c", fmt.Sprintf("mpc insert %q && mpc next >/dev/null && mpc play", strings.TrimSpace(string(bufSong[:n]))))
|
||||||
|
_, err = cmdmpc.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error al reproducir cancion", err)
|
||||||
|
}
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user