Update handbrake backend to rip to temp dir
This commit is contained in:
@@ -30,11 +30,14 @@ class Net_Gearman_Job_HandBrake extends Net_Gearman_Job_Common implements Rippin
|
|||||||
|
|
||||||
$this->job = RippingCluster_Job::fromId($args['rip_options']['id']);
|
$this->job = RippingCluster_Job::fromId($args['rip_options']['id']);
|
||||||
|
|
||||||
|
// Substitute a temporary output filename into the rip options
|
||||||
|
$args['temp_output_filename'] = tempnam($config->get('rips.temp_dir', '/tmp'), 'hbr_');
|
||||||
|
|
||||||
$handbrake_cmd_raw = array(
|
$handbrake_cmd_raw = array(
|
||||||
'-n', $config->get('rips.nice'),
|
'-n', $config->get('rips.nice'),
|
||||||
$config->get('rips.handbrake_binary'),
|
$config->get('rips.handbrake_binary'),
|
||||||
self::evaluateOption($args['rip_options'], 'input_filename', '-i'),
|
self::evaluateOption($args['rip_options'], 'input_filename', '-i'),
|
||||||
self::evaluateOption($args['rip_options'], 'output_filename', '-o'),
|
self::evaluateOption($args, 'temp_output_filename', '-o'),
|
||||||
self::evaluateOption($args['rip_options'], 'title'),
|
self::evaluateOption($args['rip_options'], 'title'),
|
||||||
self::evaluateOption($args['rip_options'], 'format', '-f'),
|
self::evaluateOption($args['rip_options'], 'format', '-f'),
|
||||||
self::evaluateOption($args['rip_options'], 'video_codec', '-e'),
|
self::evaluateOption($args['rip_options'], 'video_codec', '-e'),
|
||||||
@@ -61,12 +64,24 @@ class Net_Gearman_Job_HandBrake extends Net_Gearman_Job_Common implements Rippin
|
|||||||
|
|
||||||
list($return_val, $stdout, $stderr) = RippingCluster_ForegroundTask::execute($handbrake_cmd, null, null, null, array($this, 'callbackOutput'), array($this, 'callbackOutput'), $this);
|
list($return_val, $stdout, $stderr) = RippingCluster_ForegroundTask::execute($handbrake_cmd, null, null, null, array($this, 'callbackOutput'), array($this, 'callbackOutput'), $this);
|
||||||
if ($return_val) {
|
if ($return_val) {
|
||||||
|
// Remove any temporary output files
|
||||||
|
if (file_exists($args['temp_output_filename'])) {
|
||||||
|
unlink($args['temp_output_filename']);
|
||||||
|
}
|
||||||
$this->fail($return_val);
|
$this->fail($return_val);
|
||||||
} else {
|
} else {
|
||||||
$this->job->updateStatus(RippingCluster_JobStatus::COMPLETE);
|
// Move the temporary output file to the desired destination
|
||||||
$this->complete( array(
|
$move = rename($args['temp_output_filename'], $args['rip_options']['output_filename']);
|
||||||
'id' => $this->job->id()
|
if ($move) {
|
||||||
));
|
$this->job->updateStatus(RippingCluster_JobStatus::COMPLETE);
|
||||||
|
$this->complete( array(
|
||||||
|
'id' => $this->job->id()
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
RippingCluster_WorkerLogEntry::error($log, $this->job->id(), "Failed to move temporary output file to proper destination. File retained as '{$args['temp_output_filename']}'.");
|
||||||
|
$this->job->updateStatus(RippingCluster_JobStatus::FAILED);
|
||||||
|
$this->fail('-1');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user