diff --git a/src/ezstream.c b/src/ezstream.c index 32d32ab..957fe01 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -171,8 +171,8 @@ buildReencodeCommand(const char *extension, const char *fileName, if (strstr(dec_str, PLACEHOLDER_METADATA) != NULL) { if (cfg_get_metadata_program() && cfg_get_metadata_format_str()) { - char *mdataString = stream_get_metadata_str(cfg_get_metadata_format_str(), - mdata); + char *mdataString = metadata_format_string(mdata, + cfg_get_metadata_format_str()); char *tmpStr = replaceString(dec_str, PLACEHOLDER_METADATA, mdataString); xfree(dec_str); @@ -208,8 +208,8 @@ buildReencodeCommand(const char *extension, const char *fileName, if (strstr(enc_str, PLACEHOLDER_METADATA) != NULL) { if (cfg_get_metadata_program() && cfg_get_metadata_format_str()) { - char *mdataString = stream_get_metadata_str(cfg_get_metadata_format_str(), - mdata); + char *mdataString = metadata_format_string(mdata, + cfg_get_metadata_format_str()); char *tmpStr = replaceString(enc_str, PLACEHOLDER_METADATA, mdataString); xfree(enc_str); diff --git a/src/metadata.c b/src/metadata.c index 3f91970..e9a3836 100644 --- a/src/metadata.c +++ b/src/metadata.c @@ -35,6 +35,7 @@ #include +#include "cfg.h" #include "log.h" #include "metadata.h" #include "util.h" @@ -480,3 +481,41 @@ metadata_assemble_string(struct metadata *md) return (str); } + +char * +metadata_format_string(struct metadata *md, const char *format) +{ + char *tmp, *str; + + if (format == NULL) + return (NULL); + + str = xstrdup(format); + + if (strstr(format, PLACEHOLDER_ARTIST) != NULL) { + tmp = replaceString(str, PLACEHOLDER_ARTIST, + metadata_get_artist(md)); + xfree(str); + str = tmp; + } + if (strstr(format, PLACEHOLDER_TITLE) != NULL) { + tmp = replaceString(str, PLACEHOLDER_TITLE, + metadata_get_title(md)); + xfree(str); + str = tmp; + } + if (strstr(format, PLACEHOLDER_STRING) != NULL) { + tmp = replaceString(str, PLACEHOLDER_STRING, + metadata_get_string(md)); + xfree(str); + str = tmp; + } + if (strstr(format, PLACEHOLDER_TRACK) != NULL) { + tmp = replaceString(str, PLACEHOLDER_TRACK, + metadata_get_filename(md)); + xfree(str); + str = tmp; + } + + return (str); +} diff --git a/src/metadata.h b/src/metadata.h index eb95ac0..f517134 100644 --- a/src/metadata.h +++ b/src/metadata.h @@ -111,4 +111,9 @@ int metadata_get_length(metadata_t); */ char * metadata_assemble_string(metadata_t); +/* + * Allocates and returns a metadata string based on a template/format string. + */ +char * metadata_format_string(metadata_t, const char * /* format */); + #endif /* __METADATA_H__ */ diff --git a/src/stream.c b/src/stream.c index cd13c8a..f87ce08 100644 --- a/src/stream.c +++ b/src/stream.c @@ -29,6 +29,7 @@ #include "cfg.h" #include "log.h" +#include "metadata.h" #include "stream.h" #include "util.h" #include "xalloc.h" @@ -363,7 +364,7 @@ stream_set_metadata(struct stream *s, metadata_t md, char **md_str) exit(1); } - songInfo = stream_get_metadata_str(cfg_get_metadata_format_str(), md); + songInfo = metadata_format_string(md, cfg_get_metadata_format_str()); if (songInfo == NULL) { if (artist[0] == '\0' && title[0] == '\0') songInfo = xstrdup(metadata_get_string(md)); @@ -406,44 +407,6 @@ stream_set_metadata(struct stream *s, metadata_t md, char **md_str) return (ret == SHOUTERR_SUCCESS ? 0 : -1); } -char * -stream_get_metadata_str(const char *format, metadata_t mdata) -{ - char *tmp, *str; - - if (format == NULL) - return (NULL); - - str = xstrdup(format); - - if (strstr(format, PLACEHOLDER_ARTIST) != NULL) { - tmp = replaceString(str, PLACEHOLDER_ARTIST, - metadata_get_artist(mdata)); - xfree(str); - str = tmp; - } - if (strstr(format, PLACEHOLDER_TITLE) != NULL) { - tmp = replaceString(str, PLACEHOLDER_TITLE, - metadata_get_title(mdata)); - xfree(str); - str = tmp; - } - if (strstr(format, PLACEHOLDER_STRING) != NULL) { - tmp = replaceString(str, PLACEHOLDER_STRING, - metadata_get_string(mdata)); - xfree(str); - str = tmp; - } - if (strstr(format, PLACEHOLDER_TRACK) != NULL) { - tmp = replaceString(str, PLACEHOLDER_TRACK, - metadata_get_filename(mdata)); - xfree(str); - str = tmp; - } - - return (str); -} - int stream_get_connected(struct stream *s) { diff --git a/src/stream.h b/src/stream.h index b368915..d626764 100644 --- a/src/stream.h +++ b/src/stream.h @@ -32,7 +32,6 @@ stream_t stream_get(const char *); int stream_setup(stream_t); int stream_set_metadata(stream_t, metadata_t, char **); -char * stream_get_metadata_str(const char *, metadata_t); int stream_get_connected(stream_t); int stream_connect(stream_t);