diff options
Diffstat (limited to 'plugins/hd')
-rw-r--r-- | plugins/hd/Makefile.am | 40 | ||||
-rw-r--r-- | plugins/hd/lyrics_hd.c | 52 |
2 files changed, 92 insertions, 0 deletions
diff --git a/plugins/hd/Makefile.am b/plugins/hd/Makefile.am new file mode 100644 index 000000000..f4d4608d8 --- /dev/null +++ b/plugins/hd/Makefile.am @@ -0,0 +1,40 @@ +AM_CPPFLAGS =\ + $(GLIB_CFLAGS)\ + $(GTHREAD_CFLAGS)\ + $(libcurl_CFLAGS)\ + -I../../src + +###---- + +plugin_headers =\ + ../src_lyrics.h\ + ../screen_lyrics.h\ + ../easy_download.h\ + ../options.h + +###----- + +ncmpc_modulesdir = @plugindir@ + +ncmpc_modules_LTLIBRARIES = libhd.la + +### libhd + +libhd_la_LIBADD =\ + $(GLIB_LIBS)\ + $(libcurl_LIBS) + +libhd_la_headers =\ + $(plugins_headers) + +libhd_la_SOURCES =\ + lyrics_hd.c\ + $(libhd_la_headers) +install: + @$(MAKE) + mkdir -p ${ncmpc_modulesdir} + if test -f .libs/libhd.so; then cp .libs/libhd.so ${ncmpc_modulesdir}/lyrics_hd.so; fi + +uninstall: + @$(MAKE) + rm -f ${ncmpc_modulesdir}/lyrics_hd.so diff --git a/plugins/hd/lyrics_hd.c b/plugins/hd/lyrics_hd.c new file mode 100644 index 000000000..a90ee9d47 --- /dev/null +++ b/plugins/hd/lyrics_hd.c @@ -0,0 +1,52 @@ +#include <glib.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +#include "src_lyrics.h" + +char *check_lyr_hd(char *artist, char *title, int how) +{ //checking whether for lyrics file existence and proper access + static char path[1024]; + snprintf(path, 1024, "%s/.lyrics/%s/%s.lyric", + getenv("HOME"), artist, title); + + if(g_access(path, how) != 0) return NULL; + + return path; +} + + +int get_lyr_hd(char *artist, char *title) +{ + char *path = check_lyr_hd(artist, title, R_OK); + if(path == NULL) return -1; + + FILE *lyr_file; + lyr_file = fopen(path, "r"); + if(lyr_file == NULL) return -1; + + char *buf = NULL; + char **line = &buf; + size_t n = 0; + + while(1) + { + n = getline(line, &n, lyr_file); + if( n < 1 || *line == NULL || feof(lyr_file) != 0 ) return 0; + add_text_line(&lyr_text, *line, n); + free(*line); + *line = NULL; n = 0; + } + + return 0; +} + +int register_me (src_lyr *source_descriptor) +{ + source_descriptor->check_lyr = check_lyr_hd; + source_descriptor->get_lyr = get_lyr_hd; + + source_descriptor->name = "Harddisk"; + source_descriptor->description = ""; +} |