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"
54 /*****************************************************************************
56 *****************************************************************************/
59 static int Open ( vlc_object_t * );
60 static void Close( vlc_object_t * );
63 set_shortname( "Shoutcast");
64 set_description( _("Shoutcast radio listings") );
65 set_category( CAT_PLAYLIST );
66 set_subcategory( SUBCAT_PLAYLIST_SD );
68 add_suppressed_integer( "shoutcast-limit" );
70 set_capability( "services_discovery", 0 );
71 set_callbacks( Open, Close );
76 /*****************************************************************************
78 *****************************************************************************/
80 struct services_discovery_sys_t
82 playlist_item_t *p_item;
86 /*****************************************************************************
88 *****************************************************************************/
91 static void Run ( services_discovery_t *p_intf );
93 /*****************************************************************************
94 * Open: initialize and create stuff
95 *****************************************************************************/
96 static int Open( vlc_object_t *p_this )
98 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
99 services_discovery_sys_t *p_sys = malloc(
100 sizeof( services_discovery_sys_t ) );
103 playlist_t *p_playlist;
104 playlist_view_t *p_view;
105 playlist_item_t *p_item;
110 /* Create our playlist node */
111 p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
115 msg_Warn( p_sd, "unable to find playlist, cancelling");
119 p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
122 p_item = playlist_ItemNew( p_playlist, SHOUTCAST_BASE_URL, _("Shoutcast") );
123 playlist_NodeAddItem( p_playlist, p_item, p_view->i_id,
124 p_view->p_root, PLAYLIST_APPEND,
127 p_sys->p_item->i_flags |= PLAYLIST_RO_FLAG;
129 val.b_bool = VLC_TRUE;
130 var_Set( p_playlist, "intf-change", val );
132 vlc_object_release( p_playlist );
137 /*****************************************************************************
139 *****************************************************************************/
140 static void Close( vlc_object_t *p_this )
142 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
143 services_discovery_sys_t *p_sys = p_sd->p_sys;
144 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
145 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
148 playlist_NodeDelete( p_playlist, p_sys->p_item, VLC_TRUE, VLC_TRUE );
149 vlc_object_release( p_playlist );
154 /*****************************************************************************
156 *****************************************************************************/
157 static void Run( services_discovery_t *p_sd )
159 services_discovery_sys_t *p_sys = p_sd->p_sys;
160 int i_id = input_Read( p_sd, &p_sys->p_item->input, VLC_FALSE );
163 i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" , "Connecting...", 0.0 );
165 p_sys->b_dialog = VLC_TRUE;
166 while( !p_sd->b_die )
168 input_thread_t *p_input = (input_thread_t *)vlc_object_get( p_sd,
171 /* The Shoutcast server does not return a content-length so we
172 * can't know where we are. Use the number of inserted items
174 if( p_input != NULL )
176 int i_state = var_GetInteger( p_input, "state" );
177 if( i_state == PLAYING_S )
179 float f_pos = (float)(p_sys->p_item->i_children)* 2 *100.0 /
180 260 /* gruiiik FIXME */;
181 intf_UserProgressUpdate( p_sd, i_dialog_id, "Downloading",
184 vlc_object_release( p_input );
186 else if( p_sys->b_dialog )
188 p_sys->b_dialog = VLC_FALSE;
189 intf_UserHide( p_sd, i_dialog_id );