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;
125 playlist_view_t *p_view;
126 playlist_t *p_playlist = pl_Yield( p_this );
127 DECMALLOC_ERR( p_sys, services_discovery_sys_t );
133 p_sys->p_input = input_ItemNewExt( p_playlist,
134 SHOUTCAST_TV_BASE_URL, _("Shoutcast TV"),
139 p_sys->p_input = input_ItemNewExt( p_playlist,
140 SHOUTCAST_BASE_URL, _("Shoutcast"),
144 input_ItemAddOption( p_sys->p_input, "no-playlist-autostart" );
145 p_sys->p_input->b_prefers_tree = VLC_TRUE;
146 p_sys->p_node_cat = playlist_NodeAddInput( p_playlist, p_sys->p_input,
147 p_playlist->p_root_category,
148 PLAYLIST_APPEND, PLAYLIST_END );
149 p_sys->p_node_one = playlist_NodeAddInput( p_playlist, p_sys->p_input,
150 p_playlist->p_root_onelevel,
151 PLAYLIST_APPEND, PLAYLIST_END );
152 p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
153 p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
154 p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
155 p_sys->p_node_one->i_flags |= PLAYLIST_SKIP_FLAG;
156 p_sys->p_node_one->p_input->i_id = p_sys->p_node_cat->p_input->i_id;
158 var_SetVoid( p_playlist, "intf-change" );
160 pl_Release( p_this );
162 input_Read( p_sd, p_sys->p_input, VLC_FALSE );
166 /*****************************************************************************
168 *****************************************************************************/
169 static void Close( vlc_object_t *p_this )
171 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
172 services_discovery_sys_t *p_sys = p_sd->p_sys;
173 playlist_t *p_playlist = pl_Yield( p_sd );
174 playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE, VLC_TRUE );
175 playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE, VLC_TRUE );