From dd273fc6646266140c05447a17f991735a61631f Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 21 Mar 2010 23:16:09 +0000 Subject: [PATCH 1/2] Added cluster specific exceptions. Tidied up exception class hierarchy --- HandBrakeCluster/Exceptions.class.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/HandBrakeCluster/Exceptions.class.php b/HandBrakeCluster/Exceptions.class.php index 5bd80d9..e900b63 100644 --- a/HandBrakeCluster/Exceptions.class.php +++ b/HandBrakeCluster/Exceptions.class.php @@ -2,13 +2,15 @@ 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_DatabaseException extends HandBrakeCluster_Exception {}; +class HandBrakeCluster_Exception_DatabaseConfigMissing extends HandBrakeCluster_Exception_DatabaseException {}; +class HandBrakeCluster_Exception_DatabaseConnectFailed extends HandBrakeCluster_Exception_DatabaseException {}; +class HandBrakeCluster_Exception_NoDatabaseConnection extends HandBrakeCluster_Exception_DatabaseException {}; +class HandBrakeCluster_Exception_DatabaseQueryFailed extends HandBrakeCluster_Exception_DatabaseException {}; +class HandBrakeCluster_Exception_ResultCountMismatch extends HandBrakeCluster_Exception_DatabaseException {}; -class HandBrakeCluster_Exception_UnknownSetting extends HandBrakeCluster_Exception {}; +class HandBrakeCluster_Exception_ConfigException extends HandBrakeCluster_Exception {}; +class HandBrakeCluster_Exception_UnknownSetting extends HandBrakeCluster_Exception_ConfigException {}; class HandBrakeCluster_Exception_TemplateException extends HandBrakeCluster_Exception {}; class HandBrakeCluster_Exception_Unauthorized extends HandBrakeCluster_Exception_TemplateException {}; @@ -16,4 +18,8 @@ class HandBrakeCluster_Exception_FileNotFound extends HandBrakeCluster class HandBrakeCluster_Exception_InvalidSourceDirectory extends HandBrakeCluster_Exception {}; +class HandBrakeCluster_Exception_CacheException extends HandBrakeCluster_Exception {}; +class HandBrakeCluster_Exception_InvalidCacheDir extends HandBrakeCluster_Exception_CacheException {}; +class HandBrakeCluster_Exception_CacheObjectNotFound extends HandBrakeCluster_Exception_CacheException {}; + ?> \ No newline at end of file From 0d4ae9e9ef576b267a9a6fe09cd33ab4ca819cd4 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 21 Mar 2010 23:16:56 +0000 Subject: [PATCH 2/2] Added caching to Sources Added caching to Sources. Updated the source browser to mark sources which are still cached --- HandBrakeCluster/Rips/Source.class.php | 32 +++++++++++++++++++++++--- pages/browse/source-details.php | 3 +-- pages/browse/sources.php | 9 +++++++- templates/browse/sources.tpl | 8 +++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/HandBrakeCluster/Rips/Source.class.php b/HandBrakeCluster/Rips/Source.class.php index b107adc..b84ecc4 100644 --- a/HandBrakeCluster/Rips/Source.class.php +++ b/HandBrakeCluster/Rips/Source.class.php @@ -6,15 +6,33 @@ class HandBrakeCluster_Rips_Source { const PM_CHAPTER = 1; const PM_AUDIO = 2; const PM_SUBTITLE = 3; - + protected $source; protected $output; protected $titles = array(); - public function __construct($source) { - $this->source = $source; + public function __construct($source_filename, $use_cache) { + $this->source = $source_filename; $this->scan(); + + $main = HandBrakeCluster_Main::instance(); + $cache = $main->cache(); + $config = $main->config(); + + if ($use_cache) { + $cache->store($this->source, serialize($this), $config->get('rips.cache_ttl')); + } + } + + public static function load($source_filename, $use_cache = true) { + $cache = HandBrakeCluster_Main::instance()->cache(); + + if ($use_cache && $cache->exists($source_filename)) { + return unserialize($cache->fetch($source_filename)); + } else { + return new HandBrakeCluster_Rips_Source($source_filename, $use_cache); + } } protected function scan() { @@ -124,6 +142,14 @@ class HandBrakeCluster_Rips_Source { } } + public static function isCached($source_filename) { + $main = HandBrakeCluster_Main::instance(); + $cache = $main->cache(); + $config = $main->config(); + + return $cache->exists($source_filename, $config->get('rips.cache_ttl')); + } + public function addTitle(HandBrakeCluster_Rips_SourceTitle $title) { $this->titles[] = $title; } diff --git a/pages/browse/source-details.php b/pages/browse/source-details.php index 565f396..5ef21ed 100644 --- a/pages/browse/source-details.php +++ b/pages/browse/source-details.php @@ -18,11 +18,10 @@ if (substr($real_source_path, 0, strlen($real_source_dir)) != $real_source_dir) return; } -$source = new HandBrakeCluster_Rips_Source($source_path); +$source = HandBrakeCluster_Rips_Source::load($source_path); $this->smarty->assign('source_path', $source_path); $this->smarty->assign('source', $source); -$this->smarty->assign('output', $source->output()); $this->smarty->assign('titles', $source->titles()); ?> \ No newline at end of file diff --git a/pages/browse/sources.php b/pages/browse/sources.php index c96f227..13f6f48 100644 --- a/pages/browse/sources.php +++ b/pages/browse/sources.php @@ -4,7 +4,14 @@ $main = HandBrakeCluster_Main::instance(); $config = $main->config(); $lister = new HandBrakeCluster_Rips_SourceLister($config->get('rips.source_dir')); +$sources = $lister->sources(); -$this->smarty->assign('sources', $lister->sources()); +$sources_cached = array(); +foreach ($sources as $source) { + $sources_cached[$source] = HandBrakeCluster_Rips_Source::isCached($source); +} + +$this->smarty->assign('sources', $sources); +$this->smarty->assign('sources_cached', $sources_cached); ?> \ No newline at end of file diff --git a/templates/browse/sources.tpl b/templates/browse/sources.tpl index b04198b..22a8a7f 100644 --- a/templates/browse/sources.tpl +++ b/templates/browse/sources.tpl @@ -2,11 +2,15 @@ {if $sources}

- The following DVD sources are available to be ripped: + The list below contains all the DVD sources that are available and ready for ripping. +

+

+ Sources that have recently been scanned are marked (cached) and will load fairly quickly. + Sources that have not been cached will be scanned when the link is clicked, and this may take several minutes so please be patient.

{else}