3 Copyright (c) 2003-2015 HandBrake Team
4 This file is part of the HandBrake source code
5 Homepage: <http://handbrake.fr/>.
6 It may be used under the terms of the GNU General Public License v2.
7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
16 hb_list_t
* list_file
;
20 static int compare_str(const void *a
, const void *b
)
22 return strncmp(*(const char**)a
, *(const char**)b
, PATH_MAX
);
25 /***********************************************************************
27 ***********************************************************************
29 **********************************************************************/
30 hb_batch_t
* hb_batch_init( hb_handle_t
*h
, char * path
)
35 struct dirent
* entry
;
40 if ( hb_stat( path
, &sb
) )
43 if ( !S_ISDIR( sb
.st_mode
) )
46 dir
= hb_opendir(path
);
50 // Count the total number of entries
52 while ( (entry
= hb_readdir( dir
) ) )
56 files
= malloc(count
* sizeof(char*));
58 // Find all regular files
61 while ( (entry
= hb_readdir( dir
) ) )
63 filename
= hb_strdup_printf( "%s" DIR_SEP_STR
"%s", path
, entry
->d_name
);
64 if ( hb_stat( filename
, &sb
) )
70 if ( !S_ISREG( sb
.st_mode
) )
76 files
[ii
++] = filename
;
81 qsort(files
, count
, sizeof(char*), compare_str
);
84 d
= calloc( sizeof( hb_batch_t
), 1 );
86 d
->list_file
= hb_list_init();
87 for (ii
= 0; ii
< count
; ii
++)
89 hb_list_add( d
->list_file
, files
[ii
] );
94 if ( hb_list_count( d
->list_file
) == 0 )
96 hb_list_close( &d
->list_file
);
101 d
->path
= strdup( path
);
106 /***********************************************************************
107 * hb_batch_title_count
108 **********************************************************************/
109 int hb_batch_title_count( hb_batch_t
* d
)
111 return hb_list_count( d
->list_file
);
114 /***********************************************************************
115 * hb_batch_title_scan
116 **********************************************************************/
117 hb_title_t
* hb_batch_title_scan( hb_batch_t
* d
, int t
)
122 hb_stream_t
* stream
;
127 filename
= hb_list_item( d
->list_file
, t
- 1 );
128 if ( filename
== NULL
)
131 hb_log( "batch: scanning %s", filename
);
132 title
= hb_title_init( filename
, t
);
133 stream
= hb_stream_open(d
->h
, filename
, title
, 1);
134 if ( stream
== NULL
)
136 hb_title_close( &title
);
140 title
= hb_stream_title_scan( stream
, title
);
141 hb_stream_close( &stream
);
146 /***********************************************************************
148 ***********************************************************************
149 * Closes and frees everything
150 **********************************************************************/
151 void hb_batch_close( hb_batch_t
** _d
)
153 hb_batch_t
* d
= *_d
;
156 while ( ( filename
= hb_list_item( d
->list_file
, 0 ) ) )
158 hb_list_rem( d
->list_file
, filename
);
161 hb_list_close( &d
->list_file
);