commit 9a954b2b9dc1fb1910e4ddabcf84e9ee50e0269f Author: Ben Roberts Date: Mon Dec 12 00:48:50 2011 +0000 Initial commit Basic framework for application including two sample plugins: TV and RouterboardFirmware. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb612d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Eclipse project +.buildpath +.project +.settings diff --git a/private/.gitignore b/private/.gitignore new file mode 100644 index 0000000..52c2514 --- /dev/null +++ b/private/.gitignore @@ -0,0 +1,4 @@ +# configuration files +config.php +dbconfig.conf +settings.txt diff --git a/source/dispatcher.php b/source/dispatcher.php new file mode 100644 index 0000000..2835ab9 --- /dev/null +++ b/source/dispatcher.php @@ -0,0 +1,37 @@ +getMessage()); +} + + +?> \ No newline at end of file diff --git a/source/lib/DownloadDispatcher/Processor.class.php b/source/lib/DownloadDispatcher/Processor.class.php new file mode 100644 index 0000000..c52313e --- /dev/null +++ b/source/lib/DownloadDispatcher/Processor.class.php @@ -0,0 +1,31 @@ +config(); + $log = $main->log(); + + // Find the list of available plugins + DownloadDispatcher_Source_PluginFactory::scan(); + $plugins = DownloadDispatcher_Source_PluginFactory::getValidPlugins(); + + $enabled_plugins = $config->get('sources'); + foreach ($plugins as $plugin_name) { + if (in_array($plugin_name, $enabled_plugins)) { + $plugin = DownloadDispatcher_Source_PluginFactory::create($plugin_name, $config, $log); + $plugin->run(); + } + } + } + +} + +?> \ No newline at end of file diff --git a/source/lib/DownloadDispatcher/Source/IPlugin.class.php b/source/lib/DownloadDispatcher/Source/IPlugin.class.php new file mode 100644 index 0000000..18360cc --- /dev/null +++ b/source/lib/DownloadDispatcher/Source/IPlugin.class.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php b/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php new file mode 100644 index 0000000..178983c --- /dev/null +++ b/source/lib/DownloadDispatcher/Source/Plugin/RouterboardFirmware.class.php @@ -0,0 +1,63 @@ +config = $config; + $this->log = $log; + } + + public function run() { + DownloadDispatcher_LogEntry::debug($this->log, 'Running RouterboardFirmware dispatcher'); + + // Iterate over source directories, and move matched files to the output directory + $source_dirs = $this->config->get('sources.RouterboardFirmware.input-directories'); + foreach ($source_dirs as $dir) { + if (is_dir($dir) && is_readable($dir)) { + $this->process_dir($dir); + } else { + DownloadDispatcher_LogEntry::warning($this->log, "RouterboardFirmware 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 + } + + protected function identify_output_dir($dir, $file) { + // TODO - Generate the correct output directory, apply any special case mappings, and ensure the destination exists + } + + protected function identify_duplicate($dir, $file) { + // TODO - Verify that the file we've found hasn't already been processed + // Use the cache to reduce processing overhead + } + + protected function rename_output($dir, $file) { + // TODO - use tvrenamer to update the filenames + } + + +} + +?> \ No newline at end of file diff --git a/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php b/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php new file mode 100644 index 0000000..6c68abe --- /dev/null +++ b/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php @@ -0,0 +1,68 @@ +config = $config; + $this->log = $log; + } + + public function run() { + DownloadDispatcher_LogEntry::debug($this->log, 'Running TV dispatcher'); + + // Iterate over source directories, and move matched files to the output directory + $source_dirs = $this->config->get('sources.TV.input-directories'); + foreach ($source_dirs as $dir) { + if (is_dir($dir) && is_readable($dir)) { + $this->process_dir($dir); + } 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 + } + + protected function identify_output_dir($dir, $file) { + // TODO - Generate the correct output directory, apply any special case mappings, and ensure the destination exists + } + + protected function identify_duplicate($dir, $file) { + // TODO - Verify that the file we've found hasn't already been processed + // Use the cache to reduce processing overhead + // TODO - Upstream caching + } + + protected function rename_output($dir, $file) { + // 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/PluginFactory.class.php b/source/lib/DownloadDispatcher/Source/PluginFactory.class.php new file mode 100644 index 0000000..17517dc --- /dev/null +++ b/source/lib/DownloadDispatcher/Source/PluginFactory.class.php @@ -0,0 +1,30 @@ + 'DownloadDispatcher/Source/Plugin/', + ); + + + public static function init() { + + } + + public static function create($plugin, SihnonFramework_Config $config, SihnonFramework_Log $log) { + self::ensureScanned(); + + if (! self::isValidPlugin($plugin)) { + throw new Sihnon_Exception_InvalidPluginName($plugin); + } + + $classname = self::classname($plugin); + + return call_user_func(array($classname, 'create'), $config, $log); + } + +} + +?> \ No newline at end of file