qt: playlist: use item title if available
[vlc.git] / modules / demux / playlist / ifo.c
blob9468e133b48ed9e3e0bf782895b7ff206fd4d4f7
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 /*****************************************************************************
24 * Preamble
25 *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include <vlc_common.h>
31 #include <vlc_access.h>
32 #include <vlc_url.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 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" ) )
56 return VLC_EGENERIC;
58 const char *psz_location = StreamLocation( p_stream );
59 if( psz_location == NULL )
60 return VLC_EGENERIC;
62 size_t len = strlen( psz_location );
63 if( len < 12 )
64 return VLC_EGENERIC;
66 const char *psz_probe;
67 const char *psz_file = &psz_location[len - 12];
68 /* Valid filenames are :
69 * - VIDEO_TS.IFO
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;
84 else
85 return VLC_EGENERIC;
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 ) )
90 return VLC_EGENERIC;
92 p_stream->pf_control = PlaylistControl;
94 return VLC_SUCCESS;
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 );
102 if( !psz_url )
103 return VLC_ENOMEM;
105 input_item_t *p_input = input_item_New( psz_url, psz_url );
106 if( p_input )
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 );
113 free( psz_url );
115 return VLC_SUCCESS;
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 ) )
126 return VLC_EGENERIC;
128 strcpy( &psz_url[len - 12], "VR_MOVIE.VRO" );
130 input_item_t *p_input = input_item_New( psz_url, psz_url );
131 if( p_input )
133 input_item_node_AppendItem( node, p_input );
134 input_item_Release( p_input );
137 free( psz_url );
139 return VLC_SUCCESS;