Using utils.GetNetwork
This commit is contained in:
parent
503701691b
commit
3effda228b
11
main.go
11
main.go
@ -22,16 +22,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
config.ReadConfig()
|
config.ReadConfig()
|
||||||
var mpdConnectionError error
|
var mpdConnectionError error
|
||||||
del := ""
|
client.Conn, mpdConnectionError = mpd.Dial(utils.GetNetwork())
|
||||||
nt := viper.GetString("NETWORK_TYPE")
|
|
||||||
port := viper.GetString("MPD_PORT")
|
|
||||||
if nt == "tcp" {
|
|
||||||
del = ":"
|
|
||||||
} else if nt == "unix" && port != "" {
|
|
||||||
port = ""
|
|
||||||
}
|
|
||||||
client.Conn, mpdConnectionError = mpd.Dial(nt,
|
|
||||||
viper.GetString("NETWORK_ADDRESS")+del+port)
|
|
||||||
if mpdConnectionError != nil {
|
if mpdConnectionError != nil {
|
||||||
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
||||||
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type winsize struct {
|
type winsize struct {
|
||||||
@ -174,3 +176,15 @@ func Unique(intSlice []int) []int {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetNetwork() (string, string) {
|
||||||
|
del := ""
|
||||||
|
nt := viper.GetString("NETWORK_TYPE")
|
||||||
|
port := viper.GetString("MPD_PORT")
|
||||||
|
if nt == "tcp" {
|
||||||
|
del = ":"
|
||||||
|
} else if nt == "unix" && port != "" {
|
||||||
|
port = ""
|
||||||
|
}
|
||||||
|
return nt, viper.GetString("NETWORK_ADDRESS") + del + port
|
||||||
|
}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/aditya-K2/tview"
|
"github.com/aditya-K2/tview"
|
||||||
"github.com/fhs/gompd/v2/mpd"
|
"github.com/fhs/gompd/v2/mpd"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlaylistView struct {
|
type PlaylistView struct {
|
||||||
@ -95,17 +94,9 @@ func (p *PlaylistView) StartWatcher() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
del := ""
|
|
||||||
nt := viper.GetString("NETWORK_TYPE")
|
|
||||||
port := viper.GetString("MPD_PORT")
|
|
||||||
if nt == "tcp" {
|
|
||||||
del = ":"
|
|
||||||
} else if nt == "unix" && port != "" {
|
|
||||||
port = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
w, err := mpd.NewWatcher(nt,
|
nt, addr := utils.GetNetwork()
|
||||||
viper.GetString("NETWORK_ADDRESS")+del+port, "", "playlist")
|
w, err := mpd.NewWatcher(nt, addr, "", "playlist")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Print("RED", "Could Not Start Watcher.\n")
|
utils.Print("RED", "Could Not Start Watcher.\n")
|
||||||
utils.Print("GREEN", "Please check your MPD Info in config File.\n")
|
utils.Print("GREEN", "Please check your MPD Info in config File.\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user