From 22613e030e4f64a029895c1873e3deb5ff08127a Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Mon, 30 Aug 2010 22:03:49 +0100 Subject: [PATCH] Adding Source class from earlier botched commit. --- lib/RippingCluster/Source.class.php | 105 ++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 lib/RippingCluster/Source.class.php diff --git a/lib/RippingCluster/Source.class.php b/lib/RippingCluster/Source.class.php new file mode 100644 index 0000000..e6e0556 --- /dev/null +++ b/lib/RippingCluster/Source.class.php @@ -0,0 +1,105 @@ +filename = $source_filename; + $this->plugin = $plugin; + + } + + public static function isCached($source_filename) { + $main = RippingCluster_Main::instance(); + $cache = $main->cache(); + $config = $main->config(); + + return $cache->exists($source_filename, $config->get('rips.cache_ttl')); + } + + public function cache() { + $main = RippingCluster_Main::instance(); + $cache = $main->cache(); + $config = $main->config(); + + $cache->store($this->filename, serialize($this), $config->get('rips.cache_ttl')); + } + + public static function encodeFilename($filename) { + return str_replace("/", "-", base64_encode($filename)); + } + + public function addTitle(RippingCluster_Rips_SourceTitle $title) { + $this->titles[] = $title; + } + + public function longestTitle() { + $longest_title = null; + $maximum_duration = 0; + + if ( ! $this->titles) { + return null; + } + + foreach ($this->titles as $title) { + $duration = $title->durationInSeconds(); + if ($duration > $maximum_duration) { + $longest_title = $title; + $maximum_duration = $duration; + } + } + + return $longest_title; + } + + public function longestTitleIndex() { + $longest_index = null; + $maximmum_duration = 0; + + if ( ! $this->titles) { + return null; + } + + for ($i = 0, $l = count($this->titles); $i < $l; ++$i) { + $title = $this->titles[$i]; + $duration = $title->durationInSeconds(); + if ($duration > $maximum_duration) { + $longest_index = $i; + $maximum_duration = $duration; + } + } + + return $longest_index; + } + + public function filename() { + return $this->filename; + } + + public function filenameEncoded() { + return self::encodeFilename($this->filename); + } + + public function plugin() { + return $this->plugin; + } + + public function titleCount() { + return count($this->titles); + } + + public function titles() { + return $this->titles; + } + +}; + +?>