annotate src/streambrowser/shoutcast.c @ 2593:f4dce14ed238

Indentation cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 21 May 2008 00:46:06 +0300
parents 28498c0bde64
children 6d6a3eb67510
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2570
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
1
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
2 #include <string.h>
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
3 #include <glib.h>
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
4 #include <libxml/parser.h>
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
5 #include <libxml/tree.h>
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
6
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
7 #include "streambrowser.h"
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
8 #include "shoutcast.h"
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
9
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
10
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
11 static streaminfo_t* shoutcast_streaminfo_fetch(gchar *station_name, gchar *station_id);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
12 static category_t* shoutcast_category_fetch(gchar *category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
13
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
14
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
15 static streaminfo_t *shoutcast_streaminfo_fetch(gchar *station_name, gchar *station_id)
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
16 {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
17 gchar url[DEF_STRING_LEN];
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
18 g_snprintf(url, DEF_STRING_LEN, SHOUTCAST_STREAMINFO_URL, station_id);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
19
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
20 streaminfo_t *streaminfo = streaminfo_new(station_name, url);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
21
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
22 // todo: read the .pls file fetched from the above url
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
23
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
24 return streaminfo;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
25 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
26
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
27 static category_t *shoutcast_category_fetch(gchar *category_name)
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
28 {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
29 category_t *category = category_new(category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
30
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
31 gchar url[DEF_STRING_LEN];
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
32 g_snprintf(url, DEF_STRING_LEN, SHOUTCAST_CATEGORY_URL, category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
33
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
34 xmlDoc *doc = xmlReadFile(url, NULL, 0);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
35 if (doc == NULL) {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
36 error(" shoutcast: failed to read \"%s\" category file\n", category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
37 return NULL;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
38 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
39
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
40 debug(" shoutcast: category file fetched\n");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
41
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
42 xmlNode *root_node = xmlDocGetRootElement(doc);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
43 xmlNode *node;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
44
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
45 root_node = root_node->children;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
46
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
47 for (node = root_node; node != NULL; node = node->next) {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
48 if (node->type == XML_ELEMENT_NODE && !strcmp((char *) node->name, "station")) {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
49 gchar *station_name = (gchar*) xmlGetProp(node, (xmlChar *) "name");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
50 gchar *station_id = (gchar*) xmlGetProp(node, (xmlChar *) "id");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
51
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
52 debug(" shoutcast: fetching stream info for name = \"%s\" and id = %s\n", station_name, station_id);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
53
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
54 streaminfo_t *streaminfo = shoutcast_streaminfo_fetch(station_name, station_id);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
55 streaminfo_add(category, streaminfo);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
56
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
57 // todo: debug - print info about streaminfon urls
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
58 debug(" shoutcast: stream info added for name = \"%s\" and id = %s\n", station_name, station_id);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
59 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
60 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
61
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
62 return category;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
63 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
64
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
65
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
66 streamdir_t* shoutcast_streamdir_fetch()
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
67 {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
68 streamdir_t *streamdir = streamdir_new("Shoutcast");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
69
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
70 debug("shoutcast: fetching streaming directory file\n");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
71
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
72 // todo: replace dummy filename with SHOUTCAST_DIRECTORY_URL
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
73 xmlDoc *doc = xmlReadFile("shoutcast.xml", NULL, 0);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
74 if (doc == NULL) {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
75 error("shoutcast: failed to read stream directory file\n");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
76 return NULL;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
77 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
78
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
79 debug("shoutcast: streaming directory file fetched\n");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
80
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
81 xmlNode *root_node = xmlDocGetRootElement(doc);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
82 xmlNode *node;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
83
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
84 root_node = root_node->children;
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
85
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
86 for (node = root_node; node != NULL; node = node->next) {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
87 if (node->type == XML_ELEMENT_NODE) {
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
88 gchar *category_name = (gchar*) xmlGetProp(node, (xmlChar *) "name");
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
89
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
90 debug(" shoutcast: fetching category \"%s\"\n", category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
91
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
92 category_t *category = shoutcast_category_fetch(category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
93 category_add(streamdir, category);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
94
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
95 debug(" shoutcast: added category \"%s\"\n", category_name);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
96 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
97 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
98
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
99 exit(0);
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
100 }
28498c0bde64 Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff changeset
101