1 /*****************************************************************************
2 * podcast.c: Podcast services discovery module
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- 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() */
32 #include <vlc/input.h>
36 #include <errno.h> /* ENOMEM */
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
45 /************************************************************************
46 * Macros and definitions
47 ************************************************************************/
49 /*****************************************************************************
51 *****************************************************************************/
54 static int Open ( vlc_object_t * );
55 static void Close( vlc_object_t * );
57 #define URLS_TEXT N_("Podcast URLs list")
58 #define URLS_LONGTEXT N_("Enter the list of podcasts to retrieve, " \
59 "separated by '|' (pipe)." )
62 set_shortname( "Podcast");
63 set_description( _("Podcasts") );
64 set_category( CAT_PLAYLIST );
65 set_subcategory( SUBCAT_PLAYLIST_SD );
67 add_string( "podcast-urls", NULL, NULL,
68 URLS_TEXT, URLS_LONGTEXT, VLC_FALSE );
70 set_capability( "services_discovery", 0 );
71 set_callbacks( Open, Close );
76 /*****************************************************************************
78 *****************************************************************************/
80 struct services_discovery_sys_t
83 playlist_item_t *p_node_cat;
84 playlist_item_t *p_node_one;
85 input_thread_t **pp_input;
91 /*****************************************************************************
93 *****************************************************************************/
96 static void Run ( services_discovery_t *p_intf );
98 /*****************************************************************************
99 * Open: initialize and create stuff
100 *****************************************************************************/
101 static int Open( vlc_object_t *p_this )
103 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
104 services_discovery_sys_t *p_sys = malloc(
105 sizeof( services_discovery_sys_t ) );
108 playlist_t *p_playlist;
109 playlist_item_t *p_item;
113 char *psz_tmp = psz_buf = var_CreateGetString( p_sd, "podcast-urls" );
117 while( psz_buf[i] != 0 )
118 if( psz_buf[i++] == '|' )
121 p_sys->ppsz_urls = (char **)malloc( p_sys->i_urls * sizeof( char * ) );
125 while( psz_buf[i] != 0 )
127 if( psz_buf[i] == '|' )
130 p_sys->ppsz_urls[j] = strdup( psz_tmp );
138 p_sys->ppsz_urls[j] = strdup( psz_tmp );
144 /* Create our playlist node */
145 p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
149 msg_Warn( p_sd, "unable to find playlist, cancelling");
153 p_sys->p_node_cat = playlist_NodeCreate( p_playlist, _("Podcast"),
154 p_playlist->p_root_category );
155 p_sys->p_node_one = playlist_NodeCreate( p_playlist, _("Podcast"),
156 p_playlist->p_root_onelevel );
157 p_sys->p_node_one->p_input->i_id = p_sys->p_node_cat->p_input->i_id;
159 p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
160 p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
161 p_sys->p_node_one->i_flags |= PLAYLIST_SKIP_FLAG;
162 p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
163 p_sys->pp_input = malloc( p_sys->i_urls * sizeof( input_thread_t * ) );
164 for( i = 0; i < p_sys->i_urls; i++ )
166 input_item_t *p_input;
167 asprintf( &psz_buf, "%s", p_sys->ppsz_urls[i] );
168 p_input = input_ItemNewExt( p_playlist, psz_buf,
169 p_sys->ppsz_urls[i], 0, NULL, -1 );
170 vlc_input_item_AddOption( p_input, "demux=podcast" );
171 p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_cat,
172 PLAYLIST_APPEND, PLAYLIST_END );
173 p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_one,
174 PLAYLIST_APPEND, PLAYLIST_END );
176 p_sys->pp_input[i] = input_CreateThread( p_playlist, p_input );
179 val.b_bool = VLC_TRUE;
180 var_Set( p_playlist, "intf-change", val );
182 vlc_object_release( p_playlist );
187 /*****************************************************************************
189 *****************************************************************************/
190 static void Close( vlc_object_t *p_this )
192 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
193 services_discovery_sys_t *p_sys = p_sd->p_sys;
194 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
195 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
197 for( i = 0; i < p_sys->i_urls; i++ )
199 if( p_sd->p_sys->pp_input[i] )
201 input_StopThread( p_sd->p_sys->pp_input[i] );
202 input_DestroyThread( p_sd->p_sys->pp_input[i] );
203 vlc_object_detach( p_sd->p_sys->pp_input[i] );
204 vlc_object_destroy( p_sd->p_sys->pp_input[i] );
205 p_sd->p_sys->pp_input[i] = NULL;
208 free( p_sd->p_sys->pp_input );
211 playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE, VLC_TRUE );
212 playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE, VLC_TRUE );
213 vlc_object_release( p_playlist );
215 for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
216 free( p_sys->ppsz_urls );
220 /*****************************************************************************
222 *****************************************************************************/
223 static void Run( services_discovery_t *p_sd )
225 while( !p_sd->b_die )
228 for( i = 0; i < p_sd->p_sys->i_urls; i++ )
230 if( p_sd->p_sys->pp_input[i] &&
231 ( p_sd->p_sys->pp_input[i]->b_eof
232 || p_sd->p_sys->pp_input[i]->b_error ) )
234 input_StopThread( p_sd->p_sys->pp_input[i] );
235 input_DestroyThread( p_sd->p_sys->pp_input[i] );
236 vlc_object_detach( p_sd->p_sys->pp_input[i] );
237 vlc_object_destroy( p_sd->p_sys->pp_input[i] );
238 p_sd->p_sys->pp_input[i] = NULL;