2009-11-25 21:14:44 +00:00
|
|
|
/* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
|
|
|
|
|
|
|
|
This file is part of the HandBrake source code.
|
|
|
|
Homepage: <http://handbrake.fr/>.
|
|
|
|
It may be used under the terms of the GNU General Public License. */
|
|
|
|
|
|
|
|
#include "hb.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
struct hb_batch_s
|
|
|
|
{
|
|
|
|
char * path;
|
|
|
|
hb_list_t * list_file;
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* hb_batch_init
|
|
|
|
***********************************************************************
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
hb_batch_t * hb_batch_init( char * path )
|
|
|
|
{
|
|
|
|
hb_batch_t * d;
|
|
|
|
struct stat sb;
|
|
|
|
DIR * dir;
|
|
|
|
struct dirent * entry;
|
|
|
|
char * filename;
|
|
|
|
|
|
|
|
if ( stat( path, &sb ) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ( !S_ISDIR( sb.st_mode ) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dir = opendir( path );
|
|
|
|
if ( dir == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
d = calloc( sizeof( hb_batch_t ), 1 );
|
|
|
|
d->list_file = hb_list_init();
|
|
|
|
|
|
|
|
while ( (entry = readdir( dir ) ) )
|
|
|
|
{
|
|
|
|
filename = hb_strdup_printf( "%s" DIR_SEP_STR "%s", path, entry->d_name );
|
|
|
|
if ( stat( filename, &sb ) )
|
|
|
|
{
|
|
|
|
free( filename );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !S_ISREG( sb.st_mode ) )
|
|
|
|
{
|
|
|
|
free( filename );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
hb_list_add( d->list_file, filename );
|
|
|
|
}
|
|
|
|
|
2011-07-19 17:36:12 +00:00
|
|
|
closedir( dir );
|
2009-11-25 21:14:44 +00:00
|
|
|
if ( hb_list_count( d->list_file ) == 0 )
|
|
|
|
{
|
|
|
|
hb_list_close( &d->list_file );
|
|
|
|
free( d );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->path = strdup( path );
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* hb_batch_title_count
|
|
|
|
**********************************************************************/
|
|
|
|
int hb_batch_title_count( hb_batch_t * d )
|
|
|
|
{
|
|
|
|
return hb_list_count( d->list_file );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* hb_batch_title_scan
|
|
|
|
**********************************************************************/
|
|
|
|
hb_title_t * hb_batch_title_scan( hb_batch_t * d, int t )
|
|
|
|
{
|
|
|
|
|
|
|
|
hb_title_t * title;
|
|
|
|
char * filename;
|
|
|
|
hb_stream_t * stream;
|
|
|
|
|
2009-11-25 21:54:06 +00:00
|
|
|
if ( t < 0 )
|
2009-11-25 21:14:44 +00:00
|
|
|
return NULL;
|
|
|
|
|
2010-09-15 16:34:22 +00:00
|
|
|
filename = hb_list_item( d->list_file, t - 1 );
|
2009-11-25 21:14:44 +00:00
|
|
|
if ( filename == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
2011-07-27 15:09:49 +00:00
|
|
|
hb_log( "batch: scanning %s", filename );
|
|
|
|
title = hb_title_init( filename, 0 );
|
|
|
|
stream = hb_stream_open( filename, title, 1 );
|
2009-11-25 21:14:44 +00:00
|
|
|
if ( stream == NULL )
|
2011-07-27 15:09:49 +00:00
|
|
|
{
|
|
|
|
hb_title_close( &title );
|
2009-11-25 21:14:44 +00:00
|
|
|
return NULL;
|
2011-07-27 15:09:49 +00:00
|
|
|
}
|
2009-11-25 21:14:44 +00:00
|
|
|
|
2011-07-27 15:09:49 +00:00
|
|
|
title = hb_stream_title_scan( stream, title );
|
2009-11-25 21:14:44 +00:00
|
|
|
hb_stream_close( &stream );
|
2010-09-15 16:34:22 +00:00
|
|
|
if ( title != NULL )
|
|
|
|
{
|
|
|
|
title->index = t;
|
|
|
|
}
|
2009-11-25 21:14:44 +00:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* hb_batch_close
|
|
|
|
***********************************************************************
|
|
|
|
* Closes and frees everything
|
|
|
|
**********************************************************************/
|
|
|
|
void hb_batch_close( hb_batch_t ** _d )
|
|
|
|
{
|
|
|
|
hb_batch_t * d = *_d;
|
|
|
|
char * filename;
|
|
|
|
|
|
|
|
while ( ( filename = hb_list_item( d->list_file, 0 ) ) )
|
|
|
|
{
|
|
|
|
hb_list_rem( d->list_file, filename );
|
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
hb_list_close( &d->list_file );
|
|
|
|
free( d->path );
|
|
|
|
free( d );
|
|
|
|
*_d = NULL;
|
|
|
|
}
|
|
|
|
|