asx: fix mimetype and stream Peek
[vlc.git] / modules / demux / playlist / ifo.c
blob183a17a558fa22c97c9ab71c100bf3c37e57f1e6
1 /*****************************************************************************
2 * ifo.c: Dummy ifo demux to enable opening DVDs rips by double cliking on VIDEO_TS.IFO
3 *****************************************************************************
4 * Copyright (C) 2007 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea @t videolan d.t org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_access.h>
33 #include <assert.h>
35 #include "playlist.h"
37 /*****************************************************************************
38 * Local prototypes
39 *****************************************************************************/
40 static int ReadDVD( stream_t *, input_item_node_t * );
41 static int ReadDVD_VR( stream_t *, input_item_node_t * );
43 /*****************************************************************************
44 * Import_IFO: main import function
45 *****************************************************************************/
46 int Import_IFO( vlc_object_t *p_this )
48 stream_t *p_demux = (stream_t *)p_this;
50 CHECK_FILE(p_demux);
51 if( p_demux->psz_filepath == NULL )
52 return VLC_EGENERIC;
54 size_t len = strlen( p_demux->psz_filepath );
56 char *psz_file = p_demux->psz_filepath + len - strlen( "VIDEO_TS.IFO" );
57 /* Valid filenames are :
58 * - VIDEO_TS.IFO
59 * - VTS_XX_X.IFO where X are digits
61 if( len > strlen( "VIDEO_TS.IFO" )
62 && ( !strcasecmp( psz_file, "VIDEO_TS.IFO" )
63 || (!strncasecmp( psz_file, "VTS_", 4 )
64 && !strcasecmp( psz_file + strlen( "VTS_00_0" ) , ".IFO" ) ) ) )
66 const uint8_t *p_peek;
67 ssize_t i_peek = vlc_stream_Peek( p_demux->s, &p_peek, 8 );
69 if( i_peek != 8 || memcmp( p_peek, "DVDVIDEO", 8 ) )
70 return VLC_EGENERIC;
72 p_demux->pf_readdir = ReadDVD;
74 /* Valid filename for DVD-VR is VR_MANGR.IFO */
75 else if( len >= 12 && !strcmp( &p_demux->psz_filepath[len-12], "VR_MANGR.IFO" ) )
77 const uint8_t *p_peek;
78 ssize_t i_peek = vlc_stream_Peek( p_demux->s, &p_peek, 8 );
80 if( i_peek != 8 || memcmp( p_peek, "DVD_RTR_", 8 ) )
81 return VLC_EGENERIC;
83 p_demux->pf_readdir = ReadDVD_VR;
85 else
86 return VLC_EGENERIC;
88 p_demux->pf_control = access_vaDirectoryControlHelper;
90 return VLC_SUCCESS;
93 static int ReadDVD( stream_t *p_demux, input_item_node_t *node )
95 char *psz_url, *psz_dir;
97 psz_dir = strrchr( p_demux->psz_location, '/' );
98 if( psz_dir != NULL )
99 psz_dir[1] = '\0';
101 if( asprintf( &psz_url, "dvd://%s", p_demux->psz_location ) == -1 )
102 return 0;
104 input_item_t *p_input = input_item_New( psz_url, psz_url );
105 input_item_node_AppendItem( node, p_input );
106 input_item_Release( p_input );
108 free( psz_url );
110 return VLC_SUCCESS;
113 static int ReadDVD_VR( stream_t *p_demux, input_item_node_t *node )
115 size_t len = strlen( p_demux->psz_location );
116 char *psz_url = malloc( len + 1 );
118 if( unlikely( psz_url == NULL ) )
119 return 0;
120 assert( len >= 12 );
121 len -= 12;
122 memcpy( psz_url, p_demux->psz_location, len );
123 memcpy( psz_url + len, "VR_MOVIE.VRO", 13 );
125 input_item_t *p_input = input_item_New( psz_url, psz_url );
126 input_item_node_AppendItem( node, p_input );
127 input_item_Release( p_input );
129 free( psz_url );
131 return VLC_SUCCESS;