Reworked handbrake commandline construction

Added a function to construct commandline parameters from rip_options
array to exclude any unspecified options, and simplify handling of
special cases.
This commit is contained in:
Ben Roberts
2010-02-19 15:51:08 +00:00
parent 2ba73fe6df
commit 35b5968b33

View File

@@ -11,6 +11,7 @@ use Log::Handler;
use Pod::Usage;
use String::Random qw/random_string/;
use Storable qw/thaw/;
use Switch;
# Handle interrupts, and term signals
$SIG{'INT'} = 'INT_handler';
@@ -79,38 +80,29 @@ sub do_rip {
my $uuid = random_string('cccccc');
$log->debug("Using $uuid as unique identifier for this job");
my $rip_filename = $rip_options{output_filename};
$rip_filename =~ s/\.([^\.]+)$/\.$uuid\.$1/;
# Generate deinterlace options
my @deinterlace_options;
push @deinterlace_options, '-d' if ($rip_options{deinterlace} == 1);
push @deinterlace_options, '-5' if ($rip_options{deinterlace} == 2);
my @title_options;
if ($rip_options{title} < 0) {
push @title_options, '-L';
} else {
push @title_options, '-t', $rip_options{title};
}
$rip_options{unique_output_filename} = $rip_options{output_filename};
$rip_options{unique_output_filename} =~ s/\.([^\.]+)$/\.$uuid\.$1/;
# Generate the command line for handbrake
my @handbrake_cmd = (
# Reduce the priority of the ripping process, since it is very processor intensive
'nice', '-n', $rip_options{nice},
# Construct the handbrake command line
$options{handbrake},
'-i', $rip_options{input_filename},
'-o', $rip_filename,
@title_options,
'-f', $rip_options{format},
'-e', $rip_options{video_codec},
'-q', $rip_options{quantizer},
'-w', $rip_options{video_width},
'-l', $rip_options{video_height},
@deinterlace_options,
'-a', $rip_options{audio_tracks},
'-E', $rip_options{audio_codec},
'-A', $rip_options{audio_names},
'-s', $rip_options{subtitle_tracks},
get_options(\%rip_options, 'input_filename', '-i'),
get_options(\%rip_options, 'unique_output_filename', '-o'),
get_options(\%rip_options, 'title'),
get_options(\%rip_options, 'format', '-f'),
get_options(\%rip_options, 'video_codec', '-e'),
get_options(\%rip_options, 'quantizer', '-q'),
get_options(\%rip_options, 'video_width', '-w'),
get_options(\%rip_options, 'video_height', '-l'),
get_options(\%rip_options, 'deinterlace'),
get_options(\%rip_options, 'audio_tracks', '-a'),
get_options(\%rip_options, 'audio_codec', '-E'),
get_options(\%rip_options, 'audio_names', '-A'),
get_options(\%rip_options, 'subtitle_tracks', '-s'),
);
$log->debug("Beginning ripping process with command:\n" . join(' ', @handbrake_cmd));
@@ -136,8 +128,31 @@ sub do_rip {
return undef;
}
$log->notice("Finished rip to $rip_filename");
return $rip_filename;
$log->notice("Finished rip to $rip_options{unique_output_filename}");
return $rip_options{unique_output_filename};
}
sub get_options {
my $rip_options = shift or die;
my $option_name = shift or die;
my $option = shift;
switch ($option_name) {
case 'title' {
return ('-L') if ! defined($rip_options->{$option_name}) || $rip_options->{$option_name} < 0;
return ('-t', $rip_options->{$option_name});
}
case 'deinterlace' {
switch ($rip_options->{$option_name}) {
case 1 { return ('-d') }
case 2 { return ('-5') }
return ();
}
}
return (defined $rip_options->{$option_name} ? ($option, $rip_options->{$option_name}) : ());
}
}
sub INT_handler {