Mercurial > audlegacy-plugins
diff src/streambrowser/shoutcast.c @ 2848:fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
author | Calin Crisan ccrisan@gmail.com |
---|---|
date | Mon, 28 Jul 2008 23:43:31 +0300 |
parents | cc6f02424609 |
children | c27da2c06805 |
line wrap: on
line diff
--- a/src/streambrowser/shoutcast.c Fri Jul 25 12:03:16 2008 +0300 +++ b/src/streambrowser/shoutcast.c Mon Jul 28 23:43:31 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);