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