Mercurial > audlegacy-plugins
diff src/streambrowser/shoutcast.c @ 2889:6c53f9fa9029
Backed out changeset 59ff744e1e23
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Aug 2008 20:29:49 +0300 |
parents | fbb32674bfd2 |
children | c27da2c06805 |
line wrap: on
line diff
--- a/src/streambrowser/shoutcast.c Fri Aug 01 22:55:49 2008 +0300 +++ b/src/streambrowser/shoutcast.c Tue Aug 12 20:29:49 2008 +0300 @@ -27,6 +27,78 @@ #include "shoutcast.h" +gboolean shoutcast_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) +{ + gchar url[DEF_STRING_LEN]; + g_snprintf(url, DEF_STRING_LEN, SHOUTCAST_CATEGORY_URL, category->name); + + /* generate a valid, temporary filename */ + char *temp_filename = tempnam(NULL, "aud_sb"); + if (temp_filename == NULL) { + failure("shoutcast: failed to create a temporary file\n"); + return FALSE; + } + + char temp_pathname[DEF_STRING_LEN]; + sprintf(temp_pathname, "file://%s", temp_filename); + + debug("shoutcast: fetching category file '%s'\n", url); + if (!fetch_remote_to_local_file(url, temp_pathname)) { + failure("shoutcast: category file '%s' could not be downloaded to '%s'\n", url, temp_pathname); + free(temp_filename); + return FALSE; + } + debug("shoutcast: category file '%s' successfuly downloaded to '%s'\n", url, temp_pathname); + + xmlDoc *doc = xmlReadFile(temp_pathname, NULL, 0); + if (doc == NULL) { + failure("shoutcast: failed to read '%s' category file\n", category->name); + free(temp_filename); + return FALSE; + } + + xmlNode *root_node = xmlDocGetRootElement(doc); + xmlNode *node; + + root_node = root_node->children; + + for (node = root_node; node != NULL; node = node->next) { + if (node->type == XML_ELEMENT_NODE && !strcmp((char *) node->name, "station")) { + gchar *streaminfo_name = (gchar*) xmlGetProp(node, (xmlChar *) "name"); + gchar *streaminfo_id = (gchar*) xmlGetProp(node, (xmlChar *) "id"); + gchar streaminfo_playlist_url[DEF_STRING_LEN]; + gchar *streaminfo_current_track = (gchar*) xmlGetProp(node, (xmlChar *) "ct"); + + g_snprintf(streaminfo_playlist_url, DEF_STRING_LEN, SHOUTCAST_STREAMINFO_URL, streaminfo_id); + + if (strncmp(streaminfo_playlist_url, streaminfo->playlist_url, DEF_STRING_LEN) == 0) { + debug("shoutcast: updating stream info for '%s/%d' from '%s'\n", streaminfo_name, streaminfo_id, url); + + strcpy(streaminfo->name, streaminfo_name); + strcpy(streaminfo->playlist_url, streaminfo_playlist_url); + strcpy(streaminfo->current_track, streaminfo_current_track); + + xmlFree(streaminfo_name); + xmlFree(streaminfo_id); + xmlFree(streaminfo_current_track); + + debug("shoutcast: stream info added\n"); + + break; + } + } + } + + xmlFreeDoc(doc); + + if (remove(temp_filename) != 0) { + failure("shoutcast: cannot remove the temporary file: %s\n", strerror(errno)); + } + free(temp_filename); + + return TRUE; +} + gboolean shoutcast_category_fetch(category_t *category) { gchar url[DEF_STRING_LEN]; @@ -75,7 +147,7 @@ g_snprintf(streaminfo_playlist_url, DEF_STRING_LEN, SHOUTCAST_STREAMINFO_URL, streaminfo_id); - debug("shoutcast: fetching stream info for '%s/%d' from '%s'\n", streaminfo_name, streaminfo_id, url); + debug("shoutcast: adding stream info for '%s/%d' from '%s'\n", streaminfo_name, streaminfo_id, url); streaminfo_t *streaminfo = streaminfo_new(streaminfo_name, streaminfo_playlist_url, "", streaminfo_current_track); streaminfo_add(category, streaminfo);