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
38 # download the free Google Video Player from http://video.google.com/
40 url:http://vp.video.google.com/videodownload?version=0&secureurl=uAAAAMVHt_Q99OwfGxlWVWH7jd6AA_3n4TboaxIELD_kCg3KcBPSxExZFvQv5DGAxrahVg57KZNZvd0EORPBM3xrxTJ3FdLEWBYiduklpviqjE1Q5zLAkiEZaUsUSFtmbBZDTUUBuN9moYY59eK8lpWXsgTbYB1tLVtaxNBpAMRMyVeHoiJ7BzYdENk-PqJeBbr50QbQ83WK87yJAbN2pSRnF-ucCuNMSLBV7wBL4IcxFpYb1WOK-YXkyxY0NtWlPBufTA&sigh=matNCEVSOR8c-3zN9Gtx0zGinwU&begin=0&len=59749&docid=-715862862672743260
41 docid:-715862862672743260
43 title:Apple Macintosh 1984 Superbowl Commercial
44 description:The now infamous Apple Macintosh commercial aired during the 1984 SuperBowl.
48 /*****************************************************************************
50 *****************************************************************************/
55 #include <vlc_common.h>
56 #include <vlc_demux.h>
64 input_item_t *p_current_input;
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Demux( demux_t *p_demux);
71 static int Control( demux_t *p_demux, int i_query, va_list args );
73 /*****************************************************************************
74 * Import_GVP: main import function
75 *****************************************************************************/
76 int Import_GVP( vlc_object_t *p_this )
78 demux_t *p_demux = (demux_t *)p_this;
79 int i_peek, i, b_found = false;
80 const uint8_t *p_peek;
82 i_peek = stream_Peek( p_demux->s, &p_peek, MAX_LINE );
84 for( i = 0; i < i_peek - (int)sizeof("gvp_version:"); i++ )
86 if( p_peek[i] == 'g' && p_peek[i+1] == 'v' && p_peek[i+2] == 'p' &&
87 !memcmp( p_peek+i, "gvp_version:", sizeof("gvp_version:") - 1 ) )
94 if( !b_found ) return VLC_EGENERIC;
96 STANDARD_DEMUX_INIT_MSG( "using Google Video Playlist (gvp) import" );
97 p_demux->pf_control = Control;
98 p_demux->pf_demux = Demux;
99 p_demux->p_sys = malloc( sizeof( demux_sys_t ) );
100 if( !p_demux->p_sys )
106 /*****************************************************************************
107 * Deactivate: frees unused data
108 *****************************************************************************/
109 void Close_GVP( vlc_object_t *p_this )
111 demux_t *p_demux = (demux_t *)p_this;
112 demux_sys_t *p_sys = p_demux->p_sys;
117 static int Demux( demux_t *p_demux )
119 demux_sys_t *p_sys = p_demux->p_sys;
124 char *psz_version = NULL;
125 char *psz_url = NULL;
126 char *psz_docid = NULL;
128 char *psz_title = NULL;
129 char *psz_description = NULL;
130 input_item_t *p_input;
132 input_item_t *p_current_input = GetCurrentItem(p_demux);
134 input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
136 p_sys->p_current_input = p_current_input;
138 while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
140 if( *psz_line == '#' )
142 /* This is a comment */
146 psz_attrvalue = strchr( psz_line, ':' );
149 msg_Dbg( p_demux, "Unable to parse line (%s)", psz_line );
153 *psz_attrvalue = '\0';
155 if( !strcmp( psz_line, "gvp_version" ) )
157 psz_version = strdup( psz_attrvalue );
159 else if( !strcmp( psz_line, "url" ) )
161 psz_url = strdup( psz_attrvalue );
163 else if( !strcmp( psz_line, "docid" ) )
165 psz_docid = strdup( psz_attrvalue );
167 else if( !strcmp( psz_line, "duration" ) )
169 i_duration = atoi( psz_attrvalue );
171 else if( !strcmp( psz_line, "title" ) )
173 psz_title = strdup( psz_attrvalue );
175 else if( !strcmp( psz_line, "description" ) )
178 if( !psz_description )
180 psz_description = strdup( psz_attrvalue );
184 /* handle multi-line descriptions */
185 if( asprintf( &buf, "%s\n%s", psz_description, psz_attrvalue ) == -1 )
187 free( psz_description );
188 psz_description = buf;
190 /* remove ^M char at the end of the line (if any) */
191 buf = psz_description + strlen( psz_description );
192 if( buf != psz_description )
195 if( *buf == '\r' ) *buf = '\0';
203 msg_Err( p_demux, "URL not found" );
207 p_input = input_item_New( p_demux, psz_url, psz_title );
208 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
209 p_input, _("Google Video"), type, "%s", field ) ; }
210 SADD_INFO( "gvp_version", psz_version );
211 SADD_INFO( "docid", psz_docid );
212 SADD_INFO( "description", psz_description );
213 input_item_AddSubItem( p_current_input, p_input );
214 input_item_node_AppendItem( p_subitems, p_input );
215 vlc_gc_decref( p_input );
218 input_item_AddSubItemTree( p_subitems );
219 input_item_node_Delete( p_subitems );
221 vlc_gc_decref(p_current_input);
227 free( psz_description );
229 return 0; /* Needed for correct operation of go back */
232 static int Control( demux_t *p_demux, int i_query, va_list args )
234 VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);