1 /*****************************************************************************
2 * gvp.c: Google Video Playlist demuxer
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea @t videolan d.t 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 *****************************************************************************/
26 * gvp_version:<version> (1.1)
27 * url:<the media's url>
29 * duration:<integer ms ?>
31 * description:<desc line1>^M
32 * description:<desc linei>^M
33 * description:<desc final line (no ^M)>
34 * lines starting with # are comments
37 /*****************************************************************************
39 *****************************************************************************/
41 #include <vlc/input.h>
44 #include <errno.h> /* ENOMEM */
51 playlist_t *p_playlist;
52 playlist_item_t *p_current;
53 playlist_item_t *p_item_in_category;
57 /*****************************************************************************
59 *****************************************************************************/
60 static int Demux( demux_t *p_demux);
61 static int Control( demux_t *p_demux, int i_query, va_list args );
63 /*****************************************************************************
64 * Import_GVP: main import function
65 *****************************************************************************/
66 int E_(Import_GVP)( vlc_object_t *p_this )
68 demux_t *p_demux = (demux_t *)p_this;
71 /* FIXME: we need to skip comment lines !!!! */
72 CHECK_PEEK( p_peek, 12 );
73 if( !POKE( p_peek, "gvp_version:", 12 ) )
78 STANDARD_DEMUX_INIT_MSG( "using Google Video Playlist (gvp) import" )
79 p_demux->pf_control = Control;
80 p_demux->pf_demux = Demux;
81 MALLOC_ERR( p_demux->p_sys, demux_sys_t );
82 p_demux->p_sys->p_playlist = NULL;
87 /*****************************************************************************
88 * Deactivate: frees unused data
89 *****************************************************************************/
90 void E_(Close_GVP)( vlc_object_t *p_this )
92 demux_t *p_demux = (demux_t *)p_this;
93 demux_sys_t *p_sys = p_demux->p_sys;
95 if( p_sys->p_playlist )
96 vlc_object_release( p_sys->p_playlist );
100 static int Demux( demux_t *p_demux )
102 demux_sys_t *p_sys = p_demux->p_sys;
107 char *psz_version = NULL;
108 char *psz_url = NULL;
109 char *psz_docid = NULL;
111 char *psz_title = NULL;
112 char *psz_description = NULL;
116 p_sys->p_playlist = p_playlist;
117 p_sys->p_current = p_current;
118 p_sys->i_parent_id = i_parent_id;
119 p_sys->p_item_in_category = p_item_in_category;
121 while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
123 if( *psz_line == '#' )
125 /* This is a comment */
129 psz_attrvalue = strchr( psz_line, ':' );
132 msg_Dbg( p_demux, "Unable to parse line (%s)", psz_line );
136 *psz_attrvalue = '\0';
138 if( !strcmp( psz_line, "gvp_version" ) )
140 psz_version = strdup( psz_attrvalue );
142 else if( !strcmp( psz_line, "url" ) )
144 psz_url = strdup( psz_attrvalue );
146 else if( !strcmp( psz_line, "docid" ) )
148 psz_docid = strdup( psz_attrvalue );
150 else if( !strcmp( psz_line, "duration" ) )
152 i_duration = atoi( psz_attrvalue );
154 else if( !strcmp( psz_line, "title" ) )
156 psz_title = strdup( psz_attrvalue );
158 else if( !strcmp( psz_line, "description" ) )
161 if( !psz_description )
163 psz_description = strdup( psz_attrvalue );
167 /* handle multi-line descriptions */
168 buf = malloc( strlen( psz_description )
169 + strlen( psz_attrvalue ) + 2 );
170 sprintf( buf, "%s\n%s", psz_description, psz_attrvalue );
171 free( psz_description );
172 psz_description = buf;
174 /* remove ^M char at the end of the line (if any) */
175 buf = psz_description + strlen( psz_description );
176 if( buf != psz_description )
179 if( *buf == '\r' ) *buf = '\0';
187 msg_Err( p_demux, "URL not found" );
191 p_input = input_ItemNewExt( p_sys->p_playlist,
192 psz_url, psz_title, 0, NULL, -1 );
193 #define SADD_INFO( type, field ) if( field ) { input_ItemAddInfo( \
194 p_input, _("Google Video"), _(type), "%s", field ) ; }
195 SADD_INFO( "gvp_version", psz_version );
196 SADD_INFO( "docid", psz_docid );
197 SADD_INFO( "description", psz_description );
198 playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
199 p_sys->p_current, p_sys->p_item_in_category,
200 (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
204 HANDLE_PLAY_AND_RELEASE;
210 free( psz_description );
212 p_sys->p_playlist = NULL;
217 static int Control( demux_t *p_demux, int i_query, va_list args )