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.