1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Put "get_metadata_str()" where it belongs

This commit is contained in:
Moritz Grimm 2016-05-19 14:37:21 +02:00
parent 3135c9e517
commit b1aecc835a
5 changed files with 50 additions and 44 deletions

View File

@ -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);

View File

@ -35,6 +35,7 @@
#include <taglib/tag_c.h>
#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);
}

View File

@ -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__ */

View File

@ -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)
{

View File

@ -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);