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
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 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_access.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int ReadDVD( stream_t
*, input_item_node_t
* );
42 static int ReadDVD_VR( stream_t
*, input_item_node_t
* );
44 static const char *StreamLocation( const stream_t
*s
)
46 return s
->psz_filepath
? s
->psz_filepath
: s
->psz_url
;
49 /*****************************************************************************
50 * Import_IFO: main import function
51 *****************************************************************************/
52 int Import_IFO( vlc_object_t
*p_this
)
54 stream_t
*p_stream
= (stream_t
*)p_this
;
58 if( !stream_HasExtension( p_stream
, ".IFO" ) )
61 const char *psz_location
= StreamLocation( p_stream
);
62 if( psz_location
== NULL
)
65 size_t len
= strlen( psz_location
);
69 const char *psz_probe
;
70 const char *psz_file
= &psz_location
[len
- 12];
71 /* Valid filenames are :
73 * - VTS_XX_X.IFO where X are digits
75 if( !strncasecmp( psz_file
, "VIDEO_TS", 8 ) ||
76 !strncasecmp( psz_file
, "VTS_", 4 ) )
78 psz_probe
= "DVDVIDEO";
79 p_stream
->pf_readdir
= ReadDVD
;
81 /* Valid filename for DVD-VR is VR_MANGR.IFO */
82 else if( !strncasecmp( psz_file
, "VR_MANGR", 8 ) )
84 psz_probe
= "DVD_RTR_";
85 p_stream
->pf_readdir
= ReadDVD_VR
;
90 const uint8_t *p_peek
;
91 ssize_t i_peek
= vlc_stream_Peek( p_stream
->s
, &p_peek
, 8 );
92 if( i_peek
< 8 || memcmp( p_peek
, psz_probe
, 8 ) )
95 p_stream
->pf_control
= access_vaDirectoryControlHelper
;
100 static int ReadDVD( stream_t
*p_stream
, input_item_node_t
*node
)
102 const char *psz_location
= StreamLocation(p_stream
);
104 char *psz_url
= strndup( psz_location
, strlen( psz_location
) - 12 );
108 input_item_t
*p_input
= input_item_New( psz_url
, psz_url
);
111 input_item_AddOption( p_input
, "demux=dvd", VLC_INPUT_OPTION_TRUSTED
);
112 input_item_node_AppendItem( node
, p_input
);
113 input_item_Release( p_input
);
121 static int ReadDVD_VR( stream_t
*p_stream
, input_item_node_t
*node
)
123 const char *psz_location
= StreamLocation(p_stream
);
125 size_t len
= strlen( psz_location
);
126 char *psz_url
= strdup( psz_location
);
128 if( unlikely( psz_url
== NULL
) )
131 strcpy( &psz_url
[len
- 12], "VR_MOVIE.VRO" );
133 input_item_t
*p_input
= input_item_New( psz_url
, psz_url
);
136 input_item_node_AppendItem( node
, p_input
);
137 input_item_Release( p_input
);