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