Various UI improvements
This commit is contained in:
@@ -24,4 +24,7 @@ class HandBrakeCluster_Exception_CacheException extends HandBrakeCluster
|
||||
class HandBrakeCluster_Exception_InvalidCacheDir extends HandBrakeCluster_Exception_CacheException {};
|
||||
class HandBrakeCluster_Exception_CacheObjectNotFound extends HandBrakeCluster_Exception_CacheException {};
|
||||
|
||||
?>
|
||||
class HandBrakeCluster_Exception_LogicException extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_JobNotRunning extends HandBrakeCluster_Exception_LogicException {};
|
||||
|
||||
?>
|
||||
|
||||
@@ -44,6 +44,12 @@ class HandBrakeCluster_Job {
|
||||
$this->subtitle_tracks = $subtitle_tracks;
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
$this->id = null;
|
||||
|
||||
$this->create();
|
||||
}
|
||||
|
||||
public static function fromDatabaseRow($row) {
|
||||
return new HandBrakeCluster_Job(
|
||||
HandBrakeCluster_Rips_Source::load($rips['source']),
|
||||
@@ -124,12 +130,14 @@ class HandBrakeCluster_Job {
|
||||
$jobs = array();
|
||||
foreach ($titles as $title => $details) {
|
||||
if (HandBrakeCluster_Main::issetelse($details['queue'])) {
|
||||
HandBrakeCluster_Main::issetelse($details['output_filename'], HandBrakeCluster_Exception_InvalidParameters);
|
||||
|
||||
$job = new HandBrakeCluster_Job(
|
||||
$source,
|
||||
null,
|
||||
HandBrakeCluster_Main::issetelse($details['name'], 'unnamed job'),
|
||||
$source->filename(),
|
||||
HandBrakeCluster_Main::issetelse($details['output_filename'], HandBrakeCluster_Exception_InvalidParameters),
|
||||
$global_options['output-directory'] . DIRECTORY_SEPARATOR . $details['output_filename'],
|
||||
$title,
|
||||
$global_options['format'],
|
||||
$global_options['video-codec'],
|
||||
@@ -179,6 +187,18 @@ class HandBrakeCluster_Job {
|
||||
$status = HandBrakeCluster_JobStatus::updateStatusForJob($this, HandBrakeCluster_JobStatus::CREATED);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$database = HandBrakeCluster_Main::instance()->database();
|
||||
$database->update(
|
||||
'DELETE FROM jobs WHERE id=:job_id LIMIT 1',
|
||||
array(
|
||||
array(name => 'job_id', value => $this->id, type => PDO::PARAM_INT),
|
||||
)
|
||||
);
|
||||
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
public function queue($gearman) {
|
||||
$main = HandBrakeCluster_Main::instance();
|
||||
$config = $main->config();
|
||||
@@ -188,8 +208,8 @@ class HandBrakeCluster_Job {
|
||||
// Construct the rip options
|
||||
$rip_options = array(
|
||||
'nice' => $config->get('rips.nice', 15),
|
||||
'input_filename' => dirname($this->source_filename) . DIRECTORY_SEPARATOR . basename($this->source_filename),
|
||||
'output_filename' => dirname($this->destination_filename) . DIRECTORY_SEPARATOR . basename($this->destination_filename),
|
||||
'input_filename' => $this->source_filename,
|
||||
'output_filename' => $this->destination_filename,
|
||||
'title' => $this->title,
|
||||
'format' => $this->format,
|
||||
'video_codec' => $this->video_codec,
|
||||
@@ -233,6 +253,22 @@ class HandBrakeCluster_Job {
|
||||
return HandBrakeCluster_JobStatus::updateStatusForJob($this, $new_status, $rip_progress);
|
||||
}
|
||||
|
||||
public function calculateETA() {
|
||||
$current_status = $this->currentStatus();
|
||||
if ($current_status->status() != HandBrakeCluster_JobStatus::RUNNING) {
|
||||
throw new HandBrakeCluster_Exception_JobNotRunning();
|
||||
}
|
||||
|
||||
$running_time = $current_status->mtime() - $current_status->ctime();
|
||||
$progress = $current_status->ripProgress();
|
||||
|
||||
if ($progress > 0) {
|
||||
$remaining_time = round((100 - $progress) * ($running_time / $progress));
|
||||
}
|
||||
|
||||
return $remaining_time;
|
||||
}
|
||||
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class HandBrakeCluster_Main {
|
||||
$this->smarty->cache_dir = './tmp/cache';
|
||||
$this->smarty->config_fir = './config';
|
||||
|
||||
$this->smarty->register_modifier('formatDuration', array('HandBrakeCluster_Main', 'formatDuration'));
|
||||
|
||||
$this->smarty->assign('version', '0.1');
|
||||
|
||||
$this->base_uri = dirname($_SERVER['SCRIPT_NAME']) . '/';
|
||||
@@ -160,12 +162,39 @@ class HandBrakeCluster_Main {
|
||||
return $var;
|
||||
}
|
||||
|
||||
if (preg_match('/^HandBrakeCluster_Exception/', $default) && class_exists($default) && is_subclass_of($default, HandBrakeCluster_Exception)) {
|
||||
if (is_string($default) && preg_match('/^HandBrakeCluster_Exception/', $default) && class_exists($default) && is_subclass_of($default, HandBrakeCluster_Exception)) {
|
||||
throw new $default();
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public static function formatDuration($time) {
|
||||
if (is_null($time)) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
$labels = array('seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years');
|
||||
$limits = array(60, 3600, 86400, 604800, 2592000, 31556926, PHP_INT_MAX);
|
||||
|
||||
$working_time = $time;
|
||||
|
||||
$result = "";
|
||||
$ptr = count($labels) - 1;
|
||||
|
||||
while ($ptr >= 0 && $working_time < $limits[$ptr]) {
|
||||
--$ptr;
|
||||
}
|
||||
|
||||
while ($ptr >= 0) {
|
||||
$unit_time = floor($working_time / $limits[$ptr]);
|
||||
$working_time -= $unit_time * $limits[$ptr];
|
||||
$result = $result . ' ' . $unit_time . ' ' . $labels[$ptr];
|
||||
--$ptr;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -72,12 +72,16 @@ class HandBrakeCluster_RequestParser {
|
||||
return join('/', $this->page);
|
||||
}
|
||||
|
||||
public function exists($key) {
|
||||
return isset($this->vars[$key]);
|
||||
}
|
||||
|
||||
public function get($key, $default = null) {
|
||||
if (isset($this->vars[$key])) {
|
||||
return $this->vars[$key];
|
||||
}
|
||||
|
||||
if (is_subclass_of($default, HandBrakeCluster_Exception)) {
|
||||
if (is_string($default) && preg_match('/^HandBrakeCluster_Exception/', $default) && class_exists($default) && is_subclass_of($default, HandBrakeCluster_Exception)) {
|
||||
throw new $default();
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class HandBrakeCluster_Rips_Source {
|
||||
$title->addChapter($matches['id'], $matches['duration']);
|
||||
} break;
|
||||
|
||||
case $title && $mode == self::PM_AUDIO && preg_match('/^ \+ (?P<id>\d+), (?P<name>.+) \((?P<format>.+)\) \((?P<channels>.+) ch\) \((?P<language>.+)\), (?P<samplerate>\d+)Hz, (?P<bitrate>\d+)bps$/', $line, $matches): {
|
||||
case $title && $mode == self::PM_AUDIO && preg_match('/^ \+ (?P<id>\d+), (?P<name>.+) \((?P<format>.+)\) \((?P<channels>(.+ ch|Dolby Surround))\) \((?P<language>.+)\), (?P<samplerate>\d+)Hz, (?P<bitrate>\d+)bps$/', $line, $matches): {
|
||||
$title->addAudioTrack(
|
||||
new HandBrakeCluster_Rips_SourceAudioTrack(
|
||||
$matches['id'], $matches['name'], $matches['format'], $matches['channels'],
|
||||
@@ -196,7 +196,27 @@ class HandBrakeCluster_Rips_Source {
|
||||
}
|
||||
|
||||
return $longest_title;
|
||||
}
|
||||
}
|
||||
|
||||
public function longestTitleIndex() {
|
||||
$longest_index = null;
|
||||
$maximmum_duration = 0;
|
||||
|
||||
if ( ! $this->titles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for ($i = 0, $l = count($this->titles); $i < $l; ++$i) {
|
||||
$title = $this->titles[$i];
|
||||
$duration = $title->durationInSeconds();
|
||||
if ($duration > $maximum_duration) {
|
||||
$longest_index = $i;
|
||||
$maximum_duration = $duration;
|
||||
}
|
||||
}
|
||||
|
||||
return $longest_index;
|
||||
}
|
||||
|
||||
public function filename() {
|
||||
return $this->source;
|
||||
|
||||
Reference in New Issue
Block a user