mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Merge branch 'update-icy-metadata' into devel
This commit is contained in:
commit
abfd3c51a3
@ -1164,6 +1164,10 @@ static void command_metadata(client_t *client,
|
||||
|
||||
if (same_ip && plugin && plugin->set_tag) {
|
||||
if (song) {
|
||||
if (artist || title) {
|
||||
ICECAST_LOG_WARN("Metadata request mountpoint %H contains \"song\" but also \"artist\" and/or \"title\"", source->mount);
|
||||
}
|
||||
|
||||
plugin->set_tag (plugin, "song", song, charset);
|
||||
ICECAST_LOG_INFO("Metadata on mountpoint %H changed to \"%H\"", source->mount, song);
|
||||
} else {
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
@ -137,11 +138,16 @@ static void mp3_set_tag (format_plugin_t *plugin, const char *tag, const char *i
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_value)
|
||||
{
|
||||
value = util_conv_string (in_value, charset, plugin->charset);
|
||||
if (in_value) {
|
||||
if (!charset)
|
||||
charset = plugin->charset;
|
||||
|
||||
value = util_conv_string (in_value, charset, "UTF-8");
|
||||
if (value == NULL)
|
||||
value = strdup (in_value);
|
||||
value = strdup(in_value);
|
||||
} else {
|
||||
thread_mutex_unlock(&source_mp3->url_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(tag, "title") == 0 || strcmp(tag, "song") == 0) {
|
||||
@ -159,7 +165,7 @@ static void mp3_set_tag (format_plugin_t *plugin, const char *tag, const char *i
|
||||
}
|
||||
|
||||
|
||||
static void filter_shoutcast_metadata (source_t *source, char *metadata, unsigned int meta_len)
|
||||
static void filter_shoutcast_metadata (source_t *source, char *metadata, unsigned int meta_len, bool update_vc)
|
||||
{
|
||||
if (metadata)
|
||||
{
|
||||
@ -181,7 +187,8 @@ static void filter_shoutcast_metadata (source_t *source, char *metadata, unsigne
|
||||
logging_playlist (source->mount, p, source->listeners);
|
||||
stats_event_conv (source->mount, "title", p, source->format->charset);
|
||||
stats_event_conv (source->mount, "display-title", p, source->format->charset);
|
||||
format_set_vorbiscomment(source->format, MP3_METADATA_TITLE, p);
|
||||
if (update_vc)
|
||||
format_set_vorbiscomment(source->format, MP3_METADATA_TITLE, p);
|
||||
yp_touch (source->mount);
|
||||
free (p);
|
||||
playlist_push_track(source->history, &source->format->vc);
|
||||
@ -218,8 +225,10 @@ static void format_mp3_apply_settings (client_t *client, format_plugin_t *format
|
||||
}
|
||||
}
|
||||
|
||||
if (format->charset == NULL)
|
||||
format->charset = strdup ("ISO8859-1");
|
||||
if (format->charset == NULL) {
|
||||
ICECAST_LOG_INFO("No charset given for mount %#H with source client %zu, assuming ISO8859-1", mount ? mount->mountname : NULL, client->con->id);
|
||||
format->charset = strdup("ISO8859-1");
|
||||
}
|
||||
|
||||
ICECAST_LOG_DEBUG("sending metadata interval %d", source_mp3->interval);
|
||||
ICECAST_LOG_DEBUG("charset %s", format->charset);
|
||||
@ -233,38 +242,56 @@ static void mp3_set_title(source_t *source)
|
||||
{
|
||||
const char streamtitle[] = "StreamTitle='";
|
||||
const char streamurl[] = "StreamUrl='";
|
||||
const char *url_artist = vorbis_comment_query(&source->format->vc, MP3_METADATA_ARTIST, 0);
|
||||
const char *url_title = vorbis_comment_query(&source->format->vc, MP3_METADATA_TITLE, 0);
|
||||
const char *url = vorbis_comment_query(&source->format->vc, MP3_METADATA_URL, 0);
|
||||
const char *in_url_artist = vorbis_comment_query(&source->format->vc, MP3_METADATA_ARTIST, 0);
|
||||
const char *in_url_title = vorbis_comment_query(&source->format->vc, MP3_METADATA_TITLE, 0);
|
||||
const char *in_url = vorbis_comment_query(&source->format->vc, MP3_METADATA_URL, 0);
|
||||
char *url_artist = NULL;
|
||||
char *url_title = NULL;
|
||||
char *url = NULL;
|
||||
size_t size;
|
||||
unsigned char len_byte;
|
||||
refbuf_t *p;
|
||||
unsigned int len = sizeof(streamtitle) + 2; /* the StreamTitle, quotes, ; and null */
|
||||
mp3_state *source_mp3 = source->format->_state;
|
||||
const char *charset = source->format->charset;
|
||||
|
||||
/* make sure the url data does not disappear from under us */
|
||||
thread_mutex_lock (&source_mp3->url_lock);
|
||||
|
||||
/* work out message length */
|
||||
if (url_artist)
|
||||
len += strlen (url_artist);
|
||||
if (url_title)
|
||||
len += strlen (url_title);
|
||||
if (in_url_artist) {
|
||||
url_artist = util_conv_string(in_url_artist, "UTF-8", charset);
|
||||
if (url_artist)
|
||||
len += strlen(url_artist);
|
||||
}
|
||||
|
||||
if (in_url_title) {
|
||||
url_title = util_conv_string(in_url_title, "UTF-8", charset);
|
||||
if (url_title)
|
||||
len += strlen(url_title);
|
||||
}
|
||||
|
||||
if (url_artist && url_title)
|
||||
len += 3;
|
||||
if (source_mp3->inline_url)
|
||||
{
|
||||
|
||||
if (source_mp3->inline_url) {
|
||||
char *end = strstr (source_mp3->inline_url, "';");
|
||||
if (end)
|
||||
len += end - source_mp3->inline_url+2;
|
||||
} else if (in_url) {
|
||||
url = util_conv_string(in_url, "UTF-8", charset);
|
||||
if (url)
|
||||
len += strlen(url) + strlen(streamurl) + 2;
|
||||
}
|
||||
else if (url)
|
||||
len += strlen (url) + strlen (streamurl) + 2;
|
||||
|
||||
#define MAX_META_LEN 255*16
|
||||
if (len > MAX_META_LEN)
|
||||
{
|
||||
thread_mutex_unlock (&source_mp3->url_lock);
|
||||
ICECAST_LOG_WARN("Metadata too long at %d chars", len);
|
||||
free(url_artist);
|
||||
free(url_title);
|
||||
free(url);
|
||||
return;
|
||||
}
|
||||
/* work out the metadata len byte */
|
||||
@ -304,12 +331,16 @@ static void mp3_set_title(source_t *source)
|
||||
snprintf (p->data+r, size-r, "StreamUrl='%s';", url);
|
||||
}
|
||||
ICECAST_LOG_DEBUG("shoutcast metadata block setup with %s", p->data+1);
|
||||
filter_shoutcast_metadata (source, p->data, size);
|
||||
filter_shoutcast_metadata (source, p->data, size, false);
|
||||
|
||||
refbuf_release (source_mp3->metadata);
|
||||
source_mp3->metadata = p;
|
||||
}
|
||||
thread_mutex_unlock (&source_mp3->url_lock);
|
||||
|
||||
free(url_artist);
|
||||
free(url_title);
|
||||
free(url);
|
||||
}
|
||||
|
||||
|
||||
@ -626,7 +657,7 @@ static refbuf_t *mp3_get_filter_meta(source_t *source)
|
||||
if (strncmp (meta->data+1, "StreamTitle=", 12) == 0)
|
||||
{
|
||||
filter_shoutcast_metadata (source, source_mp3->build_metadata,
|
||||
source_mp3->build_metadata_len);
|
||||
source_mp3->build_metadata_len, true);
|
||||
refbuf_release (source_mp3->metadata);
|
||||
source_mp3->metadata = meta;
|
||||
source_mp3->inline_url = strstr (meta->data+1, "StreamUrl='");
|
||||
|
@ -1458,6 +1458,12 @@ char *util_conv_string (const char *string, const char *in_charset, const char *
|
||||
if (string == NULL || in_charset == NULL || out_charset == NULL)
|
||||
return NULL;
|
||||
|
||||
if (strcmp(in_charset, out_charset) == 0) {
|
||||
ret = strdup(string);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
in = xmlFindCharEncodingHandler (in_charset);
|
||||
out = xmlFindCharEncodingHandler (out_charset);
|
||||
|
||||
@ -1467,7 +1473,7 @@ char *util_conv_string (const char *string, const char *in_charset, const char *
|
||||
xmlBufferPtr utf8 = xmlBufferCreate ();
|
||||
xmlBufferPtr conv = xmlBufferCreate ();
|
||||
|
||||
ICECAST_LOG_INFO("converting metadata from %s to %s", in_charset, out_charset);
|
||||
ICECAST_LOG_INFO("converting metadata from %#H to %#H", in_charset, out_charset);
|
||||
xmlBufferCCat (orig, string);
|
||||
if (xmlCharEncInFunc (in, utf8, orig) > 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user