]> git.sesse.net Git - vlc/blob - modules/services_discovery/shout.c
230bbbd5bc0ac0f8dde410b2ba2ee6db3a685517
[vlc] / modules / services_discovery / shout.c
1 /*****************************************************************************
2  * shout.c:  Shoutcast services discovery module
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *          Antoine Cellerier <dionoea -@T- videolan -d.t- org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Includes
27  *****************************************************************************/
28
29 #include <vlc/vlc.h>
30 #include <vlc_services_discovery.h>
31 #include <vlc_interface.h>
32
33 #include <vlc_network.h>
34
35 #include <errno.h>                                                 /* ENOMEM */
36
37 #ifdef HAVE_UNISTD_H
38 #    include <unistd.h>
39 #endif
40 #ifdef HAVE_SYS_TIME_H
41 #    include <sys/time.h>
42 #endif
43
44 /************************************************************************
45  * Macros and definitions
46  ************************************************************************/
47
48 #define MAX_LINE_LENGTH 256
49 #define SHOUTCAST_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml"
50 #define SHOUTCAST_TV_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1"
51
52 /*****************************************************************************
53  * Module descriptor
54  *****************************************************************************/
55
56 /* Callbacks */
57     static int  Open ( vlc_object_t *, int );
58     static int  OpenRadio ( vlc_object_t * );
59     static int  OpenTV ( vlc_object_t * );
60     static void Close( vlc_object_t * );
61
62 vlc_module_begin();
63     set_shortname( "Shoutcast");
64     set_description( _("Shoutcast radio listings") );
65     add_shortcut( "shoutcast" );
66     set_category( CAT_PLAYLIST );
67     set_subcategory( SUBCAT_PLAYLIST_SD );
68
69     add_obsolete_integer( "shoutcast-limit" );
70
71     set_capability( "services_discovery", 0 );
72     set_callbacks( OpenRadio, Close );
73
74     add_submodule();
75         set_shortname( "ShoutcastTV" );
76         set_description( _("Shoutcast TV listings") );
77         set_capability( "services_discovery", 0 );
78         set_callbacks( OpenTV, Close );
79         add_shortcut( "shoutcasttv" );
80
81 vlc_module_end();
82
83
84 /*****************************************************************************
85  * Local structures
86  *****************************************************************************/
87
88 struct services_discovery_sys_t
89 {
90     input_item_t *p_input;
91     vlc_bool_t b_dialog;
92 };
93
94 #define RADIO 0
95 #define TV 1
96
97 /*****************************************************************************
98  * Local prototypes
99  *****************************************************************************/
100
101 static void Run( services_discovery_t *p_sd );
102
103 /* Main functions */
104 static int OpenRadio( vlc_object_t *p_this )
105 {
106     return Open( p_this, RADIO );
107 }
108
109 static int OpenTV( vlc_object_t *p_this )
110 {
111     return Open( p_this, TV );
112 }
113
114 /*****************************************************************************
115  * Open: initialize and create stuff
116  *****************************************************************************/
117 static int Open( vlc_object_t *p_this, int i_type )
118 {
119     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
120     DECMALLOC_ERR( p_sys, services_discovery_sys_t );
121     p_sd->p_sys  = p_sys;
122     p_sd->pf_run = Run;
123
124     switch( i_type )
125     {
126         case TV:
127             services_discovery_SetLocalizedName( p_sd, _("Shoutcast TV") );
128
129             p_sys->p_input = input_ItemNewExt( p_sd,
130                                 SHOUTCAST_TV_BASE_URL, _("Shoutcast TV"),
131                                 0, NULL, -1 );
132             break;
133         case RADIO:
134         default:
135             services_discovery_SetLocalizedName( p_sd, _("Shoutcast Radio") );
136
137             p_sys->p_input = input_ItemNewExt( p_sd,
138                                 SHOUTCAST_BASE_URL, _("Shoutcast Radio"),
139                                 0, NULL, -1 );
140             break;
141     }
142     vlc_gc_incref( p_sys->p_input ); /* Refcount to 1, so we can release it
143                                       * in Close() */
144
145     input_ItemAddOption( p_sys->p_input, "no-playlist-autostart" );
146     return VLC_SUCCESS;
147 }
148
149 /*****************************************************************************
150  * ItemAdded:
151  *****************************************************************************/
152 static void ItemAdded( const vlc_event_t * p_event, void * user_data )
153 {
154     services_discovery_t *p_sd = user_data;
155     services_discovery_AddItem( p_sd,
156             p_event->u.input_item_subitem_added.p_new_child,
157             NULL /* no category */ );
158 }
159
160 /*****************************************************************************
161  * Run:
162  *****************************************************************************/
163 static void Run( services_discovery_t *p_sd )
164 {
165     vlc_event_attach( &p_sd->p_sys->p_input->event_manager, vlc_InputItemSubItemAdded, ItemAdded, p_sd );
166     input_Read( p_sd, p_sd->p_sys->p_input, VLC_TRUE );
167     vlc_event_detach( &p_sd->p_sys->p_input->event_manager, vlc_InputItemSubItemAdded, ItemAdded, p_sd );
168 }
169
170 /*****************************************************************************
171  * Close:
172  *****************************************************************************/
173 static void Close( vlc_object_t *p_this )
174 {
175     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
176     services_discovery_sys_t *p_sys  = p_sd->p_sys;
177     vlc_gc_decref( p_sys->p_input );
178     free( p_sys );
179 }