From 053e5ac36dfce0f4247bcf91656a11016701c997 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Oct 2016 23:23:49 +0200 Subject: support reading options from config file This tries to read ~/.local/mpd-notification.conf, which is expected to look like this: host = localhost port = 6600 music-dir = /srv/media/music/ scale = 200 timeout = 20 Unused options can be commented or removed completely. --- Makefile | 1 + mpd-notification.c | 15 +++++++++++++++ mpd-notification.h | 2 ++ 3 files changed, 18 insertions(+) diff --git a/Makefile b/Makefile index c24e215..e2a1707 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ RM := rm # flags CFLAGS += -std=c11 -O2 -fPIC -Wall -Werror +CFLAGS += -liniparser CFLAGS += $(shell pkg-config --cflags --libs libmpdclient) CFLAGS += $(shell pkg-config --cflags --libs libnotify) LIBAV_CFLAGS := $(shell pkg-config --cflags --libs libavformat libavutil 2>/dev/null) diff --git a/mpd-notification.c b/mpd-notification.c index f504836..543f60a 100644 --- a/mpd-notification.c +++ b/mpd-notification.c @@ -176,6 +176,7 @@ char * append_string(char * string, const char * format, const char delim, const /*** main ***/ int main(int argc, char ** argv) { + dictionary * ini = NULL; const char * title = NULL, * artist = NULL, * album = NULL; char * notifystr = NULL; GdkPixbuf * pixbuf = NULL; @@ -198,6 +199,17 @@ int main(int argc, char ** argv) { music_dir = getenv("XDG_MUSIC_DIR"); + /* parse config file */ + if (chdir(getenv("HOME")) == 0 && access(".config/mpd-notification.conf", R_OK) == 0 && + (ini = iniparser_load(".config/mpd-notification.conf")) != NULL) { + file_workaround = iniparser_getboolean(ini, ":notification-file-workaround", file_workaround); + mpd_host = iniparser_getstring(ini, ":host", mpd_host); + mpd_port = iniparser_getint(ini, ":port", mpd_port); + notification_timeout = iniparser_getint(ini, ":timeout", notification_timeout); + music_dir = iniparser_getstring(ini, ":music-dir", music_dir); + scale = iniparser_getint(ini, ":scale", scale); + } + /* get the verbose status */ while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) { switch (i) { @@ -435,5 +447,8 @@ nonotification: g_object_unref(G_OBJECT(notification)); notify_uninit(); + if (ini != NULL) + iniparser_freedict(ini); + return EXIT_SUCCESS; } diff --git a/mpd-notification.h b/mpd-notification.h index 0cbd370..52fbec9 100644 --- a/mpd-notification.h +++ b/mpd-notification.h @@ -10,6 +10,8 @@ #define _GNU_SOURCE +#include + #include #include -- cgit v1.2.3-70-g09d2 From d021fcf40f0900a3dfb1f1e162ed25d61085ea5c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Oct 2016 23:32:17 +0200 Subject: add basic documentation about configuration file --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6025af8..5a36b9e 100644 --- a/README.md +++ b/README.md @@ -69,16 +69,32 @@ or `systemctl --user enable mpd-notification`. * *-v*: verbose output * *-V*: print version information +Configuration +------------- + +Configuration options can be read from a configuration file. `mpd` +tries to read `~/.local/mpd-notification.conf`, which is expected to +look like this: + + host = localhost + port = 6600 + music-dir = /srv/media/music/ + scale = 200 + timeout = 20 + +Unused options can be commented or removed completely. + Artwork ------- `mpd` does not provide any information where it finds its music files. To make `mpd-notification` display album artwork you need to tell it where to look for -artwork. You can do that by exporting `XDG_MUSIC_DIR` to your environment or by -specifying `-m` or `--music-dir` on the command line. `mpd-notification` reads -album artwork from `mp3` files, otherwise an image file containing the artwork -needs to be placed in the same directory as the media file and named -`cover.jpg`, `cover.png`, `folder.jpg` or `folder.png`. +artwork. You can do that by exporting `XDG_MUSIC_DIR` to your environment, by +specifying `-m` or `--music-dir` on the command line or by setting `music-dir` +in configuration file. `mpd-notification` reads album artwork from `mp3` +files, otherwise an image file containing the artwork needs to be placed +in the same directory as the media file and named `cover.jpg`, +`cover.png`, `folder.jpg` or `folder.png`. ### Upstream -- cgit v1.2.3-70-g09d2 From 86aaf24691e1d9035a3db86e2df03c49e7675d6c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 Oct 2016 23:52:53 +0200 Subject: mention the new dependency --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5a36b9e..2ee1cb5 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Requirements To compile and run `mpd-notification` you need: +* [iniparser](http://ndevilla.free.fr/iniparser/) * [libav](https://libav.org/) or [ffmpeg](https://www.ffmpeg.org/) * [libnotify](http://library.gnome.org/devel/notification-spec/) * [libmpdclient](http://www.musicpd.org/libs/libmpdclient/) -- cgit v1.2.3-70-g09d2