Added caching to Sources
Added caching to Sources. Updated the source browser to mark sources which are still cached
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
?>
|
||||
@@ -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);
|
||||
|
||||
?>
|
||||
@@ -2,11 +2,15 @@
|
||||
|
||||
{if $sources}
|
||||
<p>
|
||||
The following DVD sources are available to be ripped:
|
||||
The list below contains all the DVD sources that are available and ready for ripping.
|
||||
</p>
|
||||
<p>
|
||||
Sources that have recently been scanned are marked <em>(cached)</em> 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.
|
||||
</p>
|
||||
<ul>
|
||||
{foreach from=$sources item=source}
|
||||
<li><a href="{$base_uri}browse/source-details/id/{$source|base64_encode|replace:"/":"-"}" title="View source details">{$source|escape:'html'}</a></li>
|
||||
<li><a href="{$base_uri}browse/source-details/id/{$source|base64_encode|replace:"/":"-"}" title="View source details">{$source|escape:'html'}</a>{if $sources_cached.$source} (cached){/if}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
{else}
|
||||
|
||||
Reference in New Issue
Block a user