]> git.sesse.net Git - vlc/blob - modules/services_discovery/shout.c
Replace vlc_bool_t by bool, VLC_TRUE by true and VLC_FALSE by false.
[vlc] / modules / services_discovery / shout.c
1 /*****************************************************************************
2  * shout.c:  Shoutcast services discovery module
3  *****************************************************************************
4  * Copyright (C) 2005-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *          Antoine Cellerier <dionoea -@T- videolan -d.t- org>
9  *          Pierre d'Herbemont <pdherbemont # videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Includes
28  *****************************************************************************/
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc/vlc.h>
35 #include <vlc_services_discovery.h>
36
37 /*****************************************************************************
38  * Module descriptor
39  *****************************************************************************/
40
41 enum type_e { ShoutRadio = 0, ShoutTV = 1, Freebox = 2, FrenchTV = 3 };
42
43 static int  Open( vlc_object_t *, enum type_e );
44 static void Close( vlc_object_t * );
45
46 struct shout_item_t
47 {
48     const char *psz_url;
49     const char *psz_name;
50     const char *ppsz_options[2];
51     const struct shout_item_t * p_children;
52 };
53
54 #define endItem( ) { NULL, NULL, { NULL }, NULL }
55 #define item( title, url ) { url, title, { NULL }, NULL }
56 #define itemWithOption( title, url, option ) { url, title, { option, NULL }, NULL }
57 #define itemWithChildren( title, children ) { "vlc:skip", title, { NULL }, children }
58
59 /* WARN: We support only two levels */
60
61 static const struct shout_item_t p_frenchtv_canalplus[] = {
62     itemWithOption( N_("Les Guignols"), "http://www.canalplus.fr/index.php?pid=1784", "http-forward-cookies" ),
63     endItem()
64 };
65     
66 static const struct shout_item_t p_frenchtv[] = {
67     itemWithChildren( N_("Canal +"),  p_frenchtv_canalplus ),
68     endItem()
69 };
70
71 static const struct shout_item_t p_items[] = {
72     item(            N_("Shoutcast Radio"), "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml" ),
73     item(            N_("Shoutcast TV"),    "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1" ),
74     item(            N_("Freebox TV"),      "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u" ),
75     itemWithChildren(N_("French TV"),        p_frenchtv ),
76     endItem()
77 };
78
79 #undef endItem
80 #undef item
81 #undef itemWithOptions
82 #undef itemWithChildren
83
84 struct shout_category_t {
85     services_discovery_t * p_sd;
86     const char * psz_category;
87 };
88
89 /* Main functions */
90 #define OPEN( type )                                \
91 static int Open ## type ( vlc_object_t *p_this )    \
92 {                                                   \
93     msg_Dbg( p_this, "Starting " #type );           \
94     return Open( p_this, type );                    \
95 }
96
97 OPEN( ShoutRadio )
98 OPEN( ShoutTV )
99 OPEN( Freebox )
100 OPEN( FrenchTV )
101
102 vlc_module_begin();
103     set_category( CAT_PLAYLIST );
104     set_subcategory( SUBCAT_PLAYLIST_SD );
105
106     add_obsolete_integer( "shoutcast-limit" );
107
108         set_shortname( "Shoutcast");
109         set_description( _("Shoutcast radio listings") );
110         set_capability( "services_discovery", 0 );
111         set_callbacks( OpenShoutRadio, Close );
112         add_shortcut( "shoutcast" );
113
114     add_submodule();
115         set_shortname( "ShoutcastTV" );
116         set_description( _("Shoutcast TV listings") );
117         set_capability( "services_discovery", 0 );
118         set_callbacks( OpenShoutTV, Close );
119         add_shortcut( "shoutcasttv" );
120
121     add_submodule();
122         set_shortname( "frenchtv");
123         set_description( _("French TV") );
124         set_capability( "services_discovery", 0 );
125         set_callbacks( OpenFrenchTV, Close );
126         add_shortcut( "frenchtv" );
127
128     add_submodule();
129         set_shortname( "Freebox");
130         set_description( _("Freebox TV listing (French ISP free.fr services)") );
131         set_capability( "services_discovery", 0 );
132         set_callbacks( OpenFreebox, Close );
133         add_shortcut( "freebox" );
134
135 vlc_module_end();
136
137
138 /*****************************************************************************
139  * Local prototypes
140  *****************************************************************************/
141
142 static void Run( services_discovery_t *p_sd );
143
144
145 /*****************************************************************************
146  * Open: initialize and create stuff
147  *****************************************************************************/
148 static int Open( vlc_object_t *p_this, enum type_e i_type )
149 {
150     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
151     services_discovery_SetLocalizedName( p_sd, _(p_items[i_type].psz_name) );
152     p_sd->pf_run = Run;
153     p_sd->p_sys = (void *)i_type;
154     return VLC_SUCCESS;
155 }
156
157 /*****************************************************************************
158  * ItemAdded:
159  *****************************************************************************/
160 static void ItemAdded( const vlc_event_t * p_event, void * user_data )
161 {
162     struct shout_category_t * params = user_data;
163     services_discovery_AddItem( params->p_sd,
164             p_event->u.input_item_subitem_added.p_new_child,
165             params->psz_category );
166 }
167
168 /*****************************************************************************
169  * CreateInputItemFromShoutItem:
170  *****************************************************************************/
171 static input_item_t * CreateInputItemFromShoutItem( services_discovery_t *p_sd,
172                                          const struct shout_item_t * p_item )
173 {
174     int i;
175     /* Create the item */
176     input_item_t *p_input = input_ItemNewExt( p_sd,
177                     p_item->psz_url, _(p_item->psz_name),
178                     0, NULL, -1 );
179
180     /* Copy options */
181     for( i = 0; p_item->ppsz_options[i] != NULL; i++ )
182         input_ItemAddOption( p_input, p_item->ppsz_options[i] );
183     input_ItemAddOption( p_input, "no-playlist-autostart" );
184
185     return p_input;
186 }
187
188 /*****************************************************************************
189  * AddSubitemsOfShoutItemURL:
190  *****************************************************************************/
191 static void AddSubitemsOfShoutItemURL( services_discovery_t *p_sd,
192                                        const struct shout_item_t * p_item,
193                                        const char * psz_category )
194 {
195     struct shout_category_t category = { p_sd, psz_category };
196
197     /* Create the item */
198     input_item_t *p_input = CreateInputItemFromShoutItem( p_sd, p_item );
199
200     /* Read every subitems, and add them in ItemAdded */
201     vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded,
202                       ItemAdded, &category );
203     input_Read( p_sd, p_input, true );
204     vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemAdded,
205                       ItemAdded, &category );
206
207     vlc_gc_decref( p_input );
208 }
209
210 /*****************************************************************************
211  * Run:
212  *****************************************************************************/
213 static void Run( services_discovery_t *p_sd )
214 {
215     enum type_e i_type = (enum type_e)p_sd->p_sys;
216     int i, j;
217     
218     if( !p_items[i_type].p_children )
219     {
220         AddSubitemsOfShoutItemURL( p_sd, &p_items[i_type], NULL );
221         return;
222     }
223     for( i = 0; p_items[i_type].p_children[i].psz_name; i++ )
224     {
225         const struct shout_item_t * p_subitem = &p_items[i_type].p_children[i];
226         if( !p_subitem->p_children )
227         {
228             AddSubitemsOfShoutItemURL( p_sd, p_subitem, p_subitem->psz_name );
229             continue;
230         }
231         for( j = 0; p_subitem->p_children[j].psz_name; j++ )
232         {
233             input_item_t *p_input = CreateInputItemFromShoutItem( p_sd, &p_subitem->p_children[j] );
234             services_discovery_AddItem( p_sd,
235                 p_input,
236                 p_subitem->psz_name );
237             vlc_gc_decref( p_input );
238         }
239     }
240 }
241
242 /*****************************************************************************
243  * Close:
244  *****************************************************************************/
245 static void Close( vlc_object_t *p_this )
246 {
247     VLC_UNUSED(p_this);
248 }