From 3207c28b5c2956674cb25f1d1f1fc3e9da8067fb Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 21 Mar 2010 03:21:08 +0000 Subject: [PATCH] Added Source class to parse HandBrake output Added a Source class which executes HandBrake -t 0 to list the available titles and streams in a given source. Added a placeholder on the source-details page to display HandBrake output --- HandBrakeCluster/Rips/Source.class.php | 43 ++++++++++++++++++++++++++ pages/browse/source-details.php | 13 +++++--- templates/browse/source-details.tpl | 6 +++- 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 HandBrakeCluster/Rips/Source.class.php diff --git a/HandBrakeCluster/Rips/Source.class.php b/HandBrakeCluster/Rips/Source.class.php new file mode 100644 index 0000000..2a56e39 --- /dev/null +++ b/HandBrakeCluster/Rips/Source.class.php @@ -0,0 +1,43 @@ +source = $source; + + $this->scan(); + } + + protected function scan() { + $source_shell = escapeshellarg($this->source); + $handbrake_cmd = "HandBrakeCLI -i {$source_shell} -t 0"; + + $handbrake_pid = popen($handbrake_cmd, 'r'); + $handbrake_output = fread($handbrake_pid, 1024); + while (!feof($handbrake_pid)) { + $handbrake_output = fread($handbrake_pid, 1024); + } + pclose($handbrake_pid); + + + // Process the output + $lines = explode("\n", $handbrake_output); + foreach ($lines as $line) { + // Skip any line that doesn't begin with a + (with optional leading whitespace) + if ( ! preg_match('/\s*\+/', $line)) { + continue; + } + + $this->output .= $line; + } + } + + public function output() { + return $output; + } +}; + +?> \ No newline at end of file diff --git a/pages/browse/source-details.php b/pages/browse/source-details.php index e20408b..22ba9b4 100644 --- a/pages/browse/source-details.php +++ b/pages/browse/source-details.php @@ -6,19 +6,22 @@ $config = $main->config(); // Grab the name of this source $source_id = $req->get('id'); -$source = base64_decode(str_replace('-', '/', $source_id)); -$real_source = realpath($source); +$source_path = base64_decode(str_replace('-', '/', $source_id)); +$real_source_path = realpath($source_path); // Ensure the source is a valid directory, and lies below the configured source_dir -if (!is_dir($source)) { +if (!is_dir($source_path)) { return; } - $real_source_dir = realpath($config->get('rips.source_dir')); -if (substr($real_source, 0, strlen($real_source_dir)) != $real_source_dir) { +if (substr($real_source_path, 0, strlen($real_source_dir)) != $real_source_dir) { return; } +$source = new HandBrakeCluster_Rips_Source($source_path); + +$this->smarty->assign('source_path', $source_path); $this->smarty->assign('source', $source); +$this->smarty->assign('output', $source->output()); ?> \ No newline at end of file diff --git a/templates/browse/source-details.tpl b/templates/browse/source-details.tpl index ab75372..cb9295e 100644 --- a/templates/browse/source-details.tpl +++ b/templates/browse/source-details.tpl @@ -12,7 +12,11 @@ Source - {$source|escape:"html"} + {$source_path|escape:"html"} + + + Output + {$output|escape:"html"}