Mercurial > audlegacy-plugins
annotate src/streambrowser/xiph.c @ 3047:4434b4c4a715
ported EsounD plugin
author | Andrew O. Shadoura <bugzilla@tut.by> |
---|---|
date | Fri, 17 Apr 2009 16:17:10 +0300 |
parents | 3134a0987162 |
children |
rev | line source |
---|---|
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
1 /* |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
2 * Audacious Streambrowser Plugin |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
3 * |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
4 * Copyright (c) 2008 Calin Crisan <ccrisan@gmail.com> |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
5 * |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
8 * the Free Software Foundation; under version 3 of the License. |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
9 * |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
14 * |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
16 * along with this program. If not, see <http://www.gnu.org/licenses>. |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
17 */ |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
18 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
19 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
20 #include <string.h> |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
21 #include <glib.h> |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
22 #include <libxml/parser.h> |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
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:
2895
diff
changeset
|
24 #include <audlegacy/plugin.h> |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
25 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
26 #include "streambrowser.h" |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
27 #include "xiph.h" |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
28 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
29 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
30 typedef struct { |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
31 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
32 gchar name[DEF_STRING_LEN]; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
33 gchar url[DEF_STRING_LEN]; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
34 gchar current_song[DEF_STRING_LEN]; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
35 gchar genre[DEF_STRING_LEN]; |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
36 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
37 } xiph_entry_t; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
38 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
39 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
40 static xiph_entry_t *xiph_entries = NULL; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
41 static int xiph_entry_count = 0; |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
42 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
43 typedef struct { |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
44 |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
45 gchar *name; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
46 gchar *match_string; |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
47 |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
48 } xiph_category_t; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
49 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
50 /* inspired from streamtuner's xiph plugin */ |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
51 static xiph_category_t xiph_categories[] = { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
52 { "Alternative", "alternative indie goth college industrial punk hardcore ska" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
53 { "Electronic", "electronic ambient drum trance techno house downtempo breakbeat jungle garage" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
54 { "Classical", "classical opera symphonic" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
55 { "Country", "country swing" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
56 { "Hip-Hop/Rap", "hip hop rap turntable" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
57 { "Jazz", "jazz swing" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
58 { "Oldies", "oldies disco 50s 60s 70s 80s 90s" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
59 { "Rop", "top pop" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
60 { "Rock", "rock metal" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
61 { "R&B/Soul", "r&b funk soul urban" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
62 { "Spiritual", "spiritual gospel christian muslim jewish religio" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
63 { "Spoken", "spoken talk comedy" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
64 { "World", "world reggae island african european east asia" }, |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
65 { "Other", "various mixed misc eclectic film show instrumental" } |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
66 }; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
67 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
68 |
2895 | 69 static void refresh_streamdir(void); |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
70 /* returns true if any of the words in string1 is present in string2 */ |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
71 static gboolean genre_match(gchar *string1, gchar *string2); |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
72 |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
73 gboolean xiph_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
74 { |
2895 | 75 gint entryno; |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
76 |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
77 refresh_streamdir(); |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
78 |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
79 /* find the corresponding xiph entry */ |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
80 for (entryno = 0; entryno < xiph_entry_count; entryno++) { |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
81 if (strcmp(xiph_entries[entryno].name, streaminfo->name) == 0) { |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
82 strcpy(streaminfo->name, xiph_entries[entryno].name); |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
83 strcpy(streaminfo->url, xiph_entries[entryno].url); |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
84 strcpy(streaminfo->current_track, xiph_entries[entryno].current_song); |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
85 |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
86 break; |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
87 } |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
88 } |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
89 |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
90 return TRUE; |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
91 } |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
92 |
2891 | 93 gboolean xiph_category_fetch(streamdir_t *streamdir, category_t *category) |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
94 { |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
95 refresh_streamdir(); |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
96 |
2895 | 97 gint entryno, categoryno; |
98 gint xiph_category_count = sizeof(xiph_categories) / sizeof(xiph_category_t); | |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
99 xiph_category_t *xiph_category = NULL; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
100 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
101 for (categoryno = 0; categoryno < xiph_category_count; categoryno++) |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
102 if (strcmp(xiph_categories[categoryno].name, category->name) == 0) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
103 xiph_category = xiph_categories + categoryno; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
104 break; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
105 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
106 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
107 /* somehow we've got an invalid/unrecognized category */ |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
108 if (xiph_category == NULL) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
109 failure("xiph: got an unrecognized category: '%s'\n", category->name); |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
110 return FALSE; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
111 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
112 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
113 /* free/remove any existing streaminfos in this category */ |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
114 while (streaminfo_get_count(category) > 0) |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
115 streaminfo_remove(category, streaminfo_get_by_index(category, 0)); |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
116 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
117 /* see what entries match this category */ |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
118 for (entryno = 0; entryno < xiph_entry_count; entryno++) { |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
119 if (genre_match(xiph_category->match_string, xiph_entries[entryno].genre)) { |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
120 streaminfo_t *streaminfo = streaminfo_new(xiph_entries[entryno].name, "", xiph_entries[entryno].url, xiph_entries[entryno].current_song); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
121 streaminfo_add(category, streaminfo); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
122 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
123 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
124 |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
125 /* if the requested category is the last one in the list ("other"), |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
126 we fill it with all the entries that don't match the rest of categories */ |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
127 if (xiph_category == &xiph_categories[xiph_category_count - 1]) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
128 for (entryno = 0; entryno < xiph_entry_count; entryno++) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
129 gboolean matched = FALSE; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
130 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
131 for (categoryno = 0; categoryno < xiph_category_count; categoryno++) |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
132 if (genre_match(xiph_entries[entryno].genre, xiph_categories[categoryno].match_string)) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
133 matched = TRUE; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
134 break; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
135 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
136 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
137 if (!matched) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
138 streaminfo_t *streaminfo = streaminfo_new(xiph_entries[entryno].name, "", xiph_entries[entryno].url, xiph_entries[entryno].current_song); |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
139 streaminfo_add(category, streaminfo); |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
140 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
141 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
142 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
143 |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
144 return TRUE; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
145 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
146 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
147 |
2895 | 148 streamdir_t* xiph_streamdir_fetch(void) |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
149 { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
150 streamdir_t *streamdir = streamdir_new(XIPH_NAME); |
2895 | 151 gint categno; |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
152 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
153 refresh_streamdir(); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
154 |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
155 for (categno = 0; categno < sizeof(xiph_categories) / sizeof(xiph_category_t); categno++) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
156 category_t *category = category_new(xiph_categories[categno].name); |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
157 category_add(streamdir, category); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
158 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
159 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
160 return streamdir; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
161 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
162 |
2895 | 163 static void refresh_streamdir(void) |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
164 { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
165 /* free any previously fetched streamdir data */ |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
166 if (xiph_entries != NULL) { |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
167 free(xiph_entries); |
2850
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
168 xiph_entries = NULL; |
587b3657990d
xiph now updates the streams as well; i am aware of gui crashing when adding xiph streams, but tomorrow is another lovely day
Calin Crisan ccrisan@gmail.com
parents:
2822
diff
changeset
|
169 } |
2815
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
170 xiph_entry_count = 0; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
171 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
172 debug("xiph: fetching streaming directory file '%s'\n", XIPH_STREAMDIR_URL); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
173 if (!fetch_remote_to_local_file(XIPH_STREAMDIR_URL, XIPH_TEMP_FILENAME)) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
174 failure("xiph: stream directory file '%s' could not be downloaded to '%s'\n", XIPH_STREAMDIR_URL, XIPH_TEMP_FILENAME); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
175 return; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
176 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
177 debug("xiph: stream directory file '%s' successfuly downloaded to '%s'\n", XIPH_STREAMDIR_URL, XIPH_TEMP_FILENAME); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
178 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
179 xmlDoc *doc = xmlReadFile(XIPH_TEMP_FILENAME, NULL, 0); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
180 if (doc == NULL) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
181 failure("xiph: failed to read stream directory file\n"); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
182 return; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
183 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
184 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
185 xmlNode *root_node = xmlDocGetRootElement(doc); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
186 xmlNode *node, *child; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
187 gchar *content; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
188 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
189 root_node = root_node->children; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
190 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
191 for (node = root_node; node != NULL; node = node->next) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
192 if (node->type == XML_ELEMENT_NODE) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
193 xiph_entries = realloc(xiph_entries, sizeof(xiph_entry_t) * (xiph_entry_count + 1)); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
194 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
195 for (child = node->children; child != NULL; child = child->next) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
196 if (strcmp((gchar *)child->name, "server_name") == 0) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
197 content = (gchar *) xmlNodeGetContent(child); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
198 strcpy(xiph_entries[xiph_entry_count].name, content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
199 xmlFree(content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
200 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
201 else if (strcmp((gchar *)child->name, "listen_url") == 0) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
202 content = (gchar *) xmlNodeGetContent(child); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
203 strcpy(xiph_entries[xiph_entry_count].url, content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
204 xmlFree(content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
205 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
206 else if (strcmp((gchar *)child->name, "current_song") == 0) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
207 content = (gchar *) xmlNodeGetContent(child); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
208 strcpy(xiph_entries[xiph_entry_count].current_song, content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
209 xmlFree(content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
210 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
211 else if (strcmp((gchar *)child->name, "genre") == 0) { |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
212 content = (gchar *) xmlNodeGetContent(child); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
213 strcpy(xiph_entries[xiph_entry_count].genre, content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
214 xmlFree(content); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
215 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
216 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
217 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
218 xiph_entry_count++; |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
219 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
220 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
221 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
222 xmlFreeDoc(doc); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
223 |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
224 debug("xiph: streaming directory successfuly loaded\n"); |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
225 } |
cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
Calin Crisan ccrisan@gmail.com
parents:
diff
changeset
|
226 |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
227 static gboolean genre_match(gchar *string1, gchar *string2) |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
228 { |
2894
630c9662e0f1
No, no, no and no. "type identifier[variable]" is NOT a proper way to
Matti Hamalainen <ccr@tnsp.org>
parents:
2891
diff
changeset
|
229 gchar *saveptr = NULL, *token; |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
230 gboolean matched = FALSE; |
2894
630c9662e0f1
No, no, no and no. "type identifier[variable]" is NOT a proper way to
Matti Hamalainen <ccr@tnsp.org>
parents:
2891
diff
changeset
|
231 gchar *temp1 = g_strdup(string1), |
630c9662e0f1
No, no, no and no. "type identifier[variable]" is NOT a proper way to
Matti Hamalainen <ccr@tnsp.org>
parents:
2891
diff
changeset
|
232 *temp2 = g_strdup(string2); |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
233 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
234 token = strtok_r(temp1, " ", &saveptr); |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
235 while (token != NULL) { |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
236 if (mystrcasestr(temp2, token)) |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
237 matched = TRUE; |
2894
630c9662e0f1
No, no, no and no. "type identifier[variable]" is NOT a proper way to
Matti Hamalainen <ccr@tnsp.org>
parents:
2891
diff
changeset
|
238 |
2822
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
239 token = strtok_r(NULL, " ", &saveptr); |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
240 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
241 |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
242 return matched; |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
243 } |
e883536cefe0
implemented xiph categories/genres, xiph is now usable
Calin Crisan ccrisan@gmail.com
parents:
2815
diff
changeset
|
244 |