aboutsummaryrefslogtreecommitdiffstats
path: root/src/lyrics_hd.c
diff options
context:
space:
mode:
authorAndreas Obergrusberger <tradiaz@yahoo.de>2007-01-03 20:12:16 +0000
committerAndreas Obergrusberger <tradiaz@yahoo.de>2007-01-03 20:12:16 +0000
commit6d9b28ec69212a2542ab2958ed0b012c124dbc07 (patch)
tree17cb3f8bb8b8a3f6e0bf824202148dc326a9f25c /src/lyrics_hd.c
parentb454d1517608a8f137723c6c5080bbcb29e7329c (diff)
downloadmpd-6d9b28ec69212a2542ab2958ed0b012c124dbc07.tar.gz
mpd-6d9b28ec69212a2542ab2958ed0b012c124dbc07.tar.xz
mpd-6d9b28ec69212a2542ab2958ed0b012c124dbc07.zip
added a plugin system for lyrics sources
git-svn-id: https://svn.musicpd.org/ncmpc/branches/tradiaz@5217 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/lyrics_hd.c')
-rw-r--r--src/lyrics_hd.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lyrics_hd.c b/src/lyrics_hd.c
new file mode 100644
index 000000000..2d91adc2a
--- /dev/null
+++ b/src/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_lyr_hd (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 = "";
+}