diff options
author | Kjetil Ørbekk <orbekk@pvv.ntnu.no> | 2008-08-13 14:08:58 +0200 |
---|---|---|
committer | Kjetil Ørbekk <orbekk@pvv.ntnu.no> | 2008-08-13 14:08:58 +0200 |
commit | d2727a60c0b2d6967d9cce3ca2696e1cab79e322 (patch) | |
tree | b47672212ec148c7605d7fc9d724ac39827a5834 | |
parent | 2635d332f07ee1691a785d543f7ccbde2eeb99f0 (diff) |
- Use mp3_basename and sqlite to add extensions to filenames
-rw-r--r-- | src/mp3_subr.c | 43 | ||||
-rwxr-xr-x | src/mp3_vnops.c | 2 |
2 files changed, 27 insertions, 18 deletions
diff --git a/src/mp3_subr.c b/src/mp3_subr.c index 781b230..244edc9 100644 --- a/src/mp3_subr.c +++ b/src/mp3_subr.c @@ -358,13 +358,17 @@ mp3_lookup_finish(struct lookuphandle *lh) * * data should be a pointer to a file handle * returns 0 on success + * + * Use this function to get a file handle for a *file*, not a + * directory. Example: /Tracks/foo is a file, but not + * /Artist/some_album */ int mp3_file_data_for_path(const char *path, void *data) { struct file_data *fd; fd = (struct file_data *)data; struct lookuphandle *lh; - char *artist, *album, *title; + char *artist, *album, *title_, *title; lh = NULL; fd->fd = -1; @@ -374,9 +378,11 @@ mp3_file_data_for_path(const char *path, void *data) { if (strncmp(path, "/Tracks", 7) == 0) { switch (mp3_numtoken(path)) { case 2: - title = mp3_gettoken(path, 2); - if (title == NULL) - break; + title_ = mp3_gettoken(path, 2); + if (title_ == NULL) break; + title = mp3_basename(title_); + if (title == NULL) break; + lh = mp3_lookup_start(0, fd, mp3_lookup_open, "SELECT filepath FROM song WHERE title LIKE ?"); if (lh == NULL) @@ -390,11 +396,12 @@ mp3_file_data_for_path(const char *path, void *data) { switch (mp3_numtoken(path)) { case 3: album = mp3_gettoken(path, 2); - if (album == NULL) - break; - title = mp3_gettoken(path, 3); - if (title == NULL) - break; + if (album == NULL) break; + title_ = mp3_gettoken(path, 2); + if (title_ == NULL) break; + title = mp3_basename(title_); + if (title == NULL) break; + lh = mp3_lookup_start(0, fd, mp3_lookup_open, "SELECT filepath FROM song WHERE title LIKE ? AND " "album LIKE ?"); @@ -409,13 +416,15 @@ mp3_file_data_for_path(const char *path, void *data) { } else if (strncmp(path, "/Artists", 8) == 0) { switch (mp3_numtoken(path)) { case 4: - artist = mp3_gettoken(path, 2); - album = mp3_gettoken(path, 3); - title = mp3_gettoken(path, 4); - DEBUG("artist(%s) album(%s) title(%s)\n", artist, album, title); - if (!(artist && album && title)) { - break; - } + artist = mp3_gettoken(path, 2); + if (artist == NULL) break; + album = mp3_gettoken(path, 3); + if (album == NULL) break; + title_ = mp3_gettoken(path, 4); + if (title_ == NULL) break; + title = mp3_basename(title_); + if (title == NULL) break; + lh = mp3_lookup_start(0, fd, mp3_lookup_open, "SELECT filepath FROM song WHERE artistname LIKE ? AND " "album LIKE ? AND title LIKE ?"); @@ -599,7 +608,7 @@ mp3_lookup_artist(const char *path, struct filler_data *fd) if (album == NULL) break; lh = mp3_lookup_start(0, fd, mp3_lookup_list, - "SELECT title FROM song, artist " + "SELECT title || '.' || extension FROM song, artist " "WHERE song.artistname = artist.name AND artist.name " "LIKE ? AND song.album LIKE ?"); mp3_lookup_insert(lh, name, LIST_DATATYPE_STRING); diff --git a/src/mp3_vnops.c b/src/mp3_vnops.c index 3260550..5dcf457 100755 --- a/src/mp3_vnops.c +++ b/src/mp3_vnops.c @@ -97,7 +97,7 @@ static int mp3_readdir (const char *path, void *buf, fuse_fill_dir_t filler, return (0); } else if (strcmp(path, "/Tracks") == 0) { lh = mp3_lookup_start(0, &fd, mp3_lookup_list, - "SELECT DISTINCT title FROM song"); + "SELECT DISTINCT title || '.' || extension FROM song"); mp3_lookup_finish(lh); return (0); } else if (strncmp(path, "/Albums", 7) == 0) { |