Mercurial > audlegacy-plugins
annotate src/streambrowser/shoutcast.c @ 3199:263c7d983100
alsa-ng: 0.1 sec hard minimum buffer size.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Thu, 23 Jul 2009 14:26:10 -0400 |
parents | 3134a0987162 |
children |
rev | line source |
---|---|
2811 | 1 /* |
2 * Audacious Streambrowser Plugin | |
3 * | |
4 * Copyright (c) 2008 Calin Crisan <ccrisan@gmail.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; under version 3 of the License. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
17 */ | |
18 | |
2570
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 #include <string.h> |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
21 #include <glib.h> |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
22 #include <libxml/parser.h> |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
23 #include <libxml/tree.h> |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2913
diff
changeset
|
24 #include <audlegacy/plugin.h> |
2570
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 #include "streambrowser.h" |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
27 #include "shoutcast.h" |
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 |
2848
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
30 gboolean shoutcast_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
31 { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
32 gchar url[DEF_STRING_LEN]; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
33 g_snprintf(url, DEF_STRING_LEN, SHOUTCAST_CATEGORY_URL, category->name); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
34 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
35 /* generate a valid, temporary filename */ |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
36 char *temp_filename = tempnam(NULL, "aud_sb"); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
37 if (temp_filename == NULL) { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
38 failure("shoutcast: failed to create a temporary file\n"); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
39 return FALSE; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
40 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
41 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
42 char temp_pathname[DEF_STRING_LEN]; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
43 sprintf(temp_pathname, "file://%s", temp_filename); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
44 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
45 debug("shoutcast: fetching category file '%s'\n", url); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
46 if (!fetch_remote_to_local_file(url, temp_pathname)) { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
47 failure("shoutcast: category file '%s' could not be downloaded to '%s'\n", url, temp_pathname); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
48 free(temp_filename); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
49 return FALSE; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
50 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
51 debug("shoutcast: category file '%s' successfuly downloaded to '%s'\n", url, temp_pathname); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
52 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
53 xmlDoc *doc = xmlReadFile(temp_pathname, NULL, 0); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
54 if (doc == NULL) { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
55 failure("shoutcast: failed to read '%s' category file\n", category->name); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
56 free(temp_filename); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
57 return FALSE; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
58 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
59 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
60 xmlNode *root_node = xmlDocGetRootElement(doc); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
61 xmlNode *node; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
62 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
63 root_node = root_node->children; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
64 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
65 for (node = root_node; node != NULL; node = node->next) { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
66 if (node->type == XML_ELEMENT_NODE && !strcmp((char *) node->name, "station")) { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
67 gchar *streaminfo_name = (gchar*) xmlGetProp(node, (xmlChar *) "name"); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
68 gchar *streaminfo_id = (gchar*) xmlGetProp(node, (xmlChar *) "id"); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
69 gchar streaminfo_playlist_url[DEF_STRING_LEN]; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
70 gchar *streaminfo_current_track = (gchar*) xmlGetProp(node, (xmlChar *) "ct"); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
71 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
72 g_snprintf(streaminfo_playlist_url, DEF_STRING_LEN, SHOUTCAST_STREAMINFO_URL, streaminfo_id); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
73 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
74 if (strncmp(streaminfo_playlist_url, streaminfo->playlist_url, DEF_STRING_LEN) == 0) { |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
75 debug("shoutcast: updating stream info for '%s' with id %s from '%s'\n", streaminfo_name, streaminfo_id, url); |
2848
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
76 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
77 strcpy(streaminfo->name, streaminfo_name); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
78 strcpy(streaminfo->playlist_url, streaminfo_playlist_url); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
79 strcpy(streaminfo->current_track, streaminfo_current_track); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
80 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
81 xmlFree(streaminfo_name); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
82 xmlFree(streaminfo_id); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
83 xmlFree(streaminfo_current_track); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
84 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
85 debug("shoutcast: stream info added\n"); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
86 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
87 break; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
88 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
89 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
90 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
91 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
92 xmlFreeDoc(doc); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
93 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
94 if (remove(temp_filename) != 0) { |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
95 failure("shoutcast: cannot remove the temporary file: %s\n", strerror(errno)); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
96 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
97 free(temp_filename); |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
98 |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
99 return TRUE; |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
100 } |
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
101 |
2891 | 102 gboolean shoutcast_category_fetch(streamdir_t *streamdir, category_t *category) |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
103 { |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
104 gchar url[DEF_STRING_LEN]; |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
105 g_snprintf(url, DEF_STRING_LEN, SHOUTCAST_CATEGORY_URL, category->name); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
106 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
107 /* generate a valid, temporary filename */ |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
108 char *temp_filename = tempnam(NULL, "aud_sb"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
109 if (temp_filename == NULL) { |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
110 failure("shoutcast: failed to create a temporary file\n"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
111 return FALSE; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
112 } |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
113 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
114 char temp_pathname[DEF_STRING_LEN]; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
115 sprintf(temp_pathname, "file://%s", temp_filename); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
116 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
117 debug("shoutcast: fetching category file '%s'\n", url); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
118 if (!fetch_remote_to_local_file(url, temp_pathname)) { |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
119 failure("shoutcast: category file '%s' could not be downloaded to '%s'\n", url, temp_pathname); |
2809
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
120 free(temp_filename); |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
121 return FALSE; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
122 } |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
123 debug("shoutcast: category file '%s' successfuly downloaded to '%s'\n", url, temp_pathname); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
124 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
125 xmlDoc *doc = xmlReadFile(temp_pathname, NULL, 0); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
126 if (doc == NULL) { |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
127 failure("shoutcast: failed to read '%s' category file\n", category->name); |
2809
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
128 free(temp_filename); |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
129 return FALSE; |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
130 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
131 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
132 /* free/remove any existing streaminfos in this category */ |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
133 while (streaminfo_get_count(category) > 0) |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
134 streaminfo_remove(category, streaminfo_get_by_index(category, 0)); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
135 |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
136 xmlNode *root_node = xmlDocGetRootElement(doc); |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
137 xmlNode *node; |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
138 |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
139 root_node = root_node->children; |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
140 |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
141 for (node = root_node; node != NULL; node = node->next) { |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
142 if (node->type == XML_ELEMENT_NODE && !strcmp((char *) node->name, "station")) { |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
143 gchar *streaminfo_name = (gchar*) xmlGetProp(node, (xmlChar *) "name"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
144 gchar *streaminfo_id = (gchar*) xmlGetProp(node, (xmlChar *) "id"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
145 gchar streaminfo_playlist_url[DEF_STRING_LEN]; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
146 gchar *streaminfo_current_track = (gchar*) xmlGetProp(node, (xmlChar *) "ct"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
147 |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
148 g_snprintf(streaminfo_playlist_url, DEF_STRING_LEN, SHOUTCAST_STREAMINFO_URL, streaminfo_id); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
149 |
2848
fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
150 debug("shoutcast: adding stream info for '%s/%d' from '%s'\n", streaminfo_name, streaminfo_id, url); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
151 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
152 streaminfo_t *streaminfo = streaminfo_new(streaminfo_name, streaminfo_playlist_url, "", streaminfo_current_track); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
153 streaminfo_add(category, streaminfo); |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
154 |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
155 xmlFree(streaminfo_name); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
156 xmlFree(streaminfo_id); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
157 xmlFree(streaminfo_current_track); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
158 |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
159 debug("shoutcast: stream info added\n"); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
160 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
161 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
162 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
163 xmlFreeDoc(doc); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
164 |
2809
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
165 if (remove(temp_filename) != 0) { |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
166 failure("shoutcast: cannot remove the temporary file: %s\n", strerror(errno)); |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
167 } |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
168 free(temp_filename); |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
169 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
170 return TRUE; |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
171 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
172 |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
173 |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
174 streamdir_t* shoutcast_streamdir_fetch() |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
175 { |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
176 streamdir_t *streamdir = streamdir_new(SHOUTCAST_NAME); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
177 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
178 /* generate a valid, temporary filename */ |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
179 char *temp_filename = tempnam(NULL, "aud_sb"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
180 if (temp_filename == NULL) { |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
181 failure("shoutcast: failed to create a temporary file\n"); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
182 return NULL; |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
183 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
184 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
185 char temp_pathname[DEF_STRING_LEN]; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
186 sprintf(temp_pathname, "file://%s", temp_filename); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
187 |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
188 debug("shoutcast: fetching streaming directory file '%s'\n", SHOUTCAST_STREAMDIR_URL); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
189 if (!fetch_remote_to_local_file(SHOUTCAST_STREAMDIR_URL, temp_pathname)) { |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
190 failure("shoutcast: stream directory file '%s' could not be downloaded to '%s'\n", SHOUTCAST_STREAMDIR_URL, temp_pathname); |
2809
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
191 free(temp_filename); |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
192 return NULL; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
193 } |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
194 debug("shoutcast: stream directory file '%s' successfuly downloaded to '%s'\n", SHOUTCAST_STREAMDIR_URL, temp_pathname); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
195 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
196 xmlDoc *doc = xmlReadFile(temp_pathname, NULL, 0); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
197 if (doc == NULL) { |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
198 failure("shoutcast: failed to read stream directory file\n"); |
2809
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
199 free(temp_filename); |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
200 return NULL; |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
201 } |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
202 |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
203 xmlNode *root_node = xmlDocGetRootElement(doc); |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
204 xmlNode *node; |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
205 |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
206 root_node = root_node->children; |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
207 |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
208 for (node = root_node; node != NULL; node = node->next) { |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
209 if (node->type == XML_ELEMENT_NODE) { |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
210 gchar *category_name = (gchar*) xmlGetProp(node, (xmlChar *) "name"); |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
211 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
212 debug("shoutcast: fetching category '%s'\n", category_name); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
213 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
214 category_t *category = category_new(category_name); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
215 category_add(streamdir, category); |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
216 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
217 xmlFree(category_name); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
218 |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
219 debug("shoutcast: category added\n", category_name); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
220 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
221 } |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
222 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
2811
diff
changeset
|
223 xmlFreeDoc(doc); |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
224 |
2809
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
225 if (remove(temp_filename) != 0) { |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
226 failure("shoutcast: cannot remove the temporary file: %s\n", strerror(errno)); |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
227 } |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
228 free(temp_filename); |
d608b16a710b
fixed temporary files deletion
Calin Crisan ccrisan@gmail.com
parents:
2735
diff
changeset
|
229 |
2735
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
230 debug("shoutcast: streaming directory successfuly loaded\n"); |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
231 |
6d6a3eb67510
some work on the streambrowser
Calin Crisan ccrisan@gmail.com
parents:
2570
diff
changeset
|
232 return streamdir; |
2570
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
233 } |
28498c0bde64
Initial commit for the streambrowser plugin
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
234 |