Example #1
0
    exit('Error: arg5 must be a number' . $n);
}
if ($argv[5] < 0) {
    exit('Error: arg5 must be 0 or higher' . $n);
}
$path = $argv[1];
// Check if path ends with dir separator.
if (substr($path, -1) !== DS) {
    $path .= DS;
}
$files = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($argv[1])), '/^.+\\.nzb(\\.gz)?$/i', \RecursiveRegexIterator::GET_MATCH);
$i = 1;
$nzbFiles = [];
foreach ($files as $file) {
    $nzbFiles[] = $file[0];
    if ($i++ >= $argv[5]) {
        break;
    }
}
if ($i > 1) {
    unset($files);
    // Check these user argument values, convert them to bool.
    $deleteNZB = $argv[2] == 'true' ? true : false;
    $deleteFailedNZB = $argv[3] == 'true' ? true : false;
    $useNzbName = $argv[4] == 'true' ? true : false;
    // Create a new instance of NZBImport and send it the file locations.
    $NZBImport = new NZBImport();
    $NZBImport->beginImport($nzbFiles, $useNzbName, $deleteNZB, $deleteFailedNZB);
} else {
    echo 'Nothing found to import!' . $n;
}
Example #2
0
    // Get the list of NZB files from php /tmp folder if nzb files were uploaded.
    if (isset($_FILES["uploadedfiles"])) {
        foreach ($_FILES["uploadedfiles"]["error"] as $key => $error) {
            if ($error == UPLOAD_ERR_OK) {
                $tmp_name = $_FILES["uploadedfiles"]["tmp_name"][$key];
                $name = $_FILES["uploadedfiles"]["name"][$key];
                $filesToProcess[] = $tmp_name;
            }
        }
    } else {
        // Check if the user wants to use the file name as the release name.
        $useNzbName = isset($_POST['usefilename']) && $_POST["usefilename"] == 'on' ? true : false;
        // Check if the user wants to delete the NZB file when done importing.
        $deleteNZB = isset($_POST['deleteNZB']) && $_POST["deleteNZB"] == 'on' ? true : false;
        // Get the path the user set in the browser if he put one.
        $path = isset($_POST["folder"]) ? $_POST["folder"] : "";
        if (substr($path, strlen($path) - 1) !== DS) {
            $path .= DS;
        }
        // Get the files from the user specified path.
        $filesToProcess = glob($path . "*.nzb");
    }
    if (count($filesToProcess) > 0) {
        // Create a new instance of NZBImport and send it the file locations.
        $NZBImport = new NZBImport(['Browser' => true, 'Settings' => $page->settings]);
        $page->smarty->assign('output', $NZBImport->beginImport($filesToProcess, $useNzbName, $deleteNZB));
    }
}
$page->title = "Import Nzbs";
$page->content = $page->smarty->fetch('nzb-import.tpl');
$page->render();