1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-12-04 14:46:31 -05:00

Merge branch 'redswitchio-feature/album_metadata' into develop

This commit is contained in:
Moritz Grimm 2017-07-06 14:37:30 +02:00
commit 4e1c128493
5 changed files with 82 additions and 4 deletions

View File

@ -635,6 +635,13 @@ Available in
.Li /ezstream/encoders/encoder/program
and
.Li /ezstream/metadata/format_str .
.It Sy @b@
Replaced with the album information.
Available in
.Li /ezstream/decoders/decoder/program ,
.Li /ezstream/encoders/encoder/program
and
.Li /ezstream/metadata/format_str .
.It Sy @s@
Replaced with the string returned by
.Li /ezstream/metadata/program

View File

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

View File

@ -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_ALBUM,
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()) {

View File

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

View File

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