From cd98caa5fbe1b82c1d27cf4b4f1e33dd71ae3ba5 Mon Sep 17 00:00:00 2001 From: redswitchio Date: Tue, 4 Jul 2017 21:34:58 -0400 Subject: [PATCH] Added additional code needed to support the album field when constructing the metadata string. --- src/cfg.h | 1 + src/ezstream.c | 15 +++++++++++++- src/metadata.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/metadata.h | 8 +++++++- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/cfg.h b/src/cfg.h index 52f7273..252d8ac 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -25,6 +25,7 @@ #define PLACEHOLDER_METADATA "@M@" #define PLACEHOLDER_ARTIST "@a@" #define PLACEHOLDER_TITLE "@t@" +#define PLACEHOLDER_ALBUM "@b@" #define PLACEHOLDER_STRING "@s@" enum cfg_config_type { diff --git a/src/ezstream.c b/src/ezstream.c index 0ed1a53..9d5c2f2 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -124,7 +124,7 @@ buildReencodeCommand(const char *extension, const char *fileName, char *dec_str, *enc_str; char *commandString; size_t commandStringLen; - char *localTitle, *localArtist, *localMetaString; + char *localTitle, *localArtist, *localMetaString, *localAlbum; decoder = cfg_decoder_find(extension); if (!decoder) { @@ -141,6 +141,7 @@ buildReencodeCommand(const char *extension, const char *fileName, localTitle = UTF8toCHAR(metadata_get_title(mdata), ICONV_REPLACE); localArtist = UTF8toCHAR(metadata_get_artist(mdata), ICONV_REPLACE); + localAlbum = UTF8toCHAR(metadata_get_album(mdata), ICONV_REPLACE); localMetaString = UTF8toCHAR(metadata_get_string(mdata), ICONV_REPLACE); @@ -158,6 +159,12 @@ buildReencodeCommand(const char *extension, const char *fileName, xfree(dec_str); dec_str = tmpStr; } + if (strstr(dec_str, PLACEHOLDER_ALBUM) != NULL) { + char *tmpStr = replaceString(dec_str, PLACEHOLDER_ARTIST, + localAlbum); + xfree(dec_str); + dec_str = tmpStr; + } /* * if meta * if (prog && format) @@ -205,6 +212,12 @@ buildReencodeCommand(const char *extension, const char *fileName, xfree(enc_str); enc_str = tmpStr; } + if (strstr(enc_str, PLACEHOLDER_ALBUM) != NULL) { + char *tmpStr = replaceString(enc_str, PLACEHOLDER_ALBUM, + localAlbum); + xfree(enc_str); + enc_str = tmpStr; + } if (strstr(enc_str, PLACEHOLDER_METADATA) != NULL) { if (cfg_get_metadata_program() && cfg_get_metadata_format_str()) { diff --git a/src/metadata.c b/src/metadata.c index e9a3836..d3d43f7 100644 --- a/src/metadata.c +++ b/src/metadata.c @@ -53,6 +53,7 @@ struct metadata { char *string; char *artist; char *title; + char *album; int songLen; int normalize; int program; @@ -134,6 +135,13 @@ metadata_get(struct metadata *md, FILE **filep) free(str); } + str = taglib_tag_album(tt); + if (str != NULL) { + if (strlen(str) > 0) + md->album = xstrdup(str); + free(str); + } + md->songLen = taglib_audioproperties_length(ta); taglib_file_free(tf); @@ -154,6 +162,10 @@ metadata_clean_md(struct metadata *md) xfree(md->title); md->title = NULL; } + if (md->album != NULL) { + xfree(md->title); + md->album = NULL; + } } static char * @@ -190,6 +202,7 @@ metadata_process_md(struct metadata *md) metadata_normalize_string(&md->string); metadata_normalize_string(&md->artist); metadata_normalize_string(&md->title); + metadata_normalize_string(&md->album); } } @@ -317,7 +330,8 @@ metadata_program_update(struct metadata *md, enum metadata_request md_req) metadata_clean_md(md); if (!metadata_program_update(md, METADATA_STRING) || !metadata_program_update(md, METADATA_ARTIST) || - !metadata_program_update(md, METADATA_TITLE)) + !metadata_program_update(md, METADATA_TITLE) || + !metadata_program_update(md, METADATA_ALBUM)) return (0); else return (1); @@ -342,6 +356,13 @@ metadata_program_update(struct metadata *md, enum metadata_request md_req) md->title = NULL; } break; + case METADATA_ALBUM: + snprintf(command, sizeof(command), "%s album", md->filename); + if (md->album != NULL) { + xfree(md->album); + md->album = NULL; + } + break; default: log_alert("metadata_program_update: unknown md_req"); abort(); @@ -395,6 +416,10 @@ metadata_program_update(struct metadata *md, enum metadata_request md_req) if (strlen(buf) > 0) md->title = xstrdup(buf); break; + case METADATA_ALBUM: + if (strlen(buf) > 0) + md->album = xstrdup(buf); + break; case METADATA_ALL: default: log_alert("metadata_program_update: METADATA_ALL in code unreachable by METADATA_ALL"); @@ -405,6 +430,7 @@ metadata_program_update(struct metadata *md, enum metadata_request md_req) metadata_normalize_string(&md->string); metadata_normalize_string(&md->artist); metadata_normalize_string(&md->title); + metadata_normalize_string(&md->album); } return (1); @@ -426,6 +452,15 @@ metadata_get_artist(struct metadata *md) return (md->artist); } +const char * +metadata_get_album(struct metadata *md) +{ + if (md->album == NULL) + return (blankString); + else + return (md->album); +} + const char * metadata_get_title(struct metadata *md) { @@ -457,7 +492,7 @@ metadata_assemble_string(struct metadata *md) size_t len; char *str; - if (md->artist == NULL && md->title == NULL && md->program == 0) + if (md->artist == NULL && md->title == NULL && md->album && md->program == 0) return (metadata_get_name(md->filename)); len = 0; @@ -468,6 +503,11 @@ metadata_assemble_string(struct metadata *md) len += strlen(" - "); len += strlen(md->title); } + if (md->album != NULL) { + if (len > 0) + len += strlen(" - "); + len += strlen(md->album); + } len++; str = xcalloc(len, sizeof(char)); @@ -478,6 +518,11 @@ metadata_assemble_string(struct metadata *md) strlcat(str, " - ", len); strlcat(str, md->title, len); } + if (md->album != NULL) { + if (md->artist != NULL || md->title != NULL) + strlcat(str, " - ", len); + strlcat(str, md->album, len); + } return (str); } @@ -516,6 +561,12 @@ metadata_format_string(struct metadata *md, const char *format) xfree(str); str = tmp; } + if (strstr(format, PLACEHOLDER_ALBUM) != NULL) { + tmp = replaceString(str, PLACEHOLDER_ALBUM, + metadata_get_album(md)); + xfree(str); + str = tmp; + } return (str); } diff --git a/src/metadata.h b/src/metadata.h index f517134..6293616 100644 --- a/src/metadata.h +++ b/src/metadata.h @@ -23,7 +23,8 @@ enum metadata_request { METADATA_ALL = 0, METADATA_STRING, METADATA_ARTIST, - METADATA_TITLE + METADATA_TITLE, + METADATA_ALBUM }; typedef struct metadata * metadata_t; @@ -88,6 +89,11 @@ const char * metadata_get_string(metadata_t); */ const char * metadata_get_artist(metadata_t); +/* + * Returns a pointer to the album string, which may be empty. + */ +const char * metadata_get_album(metadata_t); + /* * Returns a pointer to the title string, which may be empty. */