Initial commit
Basic framework for application including two sample plugins: TV and RouterboardFirmware.
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Eclipse project
|
||||||
|
.buildpath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
4
private/.gitignore
vendored
Normal file
4
private/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# configuration files
|
||||||
|
config.php
|
||||||
|
dbconfig.conf
|
||||||
|
settings.txt
|
||||||
37
source/dispatcher.php
Normal file
37
source/dispatcher.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
define('DD_File', 'dispatcher');
|
||||||
|
|
||||||
|
$options = array();
|
||||||
|
if (isset($_SERVER['argv'])) {
|
||||||
|
$options = getopt('c:', array('config:'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['config'])) {
|
||||||
|
require_once $options['config'];
|
||||||
|
} else {
|
||||||
|
require_once '/etc/download-dispatcher/config.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once(SihnonFramework_Lib . 'SihnonFramework/Main.class.php');
|
||||||
|
|
||||||
|
SihnonFramework_Main::registerAutoloadClasses('SihnonFramework', SihnonFramework_Lib,
|
||||||
|
'DownloadDispatcher', SihnonFramework_Main::makeAbsolutePath(DownloadDispatcher_Lib));
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
$main = DownloadDispatcher_Main::instance();
|
||||||
|
DownloadDispatcher_LogEntry::setLocalProgname('download-dispatcher');
|
||||||
|
|
||||||
|
// Download Dispatcher entry point
|
||||||
|
DownloadDispatcher_Processor::run();
|
||||||
|
|
||||||
|
} catch (DownloadDispatcher_Exception $e) {
|
||||||
|
die("Uncaught Exception: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
31
source/lib/DownloadDispatcher/Processor.class.php
Normal file
31
source/lib/DownloadDispatcher/Processor.class.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DownloadDispatcher_Processor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point for the Download Dispatcher
|
||||||
|
*
|
||||||
|
* Iterates over all enabled plugins and moves supported files to the proper destinations
|
||||||
|
*/
|
||||||
|
public static function run() {
|
||||||
|
|
||||||
|
$main = DownloadDispatcher_Main::instance();
|
||||||
|
$config = $main->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
16
source/lib/DownloadDispatcher/Source/IPlugin.class.php
Normal file
16
source/lib/DownloadDispatcher/Source/IPlugin.class.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
interface DownloadDispatcher_Source_IPlugin extends DownloadDispatcher_IPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process files recognised by this plugin
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function run();
|
||||||
|
|
||||||
|
public static function create($config, $log);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DownloadDispatcher_Source_Plugin_RouterboardFirmware extends DownloadDispatcher_PluginBase implements DownloadDispatcher_Source_IPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of this plugin
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const PLUGIN_NAME = "RouterboardFirmware";
|
||||||
|
|
||||||
|
protected $config;
|
||||||
|
protected $log;
|
||||||
|
|
||||||
|
public static function create($config, $log) {
|
||||||
|
return new self($config, $log);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function __construct($config, $log) {
|
||||||
|
$this->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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
68
source/lib/DownloadDispatcher/Source/Plugin/TV.class.php
Normal file
68
source/lib/DownloadDispatcher/Source/Plugin/TV.class.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DownloadDispatcher_Source_Plugin_TV extends DownloadDispatcher_PluginBase implements DownloadDispatcher_Source_IPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of this plugin
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const PLUGIN_NAME = "TV";
|
||||||
|
|
||||||
|
protected $config;
|
||||||
|
protected $log;
|
||||||
|
|
||||||
|
public static function create($config, $log) {
|
||||||
|
return new self($config, $log);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function __construct($config, $log) {
|
||||||
|
$this->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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
30
source/lib/DownloadDispatcher/Source/PluginFactory.class.php
Normal file
30
source/lib/DownloadDispatcher/Source/PluginFactory.class.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DownloadDispatcher_Source_PluginFactory extends DownloadDispatcher_PluginFactory {
|
||||||
|
|
||||||
|
protected static $plugin_prefix = 'DownloadDispatcher_Source_Plugin_';
|
||||||
|
protected static $plugin_interface = 'DownloadDispatcher_Source_IPlugin';
|
||||||
|
protected static $plugin_dir = array(
|
||||||
|
DownloadDispatcher_Lib => '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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user