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 *****************************************************************************/
29 #include <vlc_playlist.h>
30 #include <vlc_network.h>
32 #include <errno.h> /* ENOMEM */
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
41 /************************************************************************
42 * Macros and definitions
43 ************************************************************************/
45 /*****************************************************************************
47 *****************************************************************************/
50 static int Open ( vlc_object_t * );
51 static void Close( vlc_object_t * );
53 #define URLS_TEXT N_("Podcast URLs list")
54 #define URLS_LONGTEXT N_("Enter the list of podcasts to retrieve, " \
55 "separated by '|' (pipe)." )
58 set_shortname( "Podcast");
59 set_description( _("Podcasts") );
60 set_category( CAT_PLAYLIST );
61 set_subcategory( SUBCAT_PLAYLIST_SD );
63 add_string( "podcast-urls", NULL, NULL,
64 URLS_TEXT, URLS_LONGTEXT, VLC_FALSE );
68 set_capability( "services_discovery", 0 );
69 set_callbacks( Open, Close );
74 /*****************************************************************************
76 *****************************************************************************/
78 struct services_discovery_sys_t
81 input_thread_t **pp_input;
90 /*****************************************************************************
92 *****************************************************************************/
93 static void Run( services_discovery_t *p_intf );
94 static int UrlsChange( vlc_object_t *, char const *, vlc_value_t,
95 vlc_value_t, void * );
96 static void ParseUrls( services_discovery_t *p_sd, char *psz_urls );
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 p_sys->ppsz_urls = NULL;
110 p_sys->pp_input = NULL;
111 p_sys->b_update = VLC_TRUE;
117 services_discovery_SetLocalizedName( p_sd, _("Podcasts") );
122 /*****************************************************************************
124 *****************************************************************************/
125 static void Close( vlc_object_t *p_this )
127 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
128 services_discovery_sys_t *p_sys = p_sd->p_sys;
130 for( i = 0; i < p_sys->i_input; i++ )
132 if( p_sd->p_sys->pp_input[i] )
134 input_StopThread( p_sd->p_sys->pp_input[i] );
135 input_DestroyThread( p_sd->p_sys->pp_input[i] );
136 p_sd->p_sys->pp_input[i] = NULL;
139 free( p_sd->p_sys->pp_input );
140 for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
141 free( p_sys->ppsz_urls );
145 /*****************************************************************************
147 *****************************************************************************/
148 static void Run( services_discovery_t *p_sd )
150 services_discovery_sys_t *p_sys = p_sd->p_sys;
152 char *psz_urls = var_CreateGetString( p_sd, "podcast-urls" );
153 free( psz_urls ); /* Gruik ? */
154 var_AddCallback( p_sd, "podcast-urls", UrlsChange, p_sys );
156 while( !p_sd->b_die )
159 if( p_sys->b_update == VLC_TRUE )
161 msg_Dbg( p_sd, "Update required" );
162 psz_urls = var_GetNonEmptyString( p_sd, "podcast-urls" );
163 if( psz_urls != NULL )
164 ParseUrls( p_sd, psz_urls );
166 p_sys->b_update = VLC_FALSE;
169 for( i = 0; i < p_sd->p_sys->i_input; i++ )
171 if( p_sd->p_sys->pp_input[i]->b_eof
172 || p_sd->p_sys->pp_input[i]->b_error )
174 input_StopThread( p_sd->p_sys->pp_input[i] );
175 input_DestroyThread( p_sd->p_sys->pp_input[i] );
176 p_sd->p_sys->pp_input[i] = NULL;
177 REMOVE_ELEM( p_sys->pp_input, p_sys->i_input, i );
185 static int UrlsChange( vlc_object_t *p_this, char const *psz_var,
186 vlc_value_t oldval, vlc_value_t newval,
189 services_discovery_sys_t *p_sys = (services_discovery_sys_t *)p_data;
190 p_sys->b_update = VLC_TRUE;
194 static void ParseUrls( services_discovery_t *p_sd, char *psz_urls )
196 services_discovery_sys_t *p_sys = p_sd->p_sys;
200 char *psz_tok = strchr( psz_urls, '|' );
201 if( psz_tok ) *psz_tok = '\0';
202 for( i = 0; i < p_sys->i_urls; i++ )
203 if( !strcmp( psz_urls, p_sys->ppsz_urls[i] ) )
205 if( i == p_sys->i_urls )
207 /* Only add new urls.
208 * FIXME: We don't delete urls which have been removed from
209 * the config since we don't have a way to know which inputs
211 input_item_t *p_input;
212 INSERT_ELEM( p_sys->ppsz_urls, p_sys->i_urls, p_sys->i_urls,
213 strdup( psz_urls ) );
214 p_input = input_ItemNewExt( p_sd, psz_urls,
215 psz_urls, 0, NULL, -1 );
216 input_ItemAddOption( p_input, "demux=podcast" );
217 services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ );
218 INSERT_ELEM( p_sys->pp_input, p_sys->i_input, p_sys->i_input,
219 input_CreateThread( p_sd, p_input ) );
221 if( psz_tok ) psz_urls = psz_tok+1;