1 /*****************************************************************************
2 * shout.c: Shoutcast services discovery module
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
31 #include <vlc_interaction.h>
33 #include <vlc/input.h>
37 #include <errno.h> /* ENOMEM */
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
46 /************************************************************************
47 * Macros and definitions
48 ************************************************************************/
50 #define MAX_LINE_LENGTH 256
53 /*****************************************************************************
55 *****************************************************************************/
58 static int Open ( vlc_object_t * );
59 static void Close( vlc_object_t * );
61 /// \bug Shortdesc too long
62 #define LIMIT_TEXT N_("Maximum number of shoutcast servers to be listed")
63 #define LIMIT_LONGTEXT LIMIT_TEXT
66 set_shortname( "Shoutcast");
68 set_description( _("Shoutcast radio listings") );
69 set_category( CAT_PLAYLIST );
70 set_subcategory( SUBCAT_PLAYLIST_SD );
72 add_integer( "shoutcast-limit", 1000, NULL, LIMIT_TEXT,
73 LIMIT_LONGTEXT, VLC_TRUE );
75 set_capability( "services_discovery", 0 );
76 set_callbacks( Open, Close );
81 /*****************************************************************************
83 *****************************************************************************/
85 struct services_discovery_sys_t
88 playlist_item_t *p_node;
89 playlist_item_t *p_item;
94 /*****************************************************************************
96 *****************************************************************************/
99 static void Run ( services_discovery_t *p_intf );
101 /*****************************************************************************
102 * Open: initialize and create stuff
103 *****************************************************************************/
104 static int Open( vlc_object_t *p_this )
106 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
107 services_discovery_sys_t *p_sys = malloc(
108 sizeof( services_discovery_sys_t ) );
111 playlist_t *p_playlist;
112 playlist_view_t *p_view;
113 playlist_item_t *p_item;
115 char *psz_shoutcast_url;
116 char *psz_shoutcast_title;
121 /* Create our playlist node */
122 p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
126 msg_Warn( p_sd, "unable to find playlist, cancelling");
130 p_sys->i_limit = config_GetInt( p_this->p_libvlc, "shoutcast-limit" );
131 #define SHOUTCAST_BASE_URL "http/shout-b4s://www.shoutcast.com/sbin/xmllister.phtml?service=vlc&no_compress=1&limit="
132 psz_shoutcast_url = (char *)malloc( strlen( SHOUTCAST_BASE_URL ) + 20 );
133 psz_shoutcast_title = (char *)malloc( 6 + 20 );
135 sprintf( psz_shoutcast_url, SHOUTCAST_BASE_URL "%d", p_sys->i_limit );
136 sprintf( psz_shoutcast_title, "Top %d", p_sys->i_limit );
138 p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
139 p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
140 _("Shoutcast"), p_view->p_root );
141 p_item = playlist_ItemNew( p_playlist, psz_shoutcast_url,
142 psz_shoutcast_title );
143 free( psz_shoutcast_url );
144 free( psz_shoutcast_title );
145 playlist_NodeAddItem( p_playlist, p_item,
146 p_sys->p_node->pp_parents[0]->i_view,
147 p_sys->p_node, PLAYLIST_APPEND,
150 /* We need to declare the parents of the node as the same of the
152 playlist_CopyParents( p_sys->p_node, p_item );
154 p_sys->p_item = p_item;
155 p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
156 val.b_bool = VLC_TRUE;
157 var_Set( p_playlist, "intf-change", val );
159 vlc_object_release( p_playlist );
164 /*****************************************************************************
166 *****************************************************************************/
167 static void Close( vlc_object_t *p_this )
169 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
170 services_discovery_sys_t *p_sys = p_sd->p_sys;
171 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
172 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
175 playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
176 vlc_object_release( p_playlist );
181 /*****************************************************************************
183 *****************************************************************************/
184 static void Run( services_discovery_t *p_sd )
186 services_discovery_sys_t *p_sys = p_sd->p_sys;
187 int i_id = input_Read( p_sd, &p_sys->p_item->input, VLC_FALSE );
190 i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" , "Connecting...", 0.0 );
192 p_sys->b_dialog = VLC_TRUE;
193 while( !p_sd->b_die )
195 input_thread_t *p_input = (input_thread_t *)vlc_object_get( p_sd,
198 /* The Shoutcast server does not return a content-length so we
199 * can't know where we are. Use the number of inserted items
201 if( p_input != NULL )
203 int i_state = var_GetInteger( p_input, "state" );
204 if( i_state == PLAYING_S )
206 float f_pos = (float)(p_sys->p_item->i_children)* 2 *100.0 /
207 (float)(p_sys->i_limit);
208 intf_UserProgressUpdate( p_sd, i_dialog_id, "Downloading",
211 vlc_object_release( p_input );
213 else if( p_sys->b_dialog )
215 p_sys->b_dialog = VLC_FALSE;
216 intf_UserHide( p_sd, i_dialog_id );