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;
84 input_thread_t **pp_input;
90 /*****************************************************************************
92 *****************************************************************************/
95 static void Run ( services_discovery_t *p_intf );
97 /*****************************************************************************
98 * Open: initialize and create stuff
99 *****************************************************************************/
100 static int Open( vlc_object_t *p_this )
102 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
103 services_discovery_sys_t *p_sys = malloc(
104 sizeof( services_discovery_sys_t ) );
107 playlist_t *p_playlist;
108 playlist_view_t *p_view;
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_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
154 p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
155 _("Podcast"), p_view->p_root );
156 p_sys->pp_input = malloc( p_sys->i_urls * sizeof( input_thread_t * ) );
157 for( i = 0; i < p_sys->i_urls; i++ )
159 asprintf( &psz_buf, "%s", p_sys->ppsz_urls[i] );
160 p_item = playlist_ItemNew( p_playlist, psz_buf,
161 p_sys->ppsz_urls[i] );
163 playlist_ItemAddOption( p_item, "demux=podcast" );
164 playlist_NodeAddItem( p_playlist, p_item,
165 p_sys->p_node->pp_parents[0]->i_view,
166 p_sys->p_node, PLAYLIST_APPEND,
169 /* We need to declare the parents of the node as the same of the
171 playlist_CopyParents( p_sys->p_node, p_item );
172 p_sys->pp_input[i] = input_CreateThread( p_playlist, &p_item->input );
175 p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
176 val.b_bool = VLC_TRUE;
177 var_Set( p_playlist, "intf-change", val );
179 vlc_object_release( p_playlist );
184 /*****************************************************************************
186 *****************************************************************************/
187 static void Close( vlc_object_t *p_this )
189 services_discovery_t *p_sd = ( services_discovery_t* )p_this;
190 services_discovery_sys_t *p_sys = p_sd->p_sys;
191 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
192 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
194 for( i = 0; i < p_sys->i_urls; i++ )
196 if( p_sd->p_sys->pp_input[i] )
198 input_StopThread( p_sd->p_sys->pp_input[i] );
199 input_DestroyThread( p_sd->p_sys->pp_input[i] );
200 vlc_object_detach( p_sd->p_sys->pp_input[i] );
201 vlc_object_destroy( p_sd->p_sys->pp_input[i] );
202 p_sd->p_sys->pp_input[i] = NULL;
207 playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
208 vlc_object_release( p_playlist );
210 for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
211 free( p_sys->ppsz_urls );
215 /*****************************************************************************
217 *****************************************************************************/
218 static void Run( services_discovery_t *p_sd )
220 while( !p_sd->b_die )
223 for( i = 0; i < p_sd->p_sys->i_urls; i++ )
225 if( p_sd->p_sys->pp_input[i] &&
226 ( p_sd->p_sys->pp_input[i]->b_eof
227 || p_sd->p_sys->pp_input[i]->b_error ) )
229 input_StopThread( p_sd->p_sys->pp_input[i] );
230 input_DestroyThread( p_sd->p_sys->pp_input[i] );
231 vlc_object_detach( p_sd->p_sys->pp_input[i] );
232 vlc_object_destroy( p_sd->p_sys->pp_input[i] );
233 p_sd->p_sys->pp_input[i] = NULL;