From ecd61bb4ca8b5c3224dba994f1ead8f21c9794b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Thu, 11 Sep 2008 14:47:55 +0200 Subject: - Fixed /Genres - Added track number on songs in Genres/*/* --- TODO | 2 -- src/mfs_subr.c | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 950f2fd..2f8f610 100644 --- a/TODO +++ b/TODO @@ -2,8 +2,6 @@ v. 0.1 ~~~~~~ -* Fix /Genres - * BUG: fsync errors with /.config v. 0.2(?) diff --git a/src/mfs_subr.c b/src/mfs_subr.c index cbf8f8d..54269be 100644 --- a/src/mfs_subr.c +++ b/src/mfs_subr.c @@ -506,6 +506,8 @@ mfs_lookup_start(int field, void *data, lookup_fn_t *fn, const char *query) ret = sqlite3_prepare_v2(lh->handle, query, -1, &lh->st, NULL); if (ret != SQLITE_OK) { free(lh); + DEBUG("Error preparing statement: %s\n", + sqlite3_errmsg(handle)); return (NULL); } lh->query = query; @@ -621,7 +623,7 @@ int mfs_realpath(const char *path, char **realpath) { DEBUG("getting real path for %s\n", path); struct lookuphandle *lh; - char *artist, *album, *title; + char *genre, *artist, *album, *title; int error; lh = NULL; @@ -700,6 +702,34 @@ mfs_realpath(const char *path, char **realpath) { default: error = -ENOENT; } + } else if (strncmp(path, "/Genres", 7) == 0) { + switch (mfs_numtoken(path)) { + case 4: + genre = mfs_gettoken(path, 2); + album = mfs_gettoken(path, 3); + title = mfs_gettoken(path, 4); + DEBUG("genre(%s) album(%s) title(%s)\n", genre, album, + title); + if (!(genre && album && title)) { + error = -ENOENT; + break; + } + lh = mfs_lookup_start(0, realpath, mfs_lookup_path, + "SELECT filepath FROM song WHERE genrename LIKE ? " + "AND album LIKE ? AND " + "(LTRIM(track||' ')||title||'.'||extension) " + "LIKE ?"); + if (lh == NULL) { + error = -EIO; + break; + } + mfs_lookup_insert(lh, genre, LIST_DATATYPE_STRING); + mfs_lookup_insert(lh, album, LIST_DATATYPE_STRING); + mfs_lookup_insert(lh, title, LIST_DATATYPE_STRING); + break; + default: + error = -ENOENT; + } } if (lh) { @@ -890,9 +920,10 @@ mfs_lookup_genre(const char *path, struct filler_data *fd) if (album == NULL) break; lh = mfs_lookup_start(0, fd, mfs_lookup_list, - "SELECT title||'.'||extension FROM song, genre WHERE" - " song.genrename = genre.name AND genre.name LIKE ? " - " AND song.album LIKE ?"); + "SELECT LTRIM(track||' ')||title||'.'||extension FROM " + "song, genre WHERE " + "song.genrename = genre.name AND genre.name LIKE ? " + "AND song.album LIKE ?"); mfs_lookup_insert(lh, genre, LIST_DATATYPE_STRING); mfs_lookup_insert(lh, album, LIST_DATATYPE_STRING); break; -- cgit v1.2.3