Added new scripts to import nzbs. Updated some of the used scripts.

This commit is contained in:
Darko
2014-10-15 15:37:23 +02:00
parent cf415c705d
commit d3bdbcf14b
9 changed files with 748 additions and 53 deletions
+24 -3
View File
@@ -8,7 +8,7 @@ require_once(WWW_DIR . "/lib/showsleep.php");
require_once(dirname(__FILE__) . "/../lib/functions.php");
$version = "0.5r0006";
$version = "0.5r0010";
$pdo = new DB();
$s = new Sites();
@@ -33,6 +33,7 @@ $seq = (isset($tmux->sequential)) ? $tmux->sequential : 0;
$powerline = (isset($tmux->powerline)) ? $tmux->powerline : 0;
$tpatch = $tmux->sqlpatch;
$run_ircscraper = $tmux->scrape;
$tmuxImport = $tmux->import;
@@ -1394,11 +1395,21 @@ while ($i > 0) {
//run update_binaries, backfill and import using seq in pane 0.2
$dead = `tmux list-panes -t${tmux_session}:0 | grep 2: | grep dead`;
if (($seq == 1) && (strlen($dead) > "4")) {
switch ($tmuxImport) {
case 1:
$useFilenames = 'false';
break;
case 2:
$useFilenames = 'true';
break;
default:
$useFilenames = 'false';
}
//run nzb-import
if (($import != 0) && ($kill_pp == "false")) {
$log = writelog($panes0[2]);
shell_exec("tmux respawnp -t${tmux_session}:0.2 ' \
$_python ${DIR}/../python/import_threaded.py $log; date +\"%D %T\"; $_sleep $import_timer' 2>&1 1> /dev/null"
cd $_multi && $_php import.php $site->nzbs $site->nzbthreads true $useFilename false $log; date +\"%D %T\"; $_sleep $import_timer' 2>&1 1> /dev/null"
);
} else {
$color = get_color($colors_start, $colors_end, $colors_exc);
@@ -1501,9 +1512,19 @@ while ($i > 0) {
//runs nzb-import in 0.4
if (($import != 0) && ($kill_pp == "false")) {
switch ($tmuxImport) {
case 1:
$useFilenames = 'false';
break;
case 2:
$useFilenames = 'true';
break;
default:
$useFilenames = 'false';
}
$log = writelog($panes0[4]);
shell_exec("tmux respawnp -t${tmux_session}:0.4 ' \
$_python ${DIR}/../python/import_threaded.py $log; date +\"%D %T\"; $_sleep $import_timer' 2>&1 1> /dev/null"
cd $_multi && $_php import.php $site->nzbs $site->nzbthreads true $useFilenames false $log; date +\"%D %T\"; $_sleep $import_timer' 2>&1 1> /dev/null"
);
} else if (($import == 1) && ($maxload <= get_load())) {
$color = get_color($colors_start, $colors_end, $colors_exc);
+54 -1
View File
@@ -833,7 +833,11 @@ class ReleaseRemover
)
);
$join = (NN_RELEASE_SEARCH_TYPE == \ReleaseSearch::SPHINX ? "INNER JOIN releases_se rse ON rse.id = r.ID" : "INNER JOIN releasesearch rs ON rs.releaseID = r.ID");
if ($opTypeName == 'Subject') {
$join = (NN_RELEASE_SEARCH_TYPE == \ReleaseSearch::SPHINX ? 'INNER JOIN releases_se rse ON rse.id = r.ID' : 'INNER JOIN releasesearch rs ON rs.releaseid = r.ID');
} else {
$join = '';
}
$this->query = sprintf("
SELECT r.guid, r.searchname, r.ID
@@ -1047,6 +1051,55 @@ class ReleaseRemover
$args[1] = $this->cleanSpaces($args[1]);
$args[2] = $this->cleanSpaces($args[2]);
switch ($args[0]) {
case 'categoryid':
switch ($args[1]) {
case 'equals':
return ' AND categoryID = ' . $args[2];
default:
break;
}
break;
case 'imdbid':
switch ($args[1]) {
case 'equals':
if ($args[2] === 'NULL') {
return ' AND imdbID IS NULL ';
}
else {
return ' AND imdbID = ' . $args[2];
}
default:
break;
}
break;
case 'nzbstatus':
switch ($args[1]) {
case 'equals':
return ' AND nzbstatus = ' . $args[2];
default:
break;
}
break;
case 'rageid':
switch ($args[1]) {
case 'equals':
return ' AND rageID = ' . $args[2];
default:
break;
}
break;
case 'totalpart':
switch ($args[1]) {
case 'equals':
return ' AND totalpart = ' . $args[2];
case 'bigger':
return ' AND totalpart > ' . $args[2];
case 'smaller':
return ' AND totalpart < ' . $args[2];
default:
break;
}
break;
case 'fromname':
switch ($args[1]) {
case 'equals':
@@ -82,7 +82,7 @@ switch ($options[1]) {
$columns = [];
switch ($options[2]) {
case 'binaries':
if ($return['last_record'] <= $groupMySQL['last_record']){
if ($return['last'] <= $groupMySQL['last_record']){
exit();
}
$columns[1] = sprintf(
@@ -91,23 +91,23 @@ switch ($options[1]) {
(is_numeric($return['last_record_postdate']) ? $return['last_record_postdate'] : strtotime($return['last_record_postdate']))
)
);
$columns[2] = sprintf('last_record = %s', $return['last_record']);
$columns[2] = sprintf('last_record = %s', $return['last']);
$query = sprintf(
'UPDATE groups SET %s, %s, last_updated = NOW() WHERE ID = %d AND last_record < %s',
$columns[1],
$columns[2],
$groupMySQL['ID'],
$return['last_record']
$return['last']
);
break;
case 'backfill':
if ($return['first_record'] >= $groupMySQL['first_record']){
if ($return['first'] >= $groupMySQL['first_record']){
exit();
}
$columns[1] = sprintf(
'first_record_postdate = %s',
$pdo->from_unixtime(
(is_numeric($return['first_record_postadate']) ? $return['first_record_postdate'] : strtotime($return['first_record_postdate']))
(is_numeric($return['first_record_postdate']) ? $return['first_record_postdate'] : strtotime($return['first_record_postdate']))
)
);
$columns[2] = sprintf('first_record = %s', $return['first_record']);
+462
View File
@@ -0,0 +1,462 @@
<?php
require_once(WWW_DIR . "/lib/framework/db.php");
require_once(WWW_DIR . "/lib/binaries.php");
require_once(WWW_DIR . "/lib/releases.php");
require_once(WWW_DIR . "/lib/nzb.php");
require_once(WWW_DIR . "/lib/site.php");
require_once(WWW_DIR . "/lib/util.php");
require_once(WWW_DIR . "/lib/Categorize.php");
require_once(NN_TMUX . 'lib' . DS . 'ReleaseCleaner.php');
require_once(NN_TMUX . 'lib' . DS . 'Enzebe.php');
/**
* Import NZB files into the database.
* Class NZBImport
*/
class NZBImport
{
/**
* @var \DB
* @access protected
*/
protected $pdo;
/**
* @var Binaries
* @access protected
*/
protected $binaries;
/**
* @var ReleaseCleaning
* @access protected
*/
protected $releaseCleaner;
/**
* @var bool|stdClass
* @access protected
*/
protected $site;
/**
* @var int
* @access protected
*/
protected $crossPostt;
/**
* @var Categorize
* @access protected
*/
protected $category;
/**
* List of all the group names/ids in the DB.
* @var array
* @access protected
*/
protected $allGroups;
/**
* Was this run from the browser?
* @var bool
* @access protected
*/
protected $browser;
/**
* Return value for browser.
* @var string
* @access protected
*/
protected $retVal;
/**
* Guid of the current releases.
* @var string
* @access protected
*/
protected $relGuid;
/**
* @var bool
*/
public $echoCLI;
/**
* @var NZB
*/
public $nzb;
/**
* Construct.
*
* @param array $options Class instances / various options.
*
* @access public
*/
public function __construct(array $options = [])
{
$defaults = [
'Browser' => false, // Was this started from the browser?
'Echo' => true, // Echo to CLI?
'Binaries' => null,
'Categorize' => null,
'NZB' => null,
'ReleaseCleaning' => null,
'Releases' => null,
'Settings' => null,
];
$options += $defaults;
$this->echoCLI = (!$this->browser && NN_ECHOCLI && $options['Echo']);
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
$this->binaries = ($options['Binaries'] instanceof \Binaries ? $options['Binaries'] : new \Binaries(['Settings' => $this->pdo, 'Echo' => $this->echoCLI]));
$this->category = ($options['Categorize'] instanceof \Categorize ? $options['Categorize'] : new \Categorize(['Settings' => $this->pdo]));
$this->nzb = ($options['NZB'] instanceof \NZB ? $options['NZB'] : new \NZB($this->pdo));
$this->releaseCleaner = ($options['ReleaseCleaning'] instanceof \ReleaseCleaning ? $options['ReleaseCleaning'] : new \ReleaseCleaning($this->pdo));
$this->releases = ($options['Releases'] instanceof \Releases ? $options['Releases'] : new \Releases(['settings' => $this->pdo]));
$s = new Sites();
$this->site = $s->get();
$this->crossPostt = ($this->site->crossposttime != '') ? $this->site->crossposttime : 2;
$this->browser = $options['Browser'];
$this->retVal = '';
}
/**
* @param array $filesToProcess List of NZB files to import.
* @param bool|string $useNzbName Use the NZB file name as release name?
* @param bool $delete Delete the NZB when done?
* @param bool $deleteFailed Delete the NZB if failed importing?
*
* @return string|bool
*
* @access public
*/
public function beginImport($filesToProcess, $useNzbName = false, $delete = true, $deleteFailed = true)
{
// Get all the groups in the DB.
if (!$this->getAllGroups()) {
if ($this->browser) {
return $this->retVal;
} else {
return false;
}
}
$start = date('Y-m-d H:i:s');
$nzbsImported = $nzbsSkipped = 0;
// Loop over the file names.
foreach ($filesToProcess as $nzbFile) {
// Check if the file is really there.
if (is_file($nzbFile)) {
// Get the contents of the NZB file as a string.
if (strtolower(substr($nzbFile, -7)) === '.nzb.gz') {
$nzbString = Utility::unzipGzipFile($nzbFile);
} else {
$nzbString = file_get_contents($nzbFile);
}
if ($nzbString === false) {
$this->echoOut('ERROR: Unable to read: ' . $nzbFile);
if ($deleteFailed) {
@unlink($nzbFile);
}
$nzbsSkipped++;
continue;
}
// Load it as a XML object.
$nzbXML = @simplexml_load_string($nzbString);
if ($nzbXML === false || strtolower($nzbXML->getName()) != 'nzb') {
$this->echoOut('ERROR: Unable to load NZB XML data: ' . $nzbFile);
if ($deleteFailed) {
@unlink($nzbFile);
}
$nzbsSkipped++;
continue;
}
// Try to insert the NZB details into the DB.
$inserted = $this->scanNZBFile($nzbXML, ($useNzbName ? str_ireplace('.nzb', '', basename($nzbFile)) : false));
if ($inserted) {
// Try to copy the NZB to the NZB folder.
$path = $this->nzb->getNZBPath($this->relGuid, 0, true);
// Try to compress the NZB file in the NZB folder.
$fp = gzopen ($path, 'w5');
gzwrite ($fp, $nzbString);
gzclose($fp);
if (!is_file($path)) {
$this->echoOut('ERROR: Problem compressing NZB file to: ' . $path);
// Remove the release.
$this->pdo->queryExec(
sprintf("DELETE FROM releases WHERE guid = %s", $this->pdo->escapeString($this->relGuid))
);
if ($deleteFailed) {
@unlink($nzbFile);
}
$nzbsSkipped++;
continue;
} else {
if ($delete) {
// Remove the nzb file.
@unlink($nzbFile);
}
$nzbsImported++;
continue;
}
} else {
if ($deleteFailed) {
@unlink($nzbFile);
}
$nzbsSkipped++;
continue;
}
} else {
$this->echoOut('ERROR: Unable to fetch: ' . $nzbFile);
$nzbsSkipped++;
continue;
}
}
$this->echoOut(
'Proccessed ' .
$nzbsImported .
' NZBs in ' .
(strtotime(date('Y-m-d H:i:s')) - strtotime($start)) .
' seconds, ' .
$nzbsSkipped .
' NZBs were skipped.'
);
if ($this->browser) {
return $this->retVal;
} else {
return true;
}
}
/**
* @param object $nzbXML Reference of simpleXmlObject with NZB contents.
* @param bool|string $useNzbName Use the NZB file name as release name?
* @return bool
*
* @access protected
*/
protected function scanNZBFile(&$nzbXML, $useNzbName = false)
{
$totalFiles = $totalSize = $groupID = 0;
$isBlackListed = $groupName = $firstName = $posterName = $postDate = false;
// Go through the NZB, get the details, look if it's blacklisted, look if we have the groups.
foreach ($nzbXML->file as $file) {
$totalFiles++;
$groupID = -1;
// Get the nzb info.
if ($firstName === false ) {
$firstName =(string) $file->attributes()->subject;
}
if ($posterName === false) {
$posterName = (string) $file->attributes()->poster;
}
if ($postDate === false) {
$postDate = date("Y-m-d H:i:s", (string) $file->attributes()->date);
}
// Make a fake message array to use to check the blacklist.
$msg = array("Subject" => (string) $file->attributes()->subject, "From" => (string) $file->attributes()->poster, "Message-ID" => "");
// Get the group names, groupID, check if it's blacklisted.
$groupArr = array();
foreach ($file->groups->group as $group) {
$group = (string) $group;
// If groupID is -1 try to get a groupID.
if ($groupID === -1) {
if (array_key_exists($group, $this->allGroups)) {
$groupID = $this->allGroups[$group];
if (!$groupName) {
$groupName = $group;
}
}
}
// Add all the found groups to an array.
$groupArr[] = $group;
// Check if this NZB is blacklisted.
if ($this->binaries->isBlacklisted($msg, $group)) {
$isBlackListed = true;
break;
}
}
// If we found a group and it's not blacklisted.
if ($groupID !== -1 && !$isBlackListed) {
// Get the size of the release.
if (count($file->segments->segment) > 0) {
foreach ($file->segments->segment as $segment) {
$totalSize += (int)$segment->attributes()->bytes;
}
}
} else {
if ($isBlackListed) {
$errorMessage = "Subject is blacklisted: " . utf8_encode(trim($firstName));
} else {
$errorMessage = "No group found for " . $firstName . " (one of " . implode(', ', $groupArr) . " are missing";
}
$this->echoOut($errorMessage);
return false;
}
}
// Try to insert the NZB details into the DB.
return $this->insertNZB(
array(
'subject' => $firstName,
'useFName' => $useNzbName,
'postDate' => (empty($postDate) ? date("Y-m-d H:i:s") : $postDate),
'from' => (empty($posterName) ? '' : $posterName),
'groupID' => $groupID,
'groupName' => $groupName,
'totalFiles' => $totalFiles,
'totalSize' => $totalSize
)
);
}
/**
* Insert the NZB details into the database.
*
* @param $nzbDetails
*
* @return bool
*
* @access protected
*/
protected function insertNZB($nzbDetails)
{
// Make up a GUID for the release.
$this->relGuid = $this->releases->createGUID();
// Remove part count from subject.
$partLess = preg_replace('/(\(\d+\/\d+\))*$/', 'yEnc', $nzbDetails['subject']);
// Remove added yEnc from above and anything after.
$subject = utf8_encode(trim(preg_replace('/yEnc.*$/i', 'yEnc', $partLess)));
$renamed = 0;
if ($nzbDetails['useFName']) {
// If the user wants to use the file name.. use it.
$cleanName = $nzbDetails['useFName'];
$renamed = 1;
} else {
// Pass the subject through release cleaner to get a nicer name.
$cleanName = $this->releaseCleaner->releaseCleaner($subject, $nzbDetails['from'], $nzbDetails['totalSize'], $nzbDetails['groupName']);
if (isset($cleanName['properlynamed'])) {
$cleanName = $cleanName['cleansubject'];
$renamed = (isset($cleanName['properlynamed']) && $cleanName['properlynamed'] === true ? 1 : 0);
}
}
$escapedSubject = $this->pdo->escapeString($subject);
$escapedFromName = $this->pdo->escapeString($nzbDetails['from']);
// Look for a duplicate on name, poster and size.
$dupeCheck = $this->pdo->queryOneRow(
sprintf(
'SELECT ID FROM releases WHERE name = %s AND fromname = %s AND size BETWEEN %s AND %s',
$escapedSubject,
$escapedFromName,
$this->pdo->escapeString($nzbDetails['totalSize'] * 0.99),
$this->pdo->escapeString($nzbDetails['totalSize'] * 1.01)
)
);
if ($dupeCheck === false) {
$escapedSearchName = $this->pdo->escapeString($cleanName);
// Insert the release into the DB.
$relID = $this->releases->insertRelease(
[
'name' => $escapedSubject,
'searchname' => $escapedSearchName,
'totalpart' => $nzbDetails['totalFiles'],
'groupID' => $nzbDetails['groupID'],
'guid' => $this->pdo->escapeString($this->relGuid),
'postdate' => $this->pdo->escapeString($nzbDetails['postDate']),
'fromname' => $escapedFromName,
'size' => $this->pdo->escapeString($nzbDetails['totalSize']),
'categoryID' => $this->category->determineCategory($cleanName, $nzbDetails['groupID']),
'isrenamed' => $renamed,
'reqidstatus' => 0,
'prehashID' => 0,
'nzbstatus' => \Enzebe::NZB_ADDED
]
);
} else {
//$this->echoOut('This release is already in our DB so skipping: ' . $subject);
return false;
}
if (isset($relID) && $relID === false) {
$this->echoOut('ERROR: Problem inserting: ' . $subject);
return false;
}
return true;
}
/**
* Get all groups in the DB.
* @return bool
*
* @access protected
*/
protected function getAllGroups()
{
$this->allGroups = [];
$groups = $this->pdo->query("SELECT ID, name FROM groups");
foreach ($groups as $group) {
$this->allGroups[$group["name"]] = $group["ID"];
}
if (count($this->allGroups) === 0) {
$this->echoOut('You have no groups in your database!');
return false;
}
return true;
}
/**
* Echo message to browser or CLI.
* @param $message
*
* @access protected
*/
protected function echoOut($message)
{
if ($this->browser) {
$this->retVal .= $message . "<br />";
} elseif ($this->echoCLI) {
echo $message . PHP_EOL;
}
}
}
+9
View File
@@ -3020,4 +3020,13 @@ class Releases
sprintf('UPDATE releases SET categoryID = %d, iscategorized = 0 %s', \Category::CAT_MISC_OTHER, $where)
);
}
/**
* Create a GUID for a release.
* @return string
*/
public function createGUID()
{
return sha1(uniqid('', true) . mt_rand());
}
}
@@ -1,53 +1,73 @@
<h1>{$page->title}</h1>
<p>
Import nzbs via the command line or browser into the system.
Import NZB's from a folder or via the browser into the system. Specify the full file path to a folder containing NZB's.
<br />
Importing will add the release to your database, compress the NZB and store it in the nzbfiles/ folder.
</p>
<ul>
<li>If you are importing a large number of nzb files, run the script /misc/update_scripts/import.php from the command line and pass in the folder path as the first argument.</li>
<li>Groups contained in the nzbs should be added to the site before the import is run, they do not have to be active.</li>
<li>Your www user will need write permission to the /nzbfiles folder in order to import the nzb.</li>
<li>If you are importing a large number of NZB files, run the nzb-import.php script in misc/testing/ from the command line and pass in the folder path as the first argument.</li>
<li>If you are running the script in misc/testing/ from the command line you can pass "true" (no quotes) as the second argument to use the NZB filename as the release name.</li>
<li>Groups contained in the NZB's should be added to the site before the import is run.</li>
<li>If you re-import the same NZB it will not be added a second time.</li>
<li>If imported sucessfully the NZB will be deleted.</li>
</ul>
<fieldset>
<legend>Import From Browser</legend>
<form action="{$SCRIPT_NAME}" method="POST" enctype="multipart/form-data">
<table class="input">
<tr>
<td width="100"><label for="uploadedfiles[]">File</label>:</td>
<td>
<input name="uploadedfiles[]" type="file" class="multi accept-nzb"/>
<div class="hint">Select one or more .nzb files.</div>
</td>
</tr>
<tr style="display:none;">
<td><label for="usefilename">Use Filename</label>:</td>
<td>
<input type="checkbox" name="usefilename" />
<div class="hint">Use the nzb's filename as the release name. This will bypass the release regex process.</div>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Import" />
</td>
</tr>
</table>
<legend>Import From Directory</legend>
<form action="{$SCRIPT_NAME}#results" method="POST">
<table class="input">
<tr>
<td style="width:100px;"><label for="folder">Folder:</label></td>
<td>
<input id="folder" class="long" name="folder" type="text" value="" />
<div class="hint">Windows file paths should be specified with forward slashes e.g. c:/temp/</div>
</td>
</tr>
<tr>
<td><label for="usefilename">Use Filename:</label></td>
<td>
<input type="checkbox" name="usefilename" />
<div class="hint">Use the NZB's filename as the release name. Else the name inside the NZB will be used.</div>
</td>
</tr>
<tr>
<td><label for="deleteNZB">Delete NZBs:</label></td>
<td>
<input type="checkbox" name="deleteNZB" />
<div class="hint">Delete the NZB when we have successfully imported it?</div>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Import" />
</td>
</tr>
</table>
</form>
</fieldset>
<fieldset>
<legend>Import From Browser</legend>
<form action="{$SCRIPT_NAME}#results" method="POST" enctype="multipart/form-data">
<table class="input">
<tr>
<td style="width:100px;"><label for="uploadedfiles[]">File:</label></td>
<td>
<input name="uploadedfiles[]" type="file" class="multi accept-nzb"/>
<div class="hint">Select one or more .nzb files.</div>
</td>
</tr>
<tr>
<td></td>
<td>
<b>These NZBs will not be deleted once imported.</b><br />
<input type="submit" value="Import" />
</td>
</tr>
</table>
</fieldset>
{if $output != ""}
<div>
<a id="results"></a>
<h1>Import Results</h1>
{$output}
</div>
@@ -481,7 +481,6 @@
<td>
{html_radios id="fix_crap_opt" name='fix_crap_opt' onchange="enableFixCrapCustom()" values=$fix_crap_radio_ids output=$fix_crap_radio_names selected=$ftmux->fix_crap_opt separator='<br />'}
<br>
<div class="checkbox-grid">
{if $ftmux->fix_crap_opt == "Custom"}
{html_checkboxes id="fix_crap" name='fix_crap' values=$fix_crap_check_ids output=$fix_crap_check_names selected=explode(', ', $ftmux->fix_crap)}
@@ -492,12 +491,10 @@
<div class="hint">Choose to run Remove Crap Releases. You can all or some.</div>
</td>
</tr>
<tr>
<td style="width:180px;"><label for="crap_timer">Remove Crap Releases Sleep Timer:</label></td>
<td>
<input id="crap_timer" name="crap_timer" class="short" type="text" value="{$ftmux->crap_timer}"/>
<div class="hint">The time to sleep from the time the loop ends until it is restarted, in seconds.</div>
</td>
</tr>
+53
View File
@@ -0,0 +1,53 @@
<?php
// New line for CLI.
$n = PHP_EOL;
// Include config.php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
require_once(WWW_DIR . "/lib/ColorCLI.php");
require_once(NN_TMUX. 'lib' . DS . 'ReleaseRemover.php');
// ColorCLI class.
$cli = new \ColorCLI();
// Print arguments/usage.
$totalArgs = count($argv);
if ($totalArgs < 2) {
exit($cli->info($n .
'This deletes releases based on a list of criteria you pass.' . $n .
'Usage:' . $n . $n.
'List of supported criteria:' . $n .
'fromname : Look for names of people who posted releases (the poster name). (modifiers: equals, like)' . $n .
'groupname : Look in groups. (modifiers: equals, like)' . $n .
'guid : Look for a specific guid. (modifiers: equals)' . $n .
'name : Look for a name (the usenet name). (modifiers: equals, like)' . $n .
'searchname : Look for a name (the search name). (modifiers: equals, like)' . $n .
'size : Release must be (bigger than |smaller than |exactly) this size.(bytes) (modifiers: equals,bigger,smaller)' . $n .
'adddate : Look for releases added to our DB (older than|newer than) x hours. (modifiers: bigger,smaller)' . $n .
'postdate : Look for posted to usenet (older than|newer than) x hours. (modifiers: bigger,smaller)' . $n .
'completion : Look for completion (less than) (modifiers: smaller)' . $n .
'categoryid : Look for releases within specified category (modifiers: equals)' . $n .
'imdbid : Look for releases with imdbid (modifiers: equals)' . $n .
'rageid : Look for releases with rageid (modifiers: equals)' . $n .
'totalpart : Look for releases with certain number of parts (modifiers: equals,bigger,smaller)' . $n .
'nzbstatus : Look for releases with nzbstatus (modifiers: equals)' . $n . $n .
'List of Modifiers:' . $n .
'equals : Match must be exactly this. (fromname=equals="john" will only look for "john", not "johndoe")' . $n .
'like : Match can be similar to this. Separate words using spaces(ie:"cars hdtv x264").' . $n .
' (fromname=like="john" will look for any posters with john in it (ie:john@smith.com)' . $n .
'bigger : Match must be bigger than this. (postdate=bigger="3" means older than 3 hours ago)' . $n .
'smaller : Match must be smaller than this (postdate=smaller="3" means between now and 3 hours ago.' . $n . $n .
'Extra:' . $n .
'ignore : Ignore the user check. (before running we ask you if you want to run the query to delete)' . $n . $n .
'Examples:' . $n .
$_SERVER['_'] . ' ' . $argv[0] . ' groupname=equals="alt.binaries.teevee" searchname=like="olympics 2014" postdate=bigger="5"' . $n .
$_SERVER['_'] . ' ' . $argv[0] . ' guid=equals="8fb5956bae3de4fb94edcc69da44d6883d586fd0"' . $n .
$_SERVER['_'] . ' ' . $argv[0] . ' size=smaller="104857600" size=bigger="2048" groupname=like="movies"' . $n .
$_SERVER['_'] . ' ' . $argv[0] . ' fromname=like="@XviD.net" groupname=equals="alt.binaries.movies.divx" ignore' .$n .
$_SERVER['_'] . ' ' . $argv[0] . ' imdbid=equals=NULL categoryid=equals=2020 nzbstatus=equals=1 adddate=bigger=2880 # Remove other movie releases with non-cleaned names added > 120 days ago'
));
}
$RR = new \ReleaseRemover();
// Remove argv[0] and send the array.
$RR->removeByCriteria(array_slice($argv, 1, $totalArgs-1));
+80
View File
@@ -0,0 +1,80 @@
<?php
require_once(dirname(__FILE__) . "/../../bin/config.php");
require_once(WWW_DIR . "/lib/NZBImport.php");
$n = PHP_EOL;
// Print usage.
if (count($argv) !== 6) {
exit(
'This will import NZB files(.nzb or .nzb.gz), into your nZEDb site from a folder recursively(it will go down into sub-folders).'. $n .
'Please use arg5, something sensible like 100k, if you have millions of NZB files the initial scan will be VERY slow otherwise.' . $n . $n .
'Usage: ' . $n .
$_SERVER['_'] . ' ' . __FILE__ . ' arg1 arg2 arg3 arg4 arg5' . $n . $n .
'arg1 : Path to folder where NZB files are stored. | a folder path' . $n .
'arg2 : Delete NZB when successfully imported.(recommended) | true/false' . $n .
'arg3 : Delete NZB when unsuccessfully imported.(not recommended) | true/false' . $n .
'arg4 : Use NZB file name as release name.(not recommended) | true/false' . $n .
'arg5 : Import this many NZB files. (RECOMMENDED 100,000) | a number' . $n . $n .
'ie: ' . $_SERVER['_'] . ' ' . __FILE__ . ' ' . NN_ROOT . 'nzbToImport' . DS . ' true false false 1000' . $n
);
}
// Verify arguments.
if (!is_dir($argv[1])) {
exit('Error: arg1 must be a path (you might not have read access to this path)' . $n);
}
if (!in_array($argv[2], array('true', 'false'))) {
exit('Error: arg2 must be true or false' . $n);
}
if (!in_array($argv[3], array('true', 'false'))) {
exit('Error: arg3 must be true or false' . $n);
}
if (!in_array($argv[4], array('true', 'false'))) {
exit('Error: arg4 must be true or false' . $n);
}
if (!is_numeric($argv[5])) {
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 = array();
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;
}