1 /* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
13 hb_list_t * list_file;
16 /***********************************************************************
18 ***********************************************************************
20 **********************************************************************/
21 hb_batch_t * hb_batch_init( char * path )
26 struct dirent * entry;
29 if ( stat( path, &sb ) )
32 if ( !S_ISDIR( sb.st_mode ) )
35 dir = opendir( path );
39 d = calloc( sizeof( hb_batch_t ), 1 );
40 d->list_file = hb_list_init();
42 while ( (entry = readdir( dir ) ) )
44 filename = hb_strdup_printf( "%s" DIR_SEP_STR "%s", path, entry->d_name );
45 if ( stat( filename, &sb ) )
51 if ( !S_ISREG( sb.st_mode ) )
57 hb_list_add( d->list_file, filename );
60 if ( hb_list_count( d->list_file ) == 0 )
62 hb_list_close( &d->list_file );
67 d->path = strdup( path );
72 /***********************************************************************
73 * hb_batch_title_count
74 **********************************************************************/
75 int hb_batch_title_count( hb_batch_t * d )
77 return hb_list_count( d->list_file );
80 /***********************************************************************
82 **********************************************************************/
83 hb_title_t * hb_batch_title_scan( hb_batch_t * d, int t )
93 filename = hb_list_item( d->list_file, t );
94 if ( filename == NULL )
97 stream = hb_stream_open( filename, 0 );
101 title = hb_stream_title_scan( stream );
102 hb_stream_close( &stream );
107 /***********************************************************************
109 ***********************************************************************
110 * Closes and frees everything
111 **********************************************************************/
112 void hb_batch_close( hb_batch_t ** _d )
114 hb_batch_t * d = *_d;
117 while ( ( filename = hb_list_item( d->list_file, 0 ) ) )
119 hb_list_rem( d->list_file, filename );
122 hb_list_close( &d->list_file );