From de1b1c3805bd055f1a3f44ab127d8514cb5bff34 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Mon, 11 May 2020 17:02:14 +0200 Subject: [PATCH] [cfg] Remove hardcoding of strings for unknown album etc Now configurable, since we don't have real localisation --- src/conffile.c | 5 +++++ src/conffile.h | 7 +++++++ src/db.c | 10 +++++----- src/httpd_dacp.c | 30 ++++++++++++++---------------- src/lastfm.c | 2 +- src/library/filescanner_itunes.c | 2 +- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/conffile.c b/src/conffile.c index 2325917d..924b2c4d 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -90,6 +90,11 @@ static cfg_opt_t sec_library[] = CFG_STR("name_podcasts", "Podcasts", CFGF_NONE), CFG_STR("name_audiobooks", "Audiobooks", CFGF_NONE), CFG_STR("name_radio", "Radio", CFGF_NONE), + CFG_STR("name_unknown_title", "Unknown title", CFGF_NONE), + CFG_STR("name_unknown_artist", "Unknown artist", CFGF_NONE), + CFG_STR("name_unknown_album", "Unknown album", CFGF_NONE), + CFG_STR("name_unknown_genre", "Unknown genre", CFGF_NONE), + CFG_STR("name_unknown_composer", "Unknown composer", CFGF_NONE), CFG_STR_LIST("artwork_basenames", "{artwork,cover,Folder}", CFGF_NONE), CFG_BOOL("artwork_individual", cfg_false, CFGF_NONE), CFG_STR_LIST("artwork_online_sources", NULL, CFGF_NONE), diff --git a/src/conffile.h b/src/conffile.h index ed145027..743e381f 100644 --- a/src/conffile.h +++ b/src/conffile.h @@ -9,6 +9,13 @@ #define CONFFILE CONFDIR "/forked-daapd.conf" +// Some shorthand macros for poor man's +#define CFG_NAME_UNKNOWN_TITLE (cfg_getstr(cfg_getsec(cfg, "library"), "name_unknown_title")) +#define CFG_NAME_UNKNOWN_ARTIST (cfg_getstr(cfg_getsec(cfg, "library"), "name_unknown_artist")) +#define CFG_NAME_UNKNOWN_ALBUM (cfg_getstr(cfg_getsec(cfg, "library"), "name_unknown_album")) +#define CFG_NAME_UNKNOWN_GENRE (cfg_getstr(cfg_getsec(cfg, "library"), "name_unknown_genre")) +#define CFG_NAME_UNKNOWN_COMPOSER (cfg_getstr(cfg_getsec(cfg, "library"), "name_unknown_composer")) + extern cfg_t *cfg; extern uint64_t libhash; extern uid_t runas_uid; diff --git a/src/db.c b/src/db.c index 792502c7..1244f84c 100644 --- a/src/db.c +++ b/src/db.c @@ -907,7 +907,7 @@ fixup_defaults(char **tag, enum fixup_type fixup, struct fixup_ctx *ctx) else if (ctx->queue_item && ctx->queue_item->path) *tag = strdup(ctx->queue_item->path); else - *tag = strdup("Unknown title"); + *tag = strdup(CFG_NAME_UNKNOWN_TITLE); break; case DB_FIXUP_ARTIST: @@ -925,7 +925,7 @@ fixup_defaults(char **tag, enum fixup_type fixup, struct fixup_ctx *ctx) else if (ctx->mfi && ctx->mfi->tv_series_name) *tag = strdup(ctx->mfi->tv_series_name); else - *tag = strdup("Unknown artist"); + *tag = strdup(CFG_NAME_UNKNOWN_ARTIST); break; case DB_FIXUP_ALBUM: @@ -935,7 +935,7 @@ fixup_defaults(char **tag, enum fixup_type fixup, struct fixup_ctx *ctx) if (ctx->mfi && ctx->mfi->tv_series_name) *tag = safe_asprintf("%s, Season %u", ctx->mfi->tv_series_name, ctx->mfi->tv_season_num); else - *tag = strdup("Unknown album"); + *tag = strdup(CFG_NAME_UNKNOWN_ALBUM); break; case DB_FIXUP_ALBUM_ARTIST: // Will be set after artist, because artist (must) come first in the col_maps @@ -955,14 +955,14 @@ fixup_defaults(char **tag, enum fixup_type fixup, struct fixup_ctx *ctx) else if (ctx->queue_item && ctx->queue_item->artist) *tag = strdup(ctx->queue_item->artist); else - *tag = strdup("Unknown artist"); + *tag = strdup(CFG_NAME_UNKNOWN_ARTIST); break; case DB_FIXUP_GENRE: if (*tag) break; - *tag = strdup("Unknown genre"); + *tag = strdup(CFG_NAME_UNKNOWN_GENRE); break; case DB_FIXUP_MEDIA_KIND: diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index 5725e004..64af5eea 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -150,22 +150,8 @@ static struct event *seek_timer; static int seek_target; /* If an item is removed from the library while in the queue, we replace it with this */ -static struct media_file_info dummy_mfi = -{ - .id = DB_MEDIA_FILE_NON_PERSISTENT_ID, - .title = "(unknown title)", - .artist = "(unknown artist)", - .album = "(unknown album)", - .genre = "(unknown genre)", -}; -static struct db_queue_item dummy_queue_item = -{ - .file_id = DB_MEDIA_FILE_NON_PERSISTENT_ID, - .title = "(unknown title)", - .artist = "(unknown artist)", - .album = "(unknown album)", - .genre = "(unknown genre)", -}; +static struct media_file_info dummy_mfi; +static struct db_queue_item dummy_queue_item; /* -------------------------------- HELPERS --------------------------------- */ @@ -2909,6 +2895,18 @@ dacp_init(void) current_rev = 2; update_requests = NULL; + dummy_mfi.id = DB_MEDIA_FILE_NON_PERSISTENT_ID; + dummy_mfi.title = CFG_NAME_UNKNOWN_TITLE; + dummy_mfi.artist = CFG_NAME_UNKNOWN_ARTIST; + dummy_mfi.album = CFG_NAME_UNKNOWN_ALBUM; + dummy_mfi.genre = CFG_NAME_UNKNOWN_GENRE; + + dummy_queue_item.file_id = DB_MEDIA_FILE_NON_PERSISTENT_ID; + dummy_queue_item.title = CFG_NAME_UNKNOWN_TITLE; + dummy_queue_item.artist = CFG_NAME_UNKNOWN_ARTIST; + dummy_queue_item.album = CFG_NAME_UNKNOWN_ALBUM; + dummy_queue_item.genre = CFG_NAME_UNKNOWN_GENRE; + #ifdef HAVE_EVENTFD update_efd = eventfd(0, EFD_CLOEXEC); if (update_efd < 0) diff --git a/src/lastfm.c b/src/lastfm.c index 08c6253a..3d15326b 100644 --- a/src/lastfm.c +++ b/src/lastfm.c @@ -277,7 +277,7 @@ scrobble(int id) goto noscrobble; // Don't scrobble songs with unknown artist - if (strcmp(mfi->artist, "Unknown artist") == 0) + if (strcmp(mfi->artist, CFG_NAME_UNKNOWN_ARTIST) == 0) goto noscrobble; kv = keyval_alloc(); diff --git a/src/library/filescanner_itunes.c b/src/library/filescanner_itunes.c index 86a1d177..385eaae2 100644 --- a/src/library/filescanner_itunes.c +++ b/src/library/filescanner_itunes.c @@ -545,7 +545,7 @@ process_track_file(plist_t trk) /* Don't let album_artist set to "Unknown artist" if we've * filled artist from the iTunes data in the meantime */ - if (strcmp(mfi->album_artist, "Unknown artist") == 0) + if (strcmp(mfi->album_artist, CFG_NAME_UNKNOWN_ARTIST) == 0) { free(mfi->album_artist); mfi->album_artist = strdup(mfi->artist);