From 2fe97f44ea7ebc3bcde0f2e108ba94c34a296c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Jul 2007 14:50:02 +0200 Subject: Handle transparently redirect done through m3u playlists. Thanks to Harald Sitter from Amarok team for reporting a testcase. --- src/input/input_http.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/input/input_http.c b/src/input/input_http.c index d28fa75ab..934e6a9f6 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -666,6 +666,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { int buflen; int use_proxy; int proxyport; + int mpegurl_redirect = 0; use_proxy = this_class->proxyhost && strlen(this_class->proxyhost); @@ -889,6 +890,16 @@ static int http_plugin_open (input_plugin_t *this_gen ) { return http_plugin_open(this_gen); } + { + static const char mpegurl_ct_str[] = "Content-Type: audio/x-mpegurl"; + static const size_t mpegurl_ct_size = sizeof(mpegurl_ct_str)-1; + if (!strncasecmp(this->buf, mpegurl_ct_str, mpegurl_ct_size)) { + lprintf("Opening an audio/x-mpegurl file, late redirect."); + + mpegurl_redirect = 1; + } + } + /* Icecast / ShoutCast Stuff */ if (!strncasecmp(this->buf, TAG_ICY_NAME, sizeof(TAG_ICY_NAME) - 1)) { _x_meta_info_set(this->stream, XINE_META_INFO_ALBUM, @@ -952,6 +963,30 @@ static int http_plugin_open (input_plugin_t *this_gen ) { lprintf ("end of headers\n"); + if ( mpegurl_redirect ) { + char buf[4096] = { 0, }; + char *newline = NULL; + + http_plugin_read_int(this, buf, 4095); + newline = strstr(buf, "\r\n"); + + /* If the newline can't be found, either the 4K buffer is too small, or + * more likely something is fuzzy. + */ + if ( newline ) { + char *href; + + *newline = '\0'; + + lprintf("mpegurl pointing to %s\n", buf); + + href = _x_canonicalise_url (this->mrl, buf); + free(this->mrl); + this->mrl = href; + return http_plugin_open(this_gen); + } + } + /* * fill preview buffer */ -- cgit v1.2.3