670f094a377e0dc7fc865d0f21b0d0234945d362
[vlc.git] / 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 #include <vlc/vlc.h>
31 #include <vlc_services_discovery.h>
32
33 /*****************************************************************************
34  * Module descriptor
35  *****************************************************************************/
36
37 enum type_e { ShoutRadio = 0, ShoutTV = 1, Freebox = 2 };
38
39 static int  Open( vlc_object_t *, enum type_e );
40 static void Close( vlc_object_t * );
41
42 static const struct
43 {
44     const char *psz_url;
45     const char *psz_name;
46 } p_items[] = {
47     { "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml",
48       N_("Shoutcast Radio") },
49     { "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1",
50       N_("Shoutcast TV") },
51     { "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u",
52       N_("Freebox TV") },
53 };
54
55 /* Main functions */
56 #define OPEN( type )                                \
57 static int Open ## type ( vlc_object_t *p_this )    \
58 {                                                   \
59     return Open( p_this, type );                    \
60 }
61
62 OPEN( ShoutRadio )
63 OPEN( ShoutTV )
64 OPEN( Freebox )
65
66 vlc_module_begin();
67     set_category( CAT_PLAYLIST );
68     set_subcategory( SUBCAT_PLAYLIST_SD );
69
70     add_obsolete_integer( "shoutcast-limit" );
71
72         set_shortname( "Shoutcast");
73         set_description( _("Shoutcast radio listings") );
74         set_capability( "services_discovery", 0 );
75         set_callbacks( OpenShoutRadio, Close );
76         add_shortcut( "shoutcast" );
77
78     add_submodule();
79         set_shortname( "ShoutcastTV" );
80         set_description( _("Shoutcast TV listings") );
81         set_capability( "services_discovery", 0 );
82         set_callbacks( OpenShoutTV, Close );
83         add_shortcut( "shoutcasttv" );
84
85     add_submodule();
86         set_shortname( "Freebox");
87         set_description( _("Freebox TV listing (French ISP free.fr services)") );
88         set_capability( "services_discovery", 0 );
89         set_callbacks( OpenFreebox, Close );
90         add_shortcut( "freebox" );
91
92 vlc_module_end();
93
94
95 /*****************************************************************************
96  * Local prototypes
97  *****************************************************************************/
98
99 static void Run( services_discovery_t *p_sd );
100
101
102 /*****************************************************************************
103  * Open: initialize and create stuff
104  *****************************************************************************/
105 static int Open( vlc_object_t *p_this, enum type_e i_type )
106 {
107     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
108     services_discovery_SetLocalizedName( p_sd, _(p_items[i_type].psz_name) );
109     p_sd->pf_run = Run;
110     p_sd->p_sys = (void *)i_type;
111     return VLC_SUCCESS;
112 }
113
114 /*****************************************************************************
115  * ItemAdded:
116  *****************************************************************************/
117 static void ItemAdded( const vlc_event_t * p_event, void * user_data )
118 {
119     services_discovery_t *p_sd = user_data;
120     services_discovery_AddItem( p_sd,
121             p_event->u.input_item_subitem_added.p_new_child,
122             NULL /* no category */ );
123 }
124
125 /*****************************************************************************
126  * Run:
127  *****************************************************************************/
128 static void Run( services_discovery_t *p_sd )
129 {
130     enum type_e i_type = (enum type_e)p_sd->p_sys;
131     input_item_t *p_input = input_ItemNewExt( p_sd,
132                         p_items[i_type].psz_url, _(p_items[i_type].psz_name),
133                         0, NULL, -1 );
134     input_ItemAddOption( p_input, "no-playlist-autostart" );
135
136     vlc_gc_incref( p_input );
137     vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded,
138                       ItemAdded, p_sd );
139     input_Read( p_sd, p_input, VLC_TRUE );
140     vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemAdded,
141                       ItemAdded, p_sd );
142     vlc_gc_decref( p_input );
143 }
144
145 /*****************************************************************************
146  * Close:
147  *****************************************************************************/
148 static void Close( vlc_object_t *p_this )
149 {
150 }