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 CHECK_PEEK( p_peek, 12 );
72 if( !POKE( p_peek, "gvp_version:", 12 ) )
77 STANDARD_DEMUX_INIT_MSG( "using Google Video Playlist (gvp) import" )
78 p_demux->pf_control = Control;
79 p_demux->pf_demux = Demux;
80 MALLOC_ERR( p_demux->p_sys, demux_sys_t );
81 p_demux->p_sys->p_playlist = NULL;
86 /*****************************************************************************
87 * Deactivate: frees unused data
88 *****************************************************************************/
89 void E_(Close_GVP)( vlc_object_t *p_this )
91 demux_t *p_demux = (demux_t *)p_this;
92 demux_sys_t *p_sys = p_demux->p_sys;
94 if( p_sys->p_playlist )
95 vlc_object_release( p_sys->p_playlist );
99 static int Demux( demux_t *p_demux )
101 demux_sys_t *p_sys = p_demux->p_sys;
105 p_sys->p_playlist = p_playlist;
106 p_sys->p_current = p_current;
107 p_sys->i_parent_id = i_parent_id;
108 p_sys->p_item_in_category = p_item_in_category;
113 char *psz_version = NULL;
114 char *psz_url = NULL;
115 char *psz_docid = NULL;
117 char *psz_title = NULL;
118 char *psz_description = NULL;
120 while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
122 if( *psz_line == '#' )
124 /* This is a comment */
128 psz_attrvalue = strchr( psz_line, ':' );
131 msg_Dbg( p_demux, "Unable to parse line (%s)", psz_line );
135 *psz_attrvalue = '\0';
137 if( !strcmp( psz_line, "gvp_version" ) )
139 psz_version = strdup( psz_attrvalue );
141 else if( !strcmp( psz_line, "url" ) )
143 psz_url = strdup( psz_attrvalue );
145 else if( !strcmp( psz_line, "docid" ) )
147 psz_docid = strdup( psz_attrvalue );
149 else if( !strcmp( psz_line, "duration" ) )
151 i_duration = atoi( psz_attrvalue );
153 else if( !strcmp( psz_line, "title" ) )
155 psz_title = strdup( psz_attrvalue );
157 else if( !strcmp( psz_line, "description" ) )
160 if( !psz_description )
162 psz_description = strdup( psz_attrvalue );
166 /* handle multi-line descriptions */
167 buf = malloc( strlen( psz_description )
168 + strlen( psz_attrvalue ) + 2 );
169 sprintf( buf, "%s\n%s", psz_description, psz_attrvalue );
170 free( psz_description );
171 psz_description = buf;
173 /* remove ^M char at the end of the line (if any) */
174 buf = psz_description + strlen( psz_description );
175 if( buf != psz_description )
178 if( *buf == '\r' ) *buf = '\0';
186 msg_Err( p_demux, "URL not found" );
190 p_input = input_ItemNewExt( p_sys->p_playlist,
191 psz_url, psz_title, 0, NULL, -1 );
192 #define SADD_INFO( type, field ) if( field ) { vlc_input_item_AddInfo( \
193 p_input, _("Google Video"), _(type), "%s", field ) ; }
194 SADD_INFO( "gvp_version", psz_version );
195 SADD_INFO( "docid", psz_docid );
196 SADD_INFO( "description", psz_description );
197 playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
198 p_sys->p_current, p_sys->p_item_in_category,
199 (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
203 HANDLE_PLAY_AND_RELEASE;
209 free( psz_description );
211 p_sys->p_playlist = NULL;
216 static int Control( demux_t *p_demux, int i_query, va_list args )