diff --git a/config/config.go b/config/config.go index 712356e..dda1381 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,8 @@ var ( "ADDITIONAL_PADDING_Y": 16, "IMAGE_WIDTH_EXTRA_X": -1.5, "IMAGE_WIDTH_EXTRA_Y": -3.75, + "NETWORK_TYPE": "tcp", + "NETWORK_ADDRESS": "localhost", "MUSIC_DIRECTORY": utils.CheckDirectoryFmt(getMusicDirectory()), "PORT": "6600", "DEFAULT_IMAGE_PATH": "default.jpg", diff --git a/docs/index.md b/docs/index.md index d73fac1..399e7f4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -26,6 +26,26 @@ This is the port where your Music Player Daemon Is Running ```yml MPD_PORT : "6600" ``` +## Network Type + +By Default gomp assumes that you connect to MPD Server through tcp, But if your MPD Server is configured to expose a unix socket rather than a port, then you can specify network type to "unix" + +```yml +NETWORK_TYPE : "unix" +``` + +Read More about it in the [sample_config](https://github.com/aditya-K2/gomp/blob/master/sample_config.yml) + +## Network Address + +The Address of the Host for e.g `"localhost"` or `"/path/to/unix/socket/"` if you are using unix sockets +Defaults to `localhost` + +```yml +NETWORK_ADDRESS : "/home/$USER/.mpd/socket" +``` + +Read More about it in the [sample_config](https://github.com/aditya-K2/gomp/blob/master/sample_config.yml) ## Music Directory diff --git a/main.go b/main.go index 14b99fa..0769117 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,16 @@ import ( func main() { config.ReadConfig() var mpdConnectionError error - CONN, mpdConnectionError := mpd.Dial("tcp", "localhost:"+viper.GetString("MPD_PORT")) + del := "" + nt := viper.GetString("NETWORK_TYPE") + port := viper.GetString("MPD_PORT") + if nt == "tcp" { + del = ":" + } else if nt == "unix" && port != "" { + port = "" + } + CONN, mpdConnectionError := mpd.Dial(nt, + viper.GetString("NETWORK_ADDRESS")+del+port) if mpdConnectionError != nil { 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") diff --git a/sample_config.yml b/sample_config.yml index d4f25d3..4eca45b 100644 --- a/sample_config.yml +++ b/sample_config.yml @@ -49,7 +49,15 @@ IMAGE_WIDTH_EXTRA_Y : -3.75 MPD_PORT : "6600" # Port on which music player daemon is running + # Do not provide this if you are connecting through a unix socket +NETWORK_TYPE : "tcp" # Defaults to tcp if not provided, use "unix" if MPD Server is configured to expose + # a unix socket rather than a port + # Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), + # "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix" and "unixpacket". + +NETWORK_ADDRESS : "localhost" # Defaults to localhost if not provided, + # This is the address of the host, for e.g "localhost"/ "127.0.0.1" / a Unix Socket "/home/$USER/.mpd/socket" DEFAULT_IMAGE_PATH: "default.jpg" # Note It is neccessary to use /home/your_user_name instead of ~