From 0646848193010ef238f131e5745cba60fa757ec6 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Tue, 13 Dec 2011 01:11:57 +0000 Subject: [PATCH] Update TV Source to find media files Updated TV Source to iterate over media files and check each against the cache to ignore previously seen items. --- .../Plugin/RouterboardFirmware.class.php | 2 +- .../Source/Plugin/TV.class.php | 26 ++++++++------- .../Source/PluginBase.class.php | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 source/lib/DownloadDispatcher/Source/PluginBase.class.php diff --git a/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php b/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php index 178983c..5860909 100644 --- a/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php +++ b/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php @@ -1,6 +1,6 @@ config->get('sources.TV.input-directories'); foreach ($source_dirs as $dir) { if (is_dir($dir) && is_readable($dir)) { - $this->process_dir($dir); + $iterator = new DownloadDispatcher_Utility_MediaFilesIterator(new DownloadDispatcher_Utility_VisibleFilesIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)))); + foreach ($iterator as /** @var SplFileInfo */ $file) { + $this->process_matched_file($file->getPath(), $file->getFilename()); + } } else { DownloadDispatcher_LogEntry::warning($this->log, "TV input directory '{$dir}' does not exist or cannot be read."); } } } - - protected function process_dir($dir) { - // TODO - Iterate over the contents of the directory, process files and recurse deeper - } - + protected function process_matched_file($dir, $file) { // TODO - Handle movement of the matched file to the correct output directory // Handle direct media files, and also RAR archives + DownloadDispatcher_LogEntry::debug($this->log, "Media file: {$file}"); + + // Check to see if this file has been handled previously + if ($this->check_processed($dir . '/' . $file)) { + DownloadDispatcher_LogEntry::debug($this->log, "Skipping previously seen file"); + return; + } + } protected function identify_output_dir($dir, $file) { @@ -58,11 +65,6 @@ class DownloadDispatcher_Source_Plugin_TV extends DownloadDispatcher_PluginBase // TODO - use tvrenamer to update the filenames } - protected function mark_processed($dir, $file) { - // TODO - Update the cache to show that a file has already been handled - // TODO - Upstream caching - } - } ?> \ No newline at end of file diff --git a/source/lib/DownloadDispatcher/Source/PluginBase.class.php b/source/lib/DownloadDispatcher/Source/PluginBase.class.php new file mode 100644 index 0000000..72567c3 --- /dev/null +++ b/source/lib/DownloadDispatcher/Source/PluginBase.class.php @@ -0,0 +1,32 @@ +init_cache(); + + if ( ! in_array($file, static::$source_cache[get_called_class()])) { + static::$source_cache[get_called_class()][] = $file; + } + + // TODO - flush cache to persistent storage + } + + protected function check_processed($file) { + $this->init_cache(); + + return in_array($file, static::$source_cache[get_called_class()]); + } + +} + +?> \ No newline at end of file