From df482694c049e4ff378fea6903e8d7fb544769f8 Mon Sep 17 00:00:00 2001 From: moritz Date: Thu, 30 Aug 2007 11:31:33 +0000 Subject: [PATCH] * Back out conversions to ISO8859-1. * Add 'charset=UTF-8' to the metadata update query arguments. The current release of Icecast will ignore it, and the next one will know how to handle it (karl@ is still working on it at this point, but previous diffs worked as advertised.) * If no metadata format string is available and we have both an artist and a title, use the artist/title way of updating instead of the generic "song" interface. git-svn-id: https://svn.xiph.org/trunk/ezstream@13658 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/ezstream.c | 67 +++++++++++++++++++++++++++++++++++--------------- src/util.c | 13 ++-------- src/util.h | 1 - 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/ezstream.c b/src/ezstream.c index ca62e53..10038b9 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -470,7 +470,8 @@ int setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy) { shout_metadata_t *shout_mdata = NULL; - char *songInfo, *encSongInfo; + char *songInfo; + const char *artist, *title; int ret = SHOUTERR_SUCCESS; if (shout == NULL) { @@ -488,37 +489,63 @@ setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy) exit(1); } - if ((songInfo = getMetadataString(pezConfig->metadataFormat, mdata)) == NULL) { - if (strlen(metadata_get_artist(mdata)) == 0 && - strlen(metadata_get_title(mdata)) == 0) - songInfo = xstrdup(metadata_get_string(mdata)); - else - songInfo = metadata_assemble_string(mdata); - } + artist = metadata_get_artist(mdata); + title = metadata_get_title(mdata); - if (strcmp(pezConfig->format, VORBIS_FORMAT) == 0 || - strcmp(pezConfig->format, THEORA_FORMAT) == 0) - encSongInfo = xstrdup(songInfo); - else - encSongInfo = UTF8toISO8859_1(songInfo, ICONV_TRANSLIT); - - if (shout_metadata_add(shout_mdata, "song", (encSongInfo != NULL) ? encSongInfo : "") - != SHOUTERR_SUCCESS) { + /* + * We can do this, because we know how libshout works. This adds + * "charset=UTF-8" to the HTTP metadata update request and has the + * desired effect of letting newer-than-2.3.1 versions of Icecast know + * which encoding we're using. + */ + if (shout_metadata_add(shout_mdata, "charset", "UTF-8") != SHOUTERR_SUCCESS) { /* Assume SHOUTERR_MALLOC */ printf("%s: shout_metadata_add(): %s\n", __progname, strerror(ENOMEM)); exit(1); } + + if ((songInfo = getMetadataString(pezConfig->metadataFormat, mdata)) == NULL) { + if (artist[0] == '\0' && title[0] == '\0') + songInfo = xstrdup(metadata_get_string(mdata)); + else + songInfo = metadata_assemble_string(mdata); + if (artist[0] != '\0' && title[0] != '\0') { + if (shout_metadata_add(shout_mdata, "artist", artist) != SHOUTERR_SUCCESS) { + printf("%s: shout_metadata_add(): %s\n", __progname, + strerror(ENOMEM)); + exit(1); + } + if (shout_metadata_add(shout_mdata, "title", title) != SHOUTERR_SUCCESS) { + printf("%s: shout_metadata_add(): %s\n", __progname, + strerror(ENOMEM)); + exit(1); + } + } else { + if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) { + printf("%s: shout_metadata_add(): %s\n", __progname, + strerror(ENOMEM)); + exit(1); + } + } + } else if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) { + printf("%s: shout_metadata_add(): %s\n", __progname, + strerror(ENOMEM)); + exit(1); + } + if ((ret = shout_set_metadata(shout, shout_mdata)) != SHOUTERR_SUCCESS) printf("%s: shout_set_metadata(): %s\n", __progname, shout_get_error(shout)); + shout_metadata_free(shout_mdata); - if (ret == SHOUTERR_SUCCESS && - mdata_copy != NULL && *mdata_copy == NULL) - *mdata_copy = xstrdup(songInfo); + + if (ret == SHOUTERR_SUCCESS) { + if (mdata_copy != NULL && *mdata_copy == NULL) + *mdata_copy = xstrdup(songInfo); + } xfree(songInfo); - xfree(encSongInfo); return (ret); } diff --git a/src/util.c b/src/util.c index acf33ef..ef2e298 100644 --- a/src/util.c +++ b/src/util.c @@ -236,7 +236,7 @@ CHARtoUTF8(const char *in_str, int mode) setlocale(LC_CTYPE, "C"); # else codeset = (char *)""; -# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE */ +# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE && CODESET */ #else char codeset[24]; @@ -261,7 +261,7 @@ UTF8toCHAR(const char *in_str, int mode) setlocale(LC_CTYPE, "C"); # else codeset = (char *)""; -# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE */ +# endif /* HAVE_NL_LANGINFO && HAVE_SETLOCALE && CODESET */ #else char codeset[24]; @@ -274,15 +274,6 @@ UTF8toCHAR(const char *in_str, int mode) return (iconvert(in_str, "UTF-8", codeset, mode)); } -char * -UTF8toISO8859_1(const char *in_str, int mode) -{ - if (in_str == NULL || strlen(in_str) == 0) - return (NULL); - - return (iconvert(in_str, "UTF-8", "ISO-8859-1", mode)); -} - char * iconvert(const char *in_str, const char *from, const char *to, int mode) { diff --git a/src/util.h b/src/util.h index bec18a2..c2c086d 100644 --- a/src/util.h +++ b/src/util.h @@ -29,6 +29,5 @@ int strrcasecmp(const char *, const char *); shout_t * stream_setup(const char *, const int, const char *); char * CHARtoUTF8(const char *, int); char * UTF8toCHAR(const char *, int); -char * UTF8toISO8859_1(const char *, int); #endif /* __UTIL_H__ */