OSDN Git Service

initialize title->angle_count to 1
[handbrake-jp/handbrake-jp-git.git] / libhb / batch.c
1 /* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
2
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. */
6
7 #include "hb.h"
8 #include "lang.h"
9
10 struct hb_batch_s
11 {
12     char      * path;
13     hb_list_t * list_file;
14 };
15
16 /***********************************************************************
17  * hb_batch_init
18  ***********************************************************************
19  *
20  **********************************************************************/
21 hb_batch_t * hb_batch_init( char * path )
22 {
23     hb_batch_t    * d;
24     struct stat     sb;
25     DIR           * dir;
26     struct dirent * entry;
27     char          * filename;
28
29     if ( stat( path, &sb ) )
30         return NULL;
31
32     if ( !S_ISDIR( sb.st_mode ) )
33         return NULL;
34
35     dir = opendir( path );
36     if ( dir == NULL )
37         return NULL;
38
39     d = calloc( sizeof( hb_batch_t ), 1 );
40     d->list_file = hb_list_init();
41
42     while ( (entry = readdir( dir ) ) )
43     {
44         filename = hb_strdup_printf( "%s" DIR_SEP_STR "%s", path, entry->d_name );
45         if ( stat( filename, &sb ) )
46         {
47             free( filename );
48             continue;
49         }
50
51         if ( !S_ISREG( sb.st_mode ) )
52         {
53             free( filename );
54             continue;
55         }
56
57         hb_list_add( d->list_file, filename );
58     }
59
60     if ( hb_list_count( d->list_file ) == 0 )
61     {
62         hb_list_close( &d->list_file );
63         free( d );
64         return NULL;
65     }
66
67     d->path = strdup( path );
68
69     return d;
70 }
71
72 /***********************************************************************
73  * hb_batch_title_count
74  **********************************************************************/
75 int hb_batch_title_count( hb_batch_t * d )
76 {
77     return hb_list_count( d->list_file );
78 }
79
80 /***********************************************************************
81  * hb_batch_title_scan
82  **********************************************************************/
83 hb_title_t * hb_batch_title_scan( hb_batch_t * d, int t )
84 {
85
86     hb_title_t   * title;
87     char         * filename;
88     hb_stream_t  * stream;
89
90     if ( t < 0 )
91         return NULL;
92
93     filename = hb_list_item( d->list_file, t - 1 );
94     if ( filename == NULL )
95         return NULL;
96
97     stream = hb_stream_open( filename, 0 );
98     if ( stream == NULL )
99         return NULL;
100
101     title = hb_stream_title_scan( stream );
102     hb_stream_close( &stream );
103     if ( title != NULL )
104     {
105         title->index = t;
106     }
107
108     return title;
109 }
110
111 /***********************************************************************
112  * hb_batch_close
113  ***********************************************************************
114  * Closes and frees everything
115  **********************************************************************/
116 void hb_batch_close( hb_batch_t ** _d )
117 {
118     hb_batch_t * d = *_d;
119     char       * filename;
120
121     while ( ( filename = hb_list_item( d->list_file, 0 ) ) )
122     {
123         hb_list_rem( d->list_file, filename );
124         free( filename );
125     }
126     hb_list_close( &d->list_file );
127     free( d->path );
128     free( d );
129     *_d = NULL;
130 }
131