1 /*****************************************************************************
2 * shout.c: Shoutcast services discovery module
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8 * Antoine Cellerier <dionoea -@T- videolan -d.t- org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
32 #include <vlc_interaction.h>
34 #include <vlc/input.h>
38 #include <errno.h> /* ENOMEM */
43 #ifdef HAVE_SYS_TIME_H
44 # include <sys/time.h>
47 /************************************************************************
48 * Macros and definitions
49 ************************************************************************/
51 #define MAX_LINE_LENGTH 256
52 #define SHOUTCAST_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newxml.phtml"
53 #define SHOUTCAST_TV_BASE_URL "http/shout-winamp://www.shoutcast.com/sbin/newtvlister.phtml?alltv=1"
55 /*****************************************************************************
57 *****************************************************************************/
60 static int Open ( vlc_object_t *, int );
61 static int OpenRadio ( vlc_object_t * );
62 static int OpenTV ( vlc_object_t * );
63 static void Close( vlc_object_t * );
66 set_shortname( "Shoutcast");
67 set_description( _("Shoutcast radio listings") );
68 add_shortcut( "shoutcast" );
69 set_category( CAT_PLAYLIST );
70 set_subcategory( SUBCAT_PLAYLIST_SD );
72 add_suppressed_integer( "shoutcast-limit" );
74 set_capability( "services_discovery", 0 );
75 set_callbacks( OpenRadio, Close );
78 set_shortname( "ShoutcastTV" );
79 set_description( _("Shoutcast TV listings") );
80 set_capability( "services_discovery", 0 );
81 set_callbacks( OpenTV, Close );
82 add_shortcut( "shoutcasttv" );
87 /*****************************************************************************
89 *****************************************************************************/
91 struct services_discovery_sys_t
93 playlist_item_t *p_node_cat,*p_node_one;
94 input_item_t *p_input;
101 /*****************************************************************************
103 *****************************************************************************/
106 static void Run ( services_discovery_t *p_intf );
108 static int OpenRadio( vlc_object_t *p_this )
110 return Open( p_this, RADIO );
113 static int OpenTV( vlc_object_t *p_this )
115 return Open( p_this, TV );
118 /*****************************************************************************
119 * Open: initialize and create stuff
120 *****************************************************************************/
121 static int Open( vlc_object_t *p_this, int i_type )
123 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
124 services_discovery_sys_t *p_sys = malloc(
125 sizeof( services_discovery_sys_t ) );
128 playlist_t *p_playlist;
129 playlist_view_t *p_view;
134 /* Create our playlist node */
135 p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
139 msg_Warn( p_sd, "unable to find playlist, cancelling");
146 p_sys->p_input = input_ItemNewExt( p_playlist,
147 SHOUTCAST_TV_BASE_URL, _("Shoutcast TV"),
152 p_sys->p_input = input_ItemNewExt( p_playlist,
153 SHOUTCAST_BASE_URL, _("Shoutcast"),
157 p_sys->p_node_cat = playlist_NodeAddInput( p_playlist, p_sys->p_input,
158 p_playlist->p_root_category,
159 PLAYLIST_APPEND, PLAYLIST_END );
160 p_sys->p_node_one = playlist_NodeAddInput( p_playlist, p_sys->p_input,
161 p_playlist->p_root_onelevel,
162 PLAYLIST_APPEND, PLAYLIST_END );
163 p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
164 p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
165 p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
166 p_sys->p_node_one->i_flags |= PLAYLIST_SKIP_FLAG;
167 p_sys->p_node_one->p_input->i_id = p_sys->p_node_cat->p_input->i_id;
169 val.b_bool = VLC_TRUE;
170 var_Set( p_playlist, "intf-change", val );
172 vlc_object_release( p_playlist );
177 /*****************************************************************************
179 *****************************************************************************/
180 static void Close( vlc_object_t *p_this )
182 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
183 services_discovery_sys_t *p_sys = p_sd->p_sys;
184 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
185 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
188 playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE, VLC_TRUE );
189 playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE, VLC_TRUE );
190 vlc_object_release( p_playlist );
195 /*****************************************************************************
197 *****************************************************************************/
198 static void Run( services_discovery_t *p_sd )
200 services_discovery_sys_t *p_sys = p_sd->p_sys;
201 int i_id = input_Read( p_sd, p_sys->p_input, VLC_FALSE );
204 i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" ,
205 _("Connecting...") , 0.0, 0 );
207 p_sys->b_dialog = VLC_TRUE;
208 while( !p_sd->b_die )
210 input_thread_t *p_input = (input_thread_t *)vlc_object_get( p_sd,
213 /* The Shoutcast server does not return a content-length so we
214 * can't know where we are. Use the number of inserted items
216 if( p_input != NULL )
218 int i_state = var_GetInteger( p_input, "state" );
219 if( i_state == PLAYING_S )
221 float f_pos = (float)(p_sys->p_node_cat->i_children)* 2 *100.0 /
222 260 /* gruiiik FIXME */;
223 intf_ProgressUpdate( p_sd, i_dialog_id, "Downloading",
226 vlc_object_release( p_input );
228 else if( p_sys->b_dialog )
230 p_sys->b_dialog = VLC_FALSE;
231 intf_UserHide( p_sd, i_dialog_id );