From 48b7cd9a05396e13bbc1f5a7e9a6f44e87866da5 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sun, 14 Jul 2013 20:54:23 +0200 Subject: [PATCH] Adds looking for artwork named [directory name].{png,jpg} --- README | 7 ++++++ src/artwork.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/README b/README index a6f39a35..cae37b11 100644 --- a/README +++ b/README @@ -223,15 +223,22 @@ As for the naming convention, it is quite simple; consider your foo.mp3 song, residing at /bar/foo.mp3: - if /bar/foo.{png,jpg} exists, this will be used as the artwork for this file; - failing that, if /bar/{artwork,cover}.{png,jpg} exists, it will be used. + - failing that, if /bar/bar.{png,jpg} exists, it will be used For "groups" (same album name and album artist), the situation is a bit different: - if a file {artwork,cover}.{png,jpg} is found in one of the directories containing files that are part of the group, it is used as the artwork. The first file found is used, ordering is not guaranteed; + - failing that, if [directory name].{png,jpg} is found in one of the + directories containing files that are part of the group, it is used as the + artwork. The first file found is used, ordering is not guaranteed; - failing that, individual files are examined and the first artwork found is used. Here again, ordering is not guaranteed. +{artwork,cover} are the default, you can add other base names in the +configuration file. + You can use symlinks for the artwork files; the artwork is not scanned/indexed in any way in the database and there is no caching on forked-daapd's side. diff --git a/src/artwork.c b/src/artwork.c index 7eacd07b..faa3826e 100644 --- a/src/artwork.c +++ b/src/artwork.c @@ -47,7 +47,7 @@ static const char *cover_extension[] = { - "png", "jpg", + "jpg", "png", }; @@ -728,6 +728,64 @@ artwork_get_dir_image(char *path, int isdir, int max_w, int max_h, int format, s return artwork_get(artwork, max_w, max_h, format, evbuf); } +static int +artwork_get_parentdir_image(char *path, int isdir, int max_w, int max_h, int format, struct evbuffer *evbuf) +{ + char artwork[PATH_MAX]; + char parentdir[PATH_MAX]; + char *ptr; + int len; + int i; + int ret; + + ret = snprintf(artwork, sizeof(artwork), "%s", path); + if ((ret < 0) || (ret >= sizeof(artwork))) + { + DPRINTF(E_INFO, L_ART, "Artwork path exceeds PATH_MAX\n"); + + return -1; + } + + if (!isdir) + { + ptr = strrchr(artwork, '/'); + if (ptr) + *ptr = '\0'; + } + + ptr = strrchr(artwork, '/'); + if ((!ptr) || (strlen(ptr) <= 1)) + return -1; + strcpy(parentdir, ptr + 1); + + len = strlen(artwork); + + for (i = 0; i < (sizeof(cover_extension) / sizeof(cover_extension[0])); i++) + { + ret = snprintf(artwork + len, sizeof(artwork) - len, "/%s.%s", parentdir, cover_extension[i]); + if ((ret < 0) || (ret >= sizeof(artwork) - len)) + { + DPRINTF(E_INFO, L_ART, "Artwork path exceeds PATH_MAX (%s.%s)\n", parentdir, cover_extension[i]); + + continue; + } + + DPRINTF(E_DBG, L_ART, "Trying parent directory artwork file %s\n", artwork); + + ret = access(artwork, F_OK); + if (ret < 0) + continue; + + break; + } + + if (i == (sizeof(cover_extension) / sizeof(cover_extension[0]))) + return -1; + + return artwork_get(artwork, max_w, max_h, format, evbuf); +} + + int artwork_get_item_filename(char *filename, int max_w, int max_h, int format, struct evbuffer *evbuf) @@ -746,6 +804,11 @@ artwork_get_item_filename(char *filename, int max_w, int max_h, int format, stru if (ret > 0) return ret; + /* Look for parentdir(filename).{png,jpg} */ + ret = artwork_get_parentdir_image(filename, 0, max_w, max_h, format, evbuf); + if (ret > 0) + return ret; + return -1; } @@ -800,6 +863,8 @@ artwork_get_group(int id, int max_w, int max_h, int format, struct evbuffer *evb while ((got_art < 0) && ((ret = db_query_fetch_string(&qp, &dir)) == 0) && (dir)) { got_art = artwork_get_dir_image(dir, 1, max_w, max_h, format, evbuf); + if (got_art < 0) + got_art = artwork_get_parentdir_image(dir, 1, max_w, max_h, format, evbuf); } db_query_end(&qp);