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
6 * Authors: Antoine Cellerier <dionoea @t videolan d.t org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_access.h>
37 /*****************************************************************************
39 *****************************************************************************/
40 static int ReadDVD( stream_t
*, input_item_node_t
* );
41 static int ReadDVD_VR( stream_t
*, input_item_node_t
* );
43 static const char *StreamLocation( const stream_t
*s
)
45 return s
->psz_filepath
? s
->psz_filepath
: s
->psz_url
;
48 /*****************************************************************************
49 * Import_IFO: main import function
50 *****************************************************************************/
51 int Import_IFO( vlc_object_t
*p_this
)
53 stream_t
*p_stream
= (stream_t
*)p_this
;
55 if( !stream_HasExtension( p_stream
, ".IFO" ) )
58 const char *psz_location
= StreamLocation( p_stream
);
59 if( psz_location
== NULL
)
62 size_t len
= strlen( psz_location
);
66 const char *psz_probe
;
67 const char *psz_file
= &psz_location
[len
- 12];
68 /* Valid filenames are :
70 * - VTS_XX_X.IFO where X are digits
72 if( !strncasecmp( psz_file
, "VIDEO_TS", 8 ) ||
73 !strncasecmp( psz_file
, "VTS_", 4 ) )
75 psz_probe
= "DVDVIDEO";
76 p_stream
->pf_readdir
= ReadDVD
;
78 /* Valid filename for DVD-VR is VR_MANGR.IFO */
79 else if( !strncasecmp( psz_file
, "VR_MANGR", 8 ) )
81 psz_probe
= "DVD_RTR_";
82 p_stream
->pf_readdir
= ReadDVD_VR
;
87 const uint8_t *p_peek
;
88 ssize_t i_peek
= vlc_stream_Peek( p_stream
->s
, &p_peek
, 8 );
89 if( i_peek
< 8 || memcmp( p_peek
, psz_probe
, 8 ) )
92 p_stream
->pf_control
= PlaylistControl
;
97 static int ReadDVD( stream_t
*p_stream
, input_item_node_t
*node
)
99 const char *psz_location
= StreamLocation(p_stream
);
101 char *psz_url
= strndup( psz_location
, strlen( psz_location
) - 12 );
105 input_item_t
*p_input
= input_item_New( psz_url
, psz_url
);
108 input_item_AddOption( p_input
, "demux=dvd", VLC_INPUT_OPTION_TRUSTED
);
109 input_item_node_AppendItem( node
, p_input
);
110 input_item_Release( p_input
);
118 static int ReadDVD_VR( stream_t
*p_stream
, input_item_node_t
*node
)
120 const char *psz_location
= StreamLocation(p_stream
);
122 size_t len
= strlen( psz_location
);
123 char *psz_url
= strdup( psz_location
);
125 if( unlikely( psz_url
== NULL
) )
128 strcpy( &psz_url
[len
- 12], "VR_MOVIE.VRO" );
130 input_item_t
*p_input
= input_item_New( psz_url
, psz_url
);
133 input_item_node_AppendItem( node
, p_input
);
134 input_item_Release( p_input
);