Added source browser
Added a SourceLister class, which enumerates all DVD folders below a given starting directory. Added a source browse page to list the available sources
This commit is contained in:
@@ -2,16 +2,18 @@
|
||||
|
||||
class HandBrakeCluster_Exception extends Exception {};
|
||||
|
||||
class HandBrakeCluster_Exception_DatabaseConfigMissing extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_DatabaseConnectFailed extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_NoDatabaseConnection extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_DatabaseQueryFailed extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_ResultCountMismatch extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_DatabaseConfigMissing extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_DatabaseConnectFailed extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_NoDatabaseConnection extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_DatabaseQueryFailed extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_ResultCountMismatch extends HandBrakeCluster_Exception {};
|
||||
|
||||
class HandBrakeCluster_Exception_UnknownSetting extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_UnknownSetting extends HandBrakeCluster_Exception {};
|
||||
|
||||
class HandBrakeCluster_Exception_TemplateException extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_Unauthorized extends HandBrakeCluster_Exception_TemplateException {};
|
||||
class HandBrakeCluster_Exception_FileNotFound extends HandBrakeCluster_Exception_TemplateException {};
|
||||
class HandBrakeCluster_Exception_TemplateException extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_Unauthorized extends HandBrakeCluster_Exception_TemplateException {};
|
||||
class HandBrakeCluster_Exception_FileNotFound extends HandBrakeCluster_Exception_TemplateException {};
|
||||
|
||||
?>
|
||||
class HandBrakeCluster_Exception_InvalidSourceDirectory extends HandBrakeCluster_Exception {};
|
||||
|
||||
?>
|
||||
56
HandBrakeCluster/Rips/SourceLister.class.php
Normal file
56
HandBrakeCluster/Rips/SourceLister.class.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_Rips_SourceLister {
|
||||
|
||||
protected $base_directory;
|
||||
protected $sources = array();
|
||||
|
||||
public function __construct($base_directory) {
|
||||
$this->base_directory = $base_directory;
|
||||
|
||||
$this->scan();
|
||||
}
|
||||
|
||||
public function scan() {
|
||||
if (!is_dir($this->base_directory)) {
|
||||
throw new HandBrakeCluster_Exception_InvalidSourceDir($this->base_directory);
|
||||
}
|
||||
|
||||
// Define a queue of directories to scan, starting with the base directory,
|
||||
// and keep going until they have all been scanned
|
||||
$scan_directories = array($this->base_directory);
|
||||
while ($scan_directories) {
|
||||
$dir = dir(array_shift($scan_directories));
|
||||
|
||||
while (($entry = $dir->read()) !== false) {
|
||||
if ($entry == '.' || $entry == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip any non-directories
|
||||
$source = $dir->path . DIRECTORY_SEPARATOR . $entry;
|
||||
if (!is_dir($source)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Accept this dir as a source if it contains a VIDEO_TS dir,
|
||||
// otherwise add the dir to the queue to scan deeper
|
||||
$source_vts = $source . DIRECTORY_SEPARATOR . 'VIDEO_TS';
|
||||
if (is_dir($source_vts)) {
|
||||
$this->sources[] = $source_vts;
|
||||
} else {
|
||||
$scan_directories[] = $source;
|
||||
}
|
||||
}
|
||||
|
||||
$dir->close();
|
||||
}
|
||||
}
|
||||
|
||||
public function sources() {
|
||||
return $this->sources;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
10
pages/browse/sources.php
Normal file
10
pages/browse/sources.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$main = HandBrakeCluster_Main::instance();
|
||||
$config = $main->config();
|
||||
|
||||
$lister = new HandBrakeCluster_Rips_SourceLister($config->get('rips.source_dir'));
|
||||
|
||||
$this->smarty->assign('sources', $lister->sources());
|
||||
|
||||
?>
|
||||
16
templates/browse/sources.tpl
Normal file
16
templates/browse/sources.tpl
Normal file
@@ -0,0 +1,16 @@
|
||||
<h2>Sources</h2>
|
||||
|
||||
{if $sources}
|
||||
<p>
|
||||
The following DVD sources are available to be ripped:
|
||||
</p>
|
||||
<ul>
|
||||
{foreach from=$sources item=source}
|
||||
<li>{$source|escape:'html'}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
{else}
|
||||
<p>
|
||||
<em>There are currently no DVD sources available to rip.</em>
|
||||
</p>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user