Move files around.

This commit is contained in:
Darko
2015-05-28 12:36:00 +02:00
parent a5ea73deec
commit ae0434ac11
1403 changed files with 13 additions and 18 deletions
@@ -0,0 +1,160 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
/* This script will update the groups table to get the new article numbers for each group you have activated.
It will also truncate the parts, binaries, collections, and partrepair tables.
*/
// TODO: Make this threaded so it goes faster.
$pdo = new DB();
if (!isset($argv[1]) || $argv[1] != 'true') {
printf($pdo->log->setColor('Yellow') . "This script is used when you have switched UseNet Providers(USP) so you can pickup where you left off, rather than resetting all the groups.\nOnly use this script after you have updated your config.php file with your new USP info!!\nMake sure you " . $pdo->log->setColor('Red', 'Bold') . "DO NOT" . $pdo->log->setcolor('Yellow') . " have any update or postprocess scripts running when running this script!\n\n" . $pdo->log->setColor('Cyan') . "Usage: php change_USP_provider true\n");
exit();
}
$groups = $pdo->query("SELECT id, name, first_record_postdate, last_record_postdate FROM groups WHERE active = 1");
$numofgroups = count($groups);
$guesstime = $numofgroups * 2;
$totalstart = microtime(true);
echo "You have $numofgroups active, it takes about 2 minutes on average to processes each group.\n";
foreach ($groups as $group) {
$starttime = microtime(true);
$nntp = new \NNTP(['Settings' => $pdo]);
if ($nntp->doConnect() !== true) {
return;
}
//printf("Updating group ".$group['name']."..\n");
$bfdays = daysOldstr($group['first_record_postdate']);
$currdays = daysOldstr($group['last_record_postdate']);
$bfartnum = daytopost($nntp, $group['name'], $bfdays, true, true);
echo "Our Current backfill postdate was: " . $pdo->log->setColor('Yellow') . date('r', strtotime($group['first_record_postdate'])) . $pdo->log->rsetcolor() . "\n";
$currartnum = daytopost($nntp, $group['name'], $currdays, true, false);
echo "Our Current current postdate was: " . $pdo->log->setColor('Yellow') . date('r', strtotime($group['last_record_postdate'])) . $pdo->log->rsetcolor() . "\n";
$pdo->queryExec(sprintf("UPDATE groups SET first_record = %s, last_record = %s WHERE id = %d", $pdo->escapeString($bfartnum), $pdo->escapeString($currartnum), $group['id']));
$endtime = microtime(true);
echo $pdo->log->setColor('Gray', 'Dim') . "This group took " . gmdate("H:i:s", $endtime - $starttime) . " to process.\n";
$numofgroups--;
echo "There are " . $numofgroups . " left to process.\n\n" . $pdo->log->rsetcolor() . "";
}
$totalend = microtime(true);
echo $pdo->log->header('Total time to update all groups ' . gmdate("H:i:s", $totalend - $totalstart));
// Truncate tables to complete the change to the new USP.
$arr = array("parts", "partrepair", "binaries");
foreach ($arr as &$value) {
$rel = $pdo->queryExec("TRUNCATE TABLE $value");
if ($rel !== false) {
echo $pdo->log->header("Truncating $value completed.");
}
}
unset($value);
function daysOldstr($timestamp)
{
return round((time() - strtotime($timestamp)) / 86400, 5);
}
function daysOld($timestamp)
{
return round((time() - $timestamp) / 86400, 5);
}
// This function taken from lib/backfill.php, and modified to fit our needs.
function daytopost($nntp, $group, $days, $debug = true, $bfcheck = true)
{
global $pdo;
$st = false;
if ($debug && $bfcheck) {
echo $pdo->log->primary('Finding start and end articles for ' . $group . '.');
}
if (!isset($nntp)) {
$nntp = new \NNTP(['Settings' => $pdo]);
if ($nntp->doConnect(false) !== true) {
return;
}
$st = true;
}
$binaries = new \Binaries(['NNTP' => $nntp, 'Settings' => $pdo]);
$data = $nntp->selectGroup($group);
if ($nntp->isError($data)) {
$data = $nntp->dataError($nntp, $group, false);
if ($data === false) {
return;
}
}
// Goal timestamp.
$goaldate = date('U') - (86400 * $days);
$totalnumberofarticles = $data['last'] - $data['first'];
$upperbound = $data['last'];
$lowerbound = $data['first'];
if ($debug && $bfcheck) {
echo $pdo->log->header('Total Articles: ' . number_format($totalnumberofarticles) . ' Newest: ' . number_format($upperbound) . ' Oldest: ' . number_format($lowerbound));
}
if ($data['last'] == PHP_INT_MAX) {
exit($pdo->log->error("Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug."));
}
$firstDate = $binaries->postdate($data['first'], $data);
$lastDate = $binaries->postdate($data['last'], $data);
if ($goaldate < $firstDate && $bfcheck) {
if ($st === true) {
$nntp->doQuit();
}
echo $pdo->log->warning("The oldest post indexed from $days day(s) ago is older than the first article stored on your news server.\nSetting to First available article of (date('r', $firstDate) or daysOld($firstDate) days).");
return $data['first'];
} else if ($goaldate > $lastDate && $bfcheck) {
if ($st === true) {
$nntp->doQuit();
}
echo $pdo->log->error("ERROR: The oldest post indexed from $days day(s) ago is newer than the last article stored on your news server.\nTo backfill this group you need to set Backfill Days to at least ceil(daysOld($lastDate)+1) days (date('r', $lastDate-86400).");
return '';
}
if ($debug && $bfcheck) {
echo $pdo->log->primary("Searching for postdates.\nGroup's Firstdate: " . $firstDate . ' (' . ((is_int($firstDate)) ? date('r', $firstDate) : 'n/a') . ").\nGroup's Lastdate: " . $lastDate . ' (' . date('r', $lastDate) . ").");
}
$interval = floor(($upperbound - $lowerbound) * 0.5);
$templowered = '';
$dateofnextone = $lastDate;
// Match on days not timestamp to speed things up.
while (daysOld($dateofnextone) < $days) {
while (($tmpDate = $binaries->postdate(($upperbound - $interval), $data)) > $goaldate) {
$upperbound = $upperbound - $interval;
}
if (!$templowered) {
$interval = ceil(($interval / 2));
}
$dateofnextone = $binaries->postdate(($upperbound - 1), $data);
while (!$dateofnextone) {
$dateofnextone = $binaries->postdate(($upperbound - 1), $data);
}
}
if ($st === true) {
$nntp->doQuit();
}
if ($bfcheck) {
echo $pdo->log->header("\nBackfill article determined to be " . $upperbound . " " . $pdo->log->setColor('Yellow') . "(" . date('r', $dateofnextone) . ")" . $pdo->log->rsetcolor());
} // which is '.daysOld($dateofnextone)." days old.\n";
else {
echo $pdo->log->header('Current article determined to be ' . $upperbound . " " . $pdo->log->setColor('Yellow') . "(" . date('r', $dateofnextone) . ")" . $pdo->log->rsetcolor());
} // which is '.daysOld($dateofnextone)." days old.\n";
return $upperbound;
}
@@ -0,0 +1,190 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$cli = new \ColorCLI();
$pdo = new DB(['checkVersion' => true]);
$ftinnodb = $pdo->isDbVersionAtLeast('5.6');
if (isset($argv[1]) && isset($argv[2]) && $argv[2] == "fmyisam") {
$tbl = $argv[1];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=MYISAM ROW_FORMAT=FIXED");
} else if (isset($argv[1]) && isset($argv[2]) && $argv[2] == "dmyisam") {
$tbl = $argv[1];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=MYISAM ROW_FORMAT=DYNAMIC");
} else if (isset($argv[1]) && isset($argv[2]) && $argv[2] == "cinnodb") {
$tbl = $argv[1];
if ($ftinnodb || (!$ftinnodb && $tbl !== 'releasesearch' && $tbl !== 'predbhash')) {
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=COMPRESSED");
} else {
printf($cli->header("Not converting releasesearch / predbhash as your INNODB version does not support fulltext indexes"));
}
} else if (isset($argv[1]) && isset($argv[2]) && $argv[2] == "dinnodb") {
$tbl = $argv[1];
if ($ftinnodb || (!$ftinnodb && $tbl !== 'releasesearch' && $tbl !== 'predbhash')) {
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=DYNAMIC");
} else {
printf($cli->header("Not converting releasesearch / predbhash as your INNODB version does not support fulltext indexes"));
}
} else if (isset($argv[1]) && $argv[1] == "fmyisam") {
$sql = 'SHOW TABLE STATUS WHERE (Engine != "MyIsam" OR Row_format != "FIXED") AND Engine != "SPHINX"';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=MYISAM ROW_FORMAT=FIXED");
}
} else if (isset($argv[1]) && $argv[1] == "dmyisam") {
$sql = 'SHOW TABLE STATUS WHERE (Engine != "MyIsam" OR Row_format != "Dynamic") AND Engine != "SPHINX"';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=MYISAM ROW_FORMAT=DYNAMIC");
}
} else if (isset($argv[1]) && $argv[1] == "dinnodb") {
$sql = 'SHOW TABLE STATUS WHERE (Engine != "InnoDB" OR Row_format != "Dynamic") AND Engine != "SPHINX"';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
if ($tbl !== 'releasesearch' && $tbl !== 'predbhash') {
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=DYNAMIC");
}
}
if ($ftinnodb) {
$sql = 'SHOW TABLE STATUS WHERE Name IN ("releasesearch", "predbhash") AND (Engine != "InnoDB" || Row_format != "Dynamic")';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=DYNAMIC");
}
} else {
printf($cli->header("Not converting releasesearch as your INNODB version does not support fulltext indexes"));
}
} else if (isset($argv[1]) && $argv[1] == "cinnodb") {
$sql = 'SHOW TABLE STATUS WHERE (Engine != "InnoDB" OR Row_format != "Compressed") AND Engine != "SPHINX"';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
if ($tbl !== 'releasenfo' && $tbl !== 'releasesearch') {
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=COMPRESSED");
}
}
$sql = 'SHOW TABLE STATUS WHERE Name = "releasenfo" AND (Engine != "InnoDB" || Row_format != "Dynamic")';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=DYNAMIC");
}
if ($ftinnodb) {
$sql = 'SHOW TABLE STATUS WHERE Name IN ("releasesearch", "predbhash") AND (Engine != "InnoDB" || Row_format != "Compressed")';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=COMPRESSED");
}
} else {
printf($cli->header("Not converting releasesearch / predbhash as your INNODB version does not support fulltext indexes"));
}
} else if (isset($argv[1]) && $argv[1] == "cinnodb-noparts") {
$sql = 'SHOW TABLE STATUS WHERE (Engine != "InnoDB" OR Row_format != "Compressed") AND Engine != "SPHINX"';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
if ($tbl !== 'releasenfo' && $tbl !== 'releasesearch' && !preg_match('/parts/', $tbl)) {
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=COMPRESSED");
}
}
$sql = 'SHOW TABLE STATUS WHERE Name = "releasenfo" AND (Engine != "InnoDB" || Row_format != "Dynamic")';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=DYNAMIC");
}
$sql = 'SHOW TABLE STATUS WHERE Name LIKE "parts%" AND (Engine != "MyISAM" || Row_format != "Dynamic")';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=MyISAM ROW_FORMAT=DYNAMIC");
}
if ($ftinnodb) {
$sql = 'SHOW TABLE STATUS WHERE Name IN ("releasesearch", "predbhash") AND (Engine != "InnoDB" || Row_format != "Compressed")';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=INNODB ROW_FORMAT=COMPRESSED");
}
} else {
printf($cli->header("Not converting releasesearch / predbhash as your INNODB version does not support fulltext indexes"));
}
} else if (isset($argv[1]) && $argv[1] == "binaries") {
$arr = array("parts", "binaries");
foreach ($arr as $row) {
$tbl = $row;
printf($cli->header("Converting $tbl"));
$pdo->queryExec("ALTER TABLE $tbl ENGINE=MYISAM ROW_FORMAT=FIXED");
}
} else if (isset($argv[1]) && $argv[1] == "mariadb-tokudb") {
$tables = $pdo->query('SHOW TABLE STATUS WHERE (Engine != "TokuDB" OR Create_options != "`COMPRESSION`=tokudb_lzma") AND Engine != "SPHINX"');
foreach ($tables as $row) {
$tbl = $row['name'];
if ($tbl !== 'releasesearch') {
printf($cli->header("Converting $tbl"));
$sql = "ALTER TABLE $tbl ENGINE=TokuDB Compression=tokudb_lzma";
$pdo->queryExec($sql);
$pdo->queryExec("OPTIMIZE TABLE $tbl");
}
}
} else if (isset($argv[1]) && $argv[1] == "tokudb") {
$tables = $pdo->query('SHOW TABLE STATUS WHERE (Engine != "TokuDB" OR ROW_FORMAT="tokudb_lzma" OR Create_options != "`COMPRESSION`=tokudb_lzma") AND Engine != "SPHINX"');
foreach ($tables as $row) {
$tbl = $row['name'];
if ($tbl !== 'releasesearch') {
printf($cli->header("Converting $tbl"));
$sql = "ALTER TABLE $tbl ENGINE=TokuDB row_format=tokudb_lzma";
$pdo->queryExec($sql);
$pdo->queryExec("OPTIMIZE TABLE $tbl");
}
}
} else {
exit($cli->error(
"\nThis script will convert your tables to a new engine/format. Only tables not meeting the new engine/format will be converted.\n"
. "A comparison of these, excluding TokuDB, https://github.com/nZEDb/nZEDb/wiki/MySQL-Storage-Engine-Comparison\n\n"
. "php convert_mysql_tables.php dmyisam ...: Converts all the tables to Myisam Dynamic. This is the default and is recommended where ram is limited.\n"
. "php convert_mysql_tables.php fmyisam ...: Converts all the tables to Myisam Fixed. This can be faster, but to fully convert all tables requires changing varchar columns to char.\n"
. " This will use much more space than dynamic.\n"
. "php convert_mysql_tables.php dinnodb ...: Converts all the tables to InnoDB Dynamic. This is recommended when the total data and indexes can fit into the innodb_buffer_pool.\n"
. " NB if your innodb version < 5.6 releasesearch / predbhash will not be converted as fulltext indexes are not supported.\n"
. "php convert_mysql_tables.php cinnodb ...: Converts all the tables to InnoDB Compressed. All tables except releasenfo will be converted to Compressed row format.\n"
. " This is recommended when the total data and indexes can not fit into the innodb_buffer_pool using DYNAMIC row format.\n"
. " NB if your innodb version < 5.6 releasesearch / predbhash will not be converted as fulltext indexes are not supported.\n"
. "php convert_mysql_tables.php cinnodb-noparts ...: Converts all the tables to InnoDB Compressed. All tables except parts and releasenfo will be converted to Compressed row format.\n"
. " Alls parts* will be converted to MyISAM Dynamic. This is recommended when using Table Per Group.\n"
. " NB if your innodb version < 5.6 releasesearch / predbhash will not be converted as fulltext indexes are not supported.\n"
. "php convert_mysql_tables.php binaries ...: Converts binaries, parts to MyIsam.\n"
. "php convert_mysql_tables.php mariadb-tokudb ...: Converts all the tables to MariaDB Tokutek DB. Use this is you installed mariadb-tokudb-engine. \n"
. " The TokuDB engine needs to be activated first.\n"
. " https://mariadb.com/kb/en/how-to-enable-tokudb-in-mariadb/\n"
. " NB releasesearch will not be converted as tokudb does not support fulltext indexes.\n"
. "php convert_mysql_tables.php tokudb ...: Converts all the tables to Tokutek DB. Use this if you downloaded and installed the TokuDB binaries.\n"
. " http://www.tokutek.com/resources/support/gadownloads/\n"
. " NB releasesearch will not be converted as tokudb does not support fulltext indexes.\n"
. "php convert_mysql_tables.php table [ fmyisam, dmyisam, dinnodb, cinnodb ] ...: Converts 1 table to Engine, row_format specified.\n"
. " NB if converting to innodb and your innodb version < 5.6 releasesearch / predbhash will not be converted as fulltext indexes are not supported.\n"
));
}
@@ -0,0 +1,166 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
/* This script will allow you to move from single binaries/parts tables to TPG without having to run reset_truncate.
Please STOP all update scripts before running this script.
Use the following options to run:
php convert_to_tpg.php true Convert c/b/p to tpg leaving current binaries/parts tables in-tact.
php convert_to_tgp.php true delete Convert c/b/p to tpg and TRUNCATE current binaries/parts tables.
*/
$debug = false;
$pdo = new DB();
$groups = new \Groups(['Settings' => $pdo]);
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$s = new Sites();
$site = $s->get();
$DoPartRepair = ($site->partrepair == '0') ? false : true;
if ((!isset($argv[1])) || $argv[1] != 'true') {
exit($pdo->log->error("\nMandatory argument missing\n\n"
. "This script will allow you to move from single binaries/parts tables to TPG without having to run reset_truncate.\n"
. "Please STOP all update scripts before running this script.\n\n"
. "Use the following options to run:\n"
. "php $argv[0] true ...: Convert b/p to tpg leaving current binaries/parts tables in-tact.\n"
. "php $argv[0] true delete ...: Convert b/p to tpg and TRUNCATE current binaries/parts tables.\n"
));
}
$blen = $pdo->queryOneRow('SELECT COUNT(*) AS total FROM binaries;');
$bdone = 0;
$bcount = 1;
$gdone = 1;
$actgroups = $groups->getActive();
$glen = count($actgroups);
$newtables = $glen * 3;
$begintime = time();
echo "Creating new binaries, and parts tables for each active group...\n";
foreach ($actgroups as $group) {
if ($groups->createNewTPGTables($group['id']) === false) {
exit($pdo->log->error("There is a problem creating new parts/files tables for group ${group['name']}."));
}
$consoletools->overWrite("Tables Created: " . $consoletools->percentString($gdone * 3, $newtables));
$gdone++;
}
$endtime = time();
echo "\nTable creation took " . $consoletools->convertTime($endtime - $begintime) . ".\n";
$starttime = time();
echo "\nNew tables created, moving data from old tables to new tables.\nThis will take awhile....\n\n";
while ($bdone < $blen['total']) {
// Only load 1000 binaries per loop to not overload memory.
$binaries = $pdo->queryAssoc('SELECT * FROM binaries LIMIT ' . $bdone . ',1000;');
if ($binaries instanceof \Traversable) {
foreach ($binaries as $binary) {
$binary['name'] = $pdo->escapeString($binary['name']);
$binary['fromname'] = $pdo->escapeString($binary['fromname']);
$binary['date'] = $pdo->escapeString($binary['date']);
$binary['binaryhash'] = $pdo->escapeString($binary['binarynhash']);
$binary['dateadded'] = $pdo->escapeString($binary['dateadded']);
$binary['xref'] = $pdo->escapeString($binary['xref']);
$binary['releaseid'] = $pdo->escapeString($binary['releaseid']);
$binary['categoryid'] = $pdo->escapeString($binary['categoryid']);
$binary['totalparts'] = $pdo->escapeString($binary['totalparts']);
$binary['relpart'] = $pdo->escapeString($binary['relpart']);
$binary['reltotalpart'] = $pdo->escapeString($binary['reltotalpart']);
$oldbid = array_shift($binary);
if ($debug) {
echo "\n\nBinaries insert:\n";
print_r($binary);
echo sprintf("\nINSERT INTO binaries_%d (name, fromname, date, xref, groupid, dateadded, releaseid, categoryid, totalparts, binaryhash, relpart, reltotalpart) VALUES (%s)\n\n", $binary['groupid'], implode(', ', $binary));
}
$newbid = array('binaryid' => $pdo->queryInsert(sprintf('INSERT INTO binaries_%d (NAME, fromname, date, xref, groupid, dateadded, releaseid, categoryid, totalparts, binaryhash, relpart, reltotalpart) VALUES (%s);', $binary['groupid'], implode(', ', $binarynew))));
//Get parts and split to correct group tables.
$parts = $pdo->queryAssoc('SELECT * FROM parts WHERE binaryid = ' . $oldbid . ';');
if ($parts instanceof \Traversable) {
$firstpart = true;
$partsnew = '';
foreach ($parts as $part) {
$oldpid = array_shift($part);
$partnew = array_replace($part, $newbid);
$partsnew .= '(\'' . implode('\', \'', $partnew) . '\'), ';
}
$partsnew = substr($partsnew, 0, -2);
if ($debug) {
echo "\n\nParts insert:\n";
echo sprintf("\nINSERT INTO parts_%d (binaryid, messageid, number, partnumber, size) VALUES %s;\n\n", $binary['groupid'], $partsnew);
}
$sql = sprintf('INSERT INTO parts_%d (binaryid, messageid, number, partnumber, size) VALUES %s;', $binary['groupid'], $partsnew);
$pdo->queryExec($sql);
}
}
$bcount++;
}
$bdone += 1000;
}
if ($DoPartRepair === true) {
foreach ($actgroups as $group) {
$pcount = 1;
$pdone = 0;
$sql = sprintf('SELECT COUNT(*) AS total FROM partrepair WHERE groupid = %d;', $group['id']);
$plen = $pdo->queryOneRow($sql);
while ($pdone < $plen['total']) {
// Only load 10000 partrepair records per loop to not overload memory.
$partrepairs = $pdo->queryAssoc(sprintf('SELECT * FROM partrepair WHERE groupid = %d LIMIT %d, 10000;', $group['id'], $pdone));
if ($partrepairs instanceof \Traversable) {
foreach ($partrepairs as $partrepair) {
$partrepair['numberid'] = $pdo->escapeString($partrepair['numberid']);
$partrepair['groupid'] = $pdo->escapeString($partrepair['groupid']);
$partrepair['attempts'] = $pdo->escapeString($partrepair['attempts']);
if ($debug) {
echo "\n\nPart Repair insert:\n";
print_r($partrepair);
echo sprintf("\nINSERT INTO partrepair_%d (numberid, groupid, attempts) VALUES (%s, %s, %s)\n\n", $group['id'], $partrepair['numberid'], $partrepair['groupid'], $partrepair['attempts']);
}
$pdo->queryExec(sprintf('INSERT INTO partrepair_%d (numberid, groupid, attempts) VALUES (%s, %s, %s);', $group['id'], $partrepair['numberid'], $partrepair['groupid'], $partrepair['attempts']));
$consoletools->overWrite('Part Repairs Completed for ' . $group['name'] . ':' . $consoletools->percentString($pcount, $plen['total']));
$pcount++;
}
}
$pdone += 10000;
}
}
}
$endtime = time();
echo "\nTable population took " . $consoletools->convertTimer($endtime - $starttime) . ".\n";
//Truncate old tables to save space.
if (isset($argv[2]) && $argv[2] == 'delete') {
echo "Truncating old tables...\n";
$pdo->queryDirect('TRUNCATE TABLE binaries;');
$pdo->queryDirect('TRUNCATE TABLE parts');
$pdo->queryDirect('TRUNCATE TABLE partrepair');
echo "Complete.\n";
}
// Update TPG setting in site-edit.
$pdo->queryExec('UPDATE site SET value = 1 WHERE setting = \'tablepergroup\';');
$pdo->queryExec('UPDATE tmux SET value = 2 WHERE setting = \'releases\';');
echo "New tables have been created.\nTable Per Group has been set to to \"TRUE\" in site-edit.\nUpdate Releases has been set to Threaded in tmux-edit.\n";
function multi_implode($array, $glue)
{
$ret = '';
foreach ($array as $item) {
if (is_array($item)) {
$ret .= '(' . multi_implode($item, $glue) . '), ';
} else {
$ret .= $item . $glue;
}
}
$ret = substr($ret, 0, 0 - strlen($glue));
return $ret;
}
@@ -0,0 +1,182 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
// This script can dump all tables or just collections/binaries/parts/partrepair/groups.
$pdo = new DB();
$exportopts = "";
//determine mysql platform Percona or Other
$mysqlplatform = exec('mysqladmin version | grep "Percona"');
if (strlen($mysqlplatform) > 0) {
//Percona only has --innodb-optimize-keys
$exportopts = "--opt --innodb-optimize-keys --complete-insert --skip-quick";
} else {
//generic (or unknown) instance of MySQL
$exportopts = "--opt --complete-insert --skip-quick";
}
function newname($filename)
{
rename($filename, dirname($filename)."/".basename($filename,".gz")."_".date("Y_m_d_His", filemtime($filename)).".gz");
}
function builddefaultsfile()
{
//generate file contents
$filetext = "[mysqldump]"
."\n"
."user = " . DB_USER
."\n"
."password = " . DB_PASSWORD
."\n[mysql]"
."\n"
."user = " . DB_USER
."\n"
."password = " . DB_PASSWORD;
$filehandle = fopen("mysql-defaults.txt", "w+");
if(!$filehandle) {
exit("Unable to write mysql defaults file! Exiting");
} else {
fwrite($filehandle, $filetext);
fclose($filehandle);
chmod("mysql-defaults.txt", 0600);
}
}
$dbhost = DB_HOST;
$dbport = DB_PORT;
$dbsocket = DB_SOCKET;
$dbuser = DB_USER;
$dbpass = DB_PASSWORD;
$dbname = DB_NAME;
if (DB_SOCKET != '') {
$use = "-S $dbsocket";
} else {
$use = "-P$dbport";
}
//generate defaults file used to store database login information so it is not in cleartext in ps command for mysqldump
builddefaultsfile();
if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) {
$filename = $argv[3]."/".$dbname.".gz";
echo $pdo->log->header("Dumping $dbname.");
if (file_exists($filename)) {
newname($filename);
}
$command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname | gzip -9 > $filename";
system($command);
} else if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) {
$filename = $argv[3]."/".$dbname.".gz";
if (file_exists($filename)) {
echo $pdo->log->header("Restoring $dbname.");
$command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname";
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
system($command);
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
}
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) {
$sql = "SHOW tables";
$tables = $pdo->query($sql);
foreach($tables as $row) {
$tbl = $row['Tables_in_'.DB_NAME];
$filename = $argv[3]."/".$tbl.".gz";
echo $pdo->log->header("Dumping $tbl.");
if (file_exists($filename)) {
newname($filename);
}
$command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname $tbl | gzip -9 > $filename";
system($command);
}
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) {
$sql = "SHOW tables";
$tables = $pdo->query($sql);
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
foreach($tables as $row) {
$tbl = $row['Tables_in_'.DB_NAME];
$filename = $argv[3]."/".$tbl.".gz";
if (file_exists($filename)) {
echo $pdo->log->header("Restoring $tbl.");
$command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname";
system($command);
}
}
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
} else if((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) {
$arr = array("parts", "binaries", "partrepair", "groups");
foreach ($arr as &$tbl) {
$filename = $argv[3]."/".$tbl.".gz";
echo $pdo->log->header("Dumping $tbl..");
if (file_exists($filename)) {
newname($filename);
}
$command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname $tbl | gzip -9 > $filename";
system($command);
}
} else if((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) {
$arr = array("parts", "binaries", "partrepair", "groups");
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
foreach ($arr as &$tbl) {
$filename = $argv[3]."/".$tbl.".gz";
if (file_exists($filename)) {
echo $pdo->log->header("Restoring $tbl.");
$command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname";
system($command);
}
}
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "outfile") && (isset($argv[3]) && file_exists($argv[3]))) {
$sql = "SHOW tables";
$tables = $pdo->query($sql);
foreach($tables as $row) {
$tbl = $row['Tables_in_'.DB_NAME];
$filename = $argv[3].$tbl.".csv";
echo $pdo->log->header("Dumping $tbl.");
if (file_exists($filename)) {
newname($filename);
}
$pdo->queryDirect(sprintf("SELECT * INTO OUTFILE %s FROM %s", $pdo->escapeString($filename), $tbl));
}
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "infile") && (isset($argv[3]) && is_dir($argv[3]))) {
$sql = "SHOW tables";
$tables = $pdo->query($sql);
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
foreach($tables as $row) {
$tbl = $row['Tables_in_'.DB_NAME];
$filename = $argv[3].$tbl.".csv";
if (file_exists($filename)) {
echo $pdo->log->header("Restoring $tbl.");
$pdo->queryExec(sprintf("LOAD DATA INFILE %s INTO TABLE %s", $pdo->escapeString($filename), $tbl));
}
}
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
} else {
passthru("clear");
echo $pdo->log->error("\nThis script can dump/restore all tables, compressed or OUTFILE/INFILE, or just collections/binaries/parts.\n\n"
. "**Single File\n"
. "php $argv[0] db dump /path/to/save/to ...: To dump the database.\n"
. "php $argv[0] db restore /path/to/restore/from ...: To restore the database.\n\n"
. "**Individual Table Files\n"
. "php $argv[0] all dump /path/to/save/to ...: To dump all tables.\n"
. "php $argv[0] all restore /path/to/restore/from ...: To restore all tables.\n\n"
. "**Three Tables (collections, binaries, parts)\n"
. "php $argv[0] test dump /path/to/save/to ...: To dump binaries and parts tables.\n"
. "php $argv[0] test restore /path/to/restore/from ...: To restore binaries and parts tables.\n\n"
. "**Individal Files - OUTFILE/INFILE - No schema\n"
. "**MySQL MUST have write permissions to this path\n"
. "php $argv[0] all outfile /path/to/save/to ...: To dump all tables, using OUTFILE.\n"
. "php $argv[0] all infile /path/to/restore/from ...: To restore all tables, using INFILE.\n\n");
}
if(file_exists("mysql-defaults.txt")) {
@unlink("mysql-defaults.txt");
}
@@ -0,0 +1,101 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
use newznab\utility\Utility;
$cli = new \ColorCLI();
if (isset($argv[1])) {
$del = false;
if (isset($argv[2])) {
$del = $argv[2];
}
create_guids($argv[1], $del);
} else {
exit($cli->error("\nThis script updates all releases with the guid (md5 hash of the first message-id) from the nzb file.\n\n"
. "php $argv[0] true ...: To create missing nzb_guids.\n"
. "php $argv[0] true delete ...: To create missing nzb_guids and delete invalid nzbs and releases.\n"));
}
function create_guids($live, $delete = false)
{
$pdo = new DB();
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$timestart = TIME();
$relcount = $deleted = $total = 0;
$relrecs = false;
if ($live == "true") {
$relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC"));
} else if ($live == "limited") {
$relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000"));
}
if ($relrecs) {
$total = $relrecs->rowCount();
}
if ($total > 0) {
echo $pdo->log->header("Creating nzb_guids for " . number_format($total) . " releases.");
$releases = new \Releases(['Settings' => $pdo]);
$nzb = new \NZB($pdo);
$releaseImage = new \ReleaseImage($pdo);
$reccnt = 0;
if ($relrecs instanceof \Traversable) {
foreach ($relrecs as $relrec) {
$reccnt++;
$nzbpath = $nzb->getNZBPath($relrec['guid']);
if ($nzbpath !== false) {
$nzbfile = Utility::unzipGzipFile($nzbpath);
if ($nzbfile) {
$nzbfile = @simplexml_load_string($nzbfile);
}
if (!$nzbfile) {
if (isset($delete) && $delete == 'delete') {
//echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n";
$releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
$deleted++;
}
continue;
}
$binary_names = array();
foreach ($nzbfile->file as $file) {
$binary_names[] = $file["subject"];
}
if (count($binary_names) == 0) {
if (isset($delete) && $delete == 'delete') {
//echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n";
$releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
$deleted++;
}
continue;
}
asort($binary_names);
foreach ($nzbfile->file as $file) {
if ($file["subject"] == $binary_names[0]) {
$segment = $file->segments->segment;
$nzb_guid = md5($segment);
$pdo->queryExec("UPDATE releases set nzb_guid = " . $pdo->escapestring($nzb_guid) . " WHERE id = " . $relrec["id"]);
$relcount++;
$consoletools->overWritePrimary("Created: [" . $deleted . "] " . $consoletools->percentString($reccnt, $total) . " Time:" . $consoletools->convertTimer(TIME() - $timestart));
break;
}
}
} else {
if (isset($delete) && $delete == 'delete') {
//echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting.");
$releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
}
}
}
}
if ($relcount > 0) {
echo "\n";
}
echo $pdo->log->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart));
} else {
echo $pdo->log->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart));
exit($pdo->log->info("No releases are missing the guid."));
}
}
@@ -0,0 +1,64 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
passthru('clear');
$pdo = new newznab\db\DB();
if (!isset($argv[1]) || (isset($argv[1]) && $argv[1] !== 'true')) {
exit($pdo->log->error("\nThis script renames all table columns to lowercase, it can be dangerous. Please BACKUP your database before running this script.\n"
. "php rename_to_lower.php true ...: To rename all table columns to lowercase.\n"));
}
echo $pdo->log->warning("This script renames all table colums to lowercase.");
echo $pdo->log->header("Have you backed up your database? Type 'BACKEDUP' to continue: \n");
echo $pdo->log->warningOver("\n");
$line = fgets(STDIN);
if (trim($line) != 'BACKEDUP') {
exit($pdo->log->error("This script is dangerous you must type BACKEDUP for it function."));
}
echo "\n";
echo $pdo->log->header("Thank you, continuing...\n\n");
if ($argc == 1 || $argv[1] != 'true') {
exit($pdo->log->error("\nThis script will rename every table column to lowercase that is not already lowercase.\nTo run:\nphp $argv[0] true\n"));
}
$database = DB_NAME;
$count = 0;
$list = $pdo->query("SELECT TABLE_NAME, COLUMN_NAME, UPPER(COLUMN_TYPE), EXTRA FROM information_schema.columns WHERE table_schema = '" . $database . "'");
if (count($list) == 0) {
echo $pdo->log->info("No table columns to rename");
} else {
foreach ($list as $column) {
if ($column['column_name'] !== strtolower($column['column_name'])) {
echo $pdo->log->header("Renaming Table " . $column['table_name'] . " Column " . $column['column_name']);
if (isset($column['extra'])) {
$extra = strtoupper($column['extra']);
} else {
$extra = '';
}
$pdo->queryDirect("ALTER TABLE " . $column['table_name'] . " CHANGE " . $column['column_name'] . " " . strtolower($column['column_name']) . " " . $column['upper(column_type)'] . " " . $extra);
$count++;
}
if (strtolower($column['column_name']) === 'id' && strtolower($column['extra']) !== 'auto_increment') {
echo $pdo->log->header("Renaming Table " . $column['table_name'] . " Column " . $column['column_name']);
$extra = 'AUTO_INCREMENT';
if ($column['table_name'] != "releases_se") {
$placeholder = $pdo->queryDirect("SELECT MAX(id) FROM " . $column['table_name']);
$pdo->queryDirect("ALTER IGNORE TABLE " . $column['table_name'] . " CHANGE " . $column['column_name'] . " " . strtolower($column['column_name']) . " " . $column['upper(column_type)'] . " " . $extra);
$pdo->queryDirect("ALTER IGNORE TABLE " . $column['table_name'] . " AUTO_INCREMENT = " . $placeholder + 1);
$count++;
}
}
}
}
if ($count == 0) {
echo $pdo->log->info("All table column names are already lowercase");
} else {
echo $pdo->log->header($count . " colums renamed");
}
@@ -0,0 +1,307 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$ran = false;
if (isset($argv[1]) && $argv[1] === "all") {
if (isset($argv[2]) && $argv[2] === "true") {
$ran = true;
$where = '';
if (isset($argv[3]) && $argv[3] === "truncate") {
echo "Truncating tables\n";
$pdo->queryExec("TRUNCATE TABLE consoleinfo");
$pdo->queryExec("TRUNCATE TABLE gamesinfo");
$pdo->queryExec("TRUNCATE TABLE movieinfo");
$pdo->queryExec("TRUNCATE TABLE releasevideo");
$pdo->queryExec("TRUNCATE TABLE musicinfo");
$pdo->queryExec("TRUNCATE TABLE bookinfo");
$pdo->queryExec("TRUNCATE TABLE releasenfo");
$pdo->queryExec("TRUNCATE TABLE releaseextrafull");
$pdo->queryExec("TRUNCATE TABLE xxxinfo");
}
echo $pdo->log->header("Resetting all postprocessing");
$qry = $pdo->queryDirect("SELECT id FROM releases");
$affected = 0;
if ($qry instanceof Traversable) {
$total = $qry->rowCount();
foreach ($qry as $releases) {
$pdo->queryExec(
sprintf("
UPDATE releases
SET consoleinfoid = NULL, gamesinfo_id = 0, imdbid = NULL, musicinfoid = NULL,
bookinfoid = NULL, rageid = -1, xxxinfo_id = 0, passwordstatus = -1, haspreview = -1,
jpgstatus = 0, videostatus = 0, audiostatus = 0, nfostatus = -1
WHERE id = %d",
$releases['id']
)
);
$consoletools->overWritePrimary("Resetting Releases: " . $consoletools->percentString(++$affected, $total));
}
}
}
}
if (isset($argv[1]) && ($argv[1] === "consoles" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE consoleinfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all Console postprocessing");
$where = ' WHERE consoleinfoid IS NOT NULL';
} else {
echo $pdo->log->header("Resetting all failed Console postprocessing");
$where = " WHERE consoleinfoid IN (-2, 0) AND categoryid BETWEEN 1000 AND 1999";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
if ($qry !== false) {
$total = $qry->rowCount();
} else {
$total = 0;
}
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET consoleinfoid = NULL WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting Console Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " consoleinfoid's reset.");
}
if (isset($argv[1]) && ($argv[1] === "games" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE gamesinfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all Games postprocessing");
$where = ' WHERE gamesinfo_id != 0';
} else {
echo $pdo->log->header("Resetting all failed Games postprocessing");
$where = " WHERE gamesinfo_id IN (-2, 0) AND categoryid = 4050";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
if ($qry !== false) {
$total = $qry->rowCount();
} else {
$total = 0;
}
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET gamesinfo_id = 0 WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting Games Releases: " . $consoletools->percentString(++$concount, $total));
}
echo $pdo->log->header("\n" . number_format($concount) . " gameinfo_ID's reset.");
}
}
if (isset($argv[1]) && ($argv[1] === "movies" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE movieinfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all Movie postprocessing");
$where = ' WHERE imdbid IS NOT NULL';
} else {
echo $pdo->log->header("Resetting all failed Movie postprocessing");
$where = " WHERE imdbid IN (-2, 0) AND categoryid BETWEEN 2000 AND 2999";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
if ($qry !== false) {
$total = $qry->rowCount();
} else {
$total = 0;
}
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET imdbid = NULL WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting Movie Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " imdbid's reset.");
}
if (isset($argv[1]) && ($argv[1] === "music" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE musicinfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all Music postprocessing");
$where = ' WHERE musicinfoid IS NOT NULL';
} else {
echo $pdo->log->header("Resetting all failed Music postprocessing");
$where = " WHERE musicinfoid IN (-2, 0) AND categoryid BETWEEN 3000 AND 3999";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
$total = $qry->rowCount();
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET musicinfoid = NULL WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting Music Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " musicinfoid's reset.");
}
if (isset($argv[1]) && ($argv[1] === "misc" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all Additional postprocessing");
$where = ' WHERE (haspreview != -1 AND haspreview != 0) OR (passwordstatus != -1 AND passwordstatus != 0) OR jpgstatus != 0 OR videostatus != 0 OR audiostatus != 0';
} else {
echo $pdo->log->header("Resetting all failed Additional postprocessing");
$where = " WHERE haspreview < -1 OR haspreview = 0 OR passwordstatus < -1 OR passwordstatus = 0 OR jpgstatus < 0 OR videostatus < 0 OR audiostatus < 0";
}
echo $pdo->log->primary("SELECT id FROM releases" . $where);
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
if ($qry !== false) {
$total = $qry->rowCount();
} else {
$total = 0;
}
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET passwordstatus = -1, haspreview = -1, jpgstatus = 0, videostatus = 0, audiostatus = 0 WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " Release's reset.");
}
if (isset($argv[1]) && ($argv[1] === "tv" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE tvrage");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all TV postprocessing");
$where = ' WHERE rageid != -1';
} else {
echo $pdo->log->header("Resetting all failed TV postprocessing");
$where = " WHERE rageid IN (-2, 0) OR rageid IS NULL AND categoryid BETWEEN 5000 AND 5999";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
if ($qry !== false) {
$total = $qry->rowCount();
} else {
$total = 0;
}
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET rageid = -1 WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting TV Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " rageid's reset.");
}
if (isset($argv[1]) && ($argv[1] === "books" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE bookinfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all Book postprocessing");
$where = ' WHERE bookinfoid IS NOT NULL';
} else {
echo $pdo->log->header("Resetting all failed Book postprocessing");
$where = " WHERE bookinfoid IN (-2, 0) AND categoryid BETWEEN 7000 AND 7899";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
$total = $qry->rowCount();
$concount = 0;
if ($qry instanceof Traversable) {
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET bookinfoid = NULL WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting Book Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " bookinfoid's reset.");
}
if (isset($argv[1]) && ($argv[1] === "xxx" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE xxxinfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all XXX postprocessing");
$where = ' WHERE xxxinfo_id != 0';
} else {
echo $pdo->log->header("Resetting all failed XXX postprocessing");
$where = " WHERE xxxinfo_id IN (-2, 0) AND categoryid BETWEEN 6000 AND 6040";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
$concount = 0;
if ($qry instanceof Traversable) {
$total = $qry->rowCount();
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET xxxinfo_id = 0 WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting XXX Releases: " . $consoletools->percentString(++$concount,
$total
)
);
}
}
echo $pdo->log->header("\n" . number_format($concount) . " xxxinfo_ID's reset.");
}
if (isset($argv[1]) && ($argv[1] === "nfos" || $argv[1] === "all")) {
$ran = true;
if (isset($argv[3]) && $argv[3] === "truncate") {
$pdo->queryExec("TRUNCATE TABLE releasenfo");
}
if (isset($argv[2]) && $argv[2] === "true") {
echo $pdo->log->header("Resetting all NFO postprocessing");
$where = ' WHERE nfostatus != -1';
} else {
echo $pdo->log->header("Resetting all failed NFO postprocessing");
$where = " WHERE nfostatus < -1";
}
$qry = $pdo->queryDirect("SELECT id FROM releases" . $where);
$concount = 0;
if ($qry instanceof Traversable) {
$total = $qry->rowCount();
foreach ($qry as $releases) {
$pdo->queryExec("UPDATE releases SET nfostatus = -1 WHERE id = " . $releases['id']);
$consoletools->overWritePrimary("Resetting NFO Releases: " . $consoletools->percentString(++$concount, $total));
}
}
echo $pdo->log->header("\n" . number_format($concount) . " NFO's reset.");
}
if ($ran === false) {
exit(
$pdo->log->error(
"\nThis script will reset postprocessing per category. It can also truncate the associated tables."
. "\nTo reset only those that have previously failed, those without covers, samples, previews, etc. use the "
. "second argument false.\n"
. "To reset even those previously post processed, use the second argument true.\n"
. "To truncate the associated table, use the third argument truncate.\n\n"
. "php reset_postprocessing.php consoles true ...: To reset all consoles.\n"
. "php reset_postprocessing.php games true ...: To reset all games.\n"
. "php reset_postprocessing.php movies true ...: To reset all movies.\n"
. "php reset_postprocessing.php music true ...: To reset all music.\n"
. "php reset_postprocessing.php misc true ...: To reset all misc.\n"
. "php reset_postprocessing.php tv true ...: To reset all tv.\n"
. "php reset_postprocessing.php books true ...: To reset all books.\n"
. "php reset_postprocessing.php xxx true ...: To reset all xxx.\n"
. "php reset_postprocessing.php nfos true ...: To reset all nfos.\n"
. "php reset_postprocessing.php all true ...: To reset everything.\n"
)
);
} else {
echo "\n";
}
@@ -0,0 +1,55 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$s = new Sites();
$site = $s->get();
if (isset($argv[1]) && ($argv[1] == "true" || $argv[1] == "drop")) {
$pdo->queryExec("UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL");
echo $pdo->log->primary("Reseting all groups completed.");
$arr = array("parts", "partrepair", "binaries", "collections");
foreach ($arr as &$value) {
$rel = $pdo->queryExec("TRUNCATE TABLE $value");
if ($rel !== false) {
echo $pdo->log->primary("Truncating ${value} completed.");
}
}
unset($value);
$tpg = $site->tablepergroup;
$tablepergroup = (!empty($tpg)) ? $tpg : 0;
if ($tablepergroup == 1) {
$sql = 'SHOW table status';
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
if (preg_match('/collections_\d+/', $tbl) || preg_match('/binaries_\d+/', $tbl) || preg_match('/parts_\d+/', $tbl) || preg_match('/partrepair_\d+/', $tbl) || preg_match('/\d+_collections/', $tbl) || preg_match('/\d+_binaries/', $tbl) || preg_match('/\d+_parts/', $tbl) || preg_match('/\d+_partrepair_\d+/', $tbl)) {
if ($argv[1] == "drop") {
$rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl));
if ($rel !== false) {
echo $pdo->log->primary("Dropping ${tbl} completed.");
}
} else {
$rel = $pdo->queryDirect(sprintf('TRUNCATE TABLE %s', $tbl));
if ($rel !== false) {
echo $pdo->log->primary("Truncating ${tbl} completed.");
}
}
}
}
}
$delcount = $pdo->queryDirect("DELETE FROM releases WHERE nzbstatus = 0");
echo $pdo->log->primary($delcount->rowCount() . " releases had no nzb, deleted.");
} else {
exit($pdo->log->error("\nThis script removes releases with no NZBs, resets all groups, truncates or drops(tpg) \n"
. "article tables. All other releases are left alone.\n"
. "php $argv[0] [true, drop] ...: To reset all groups and truncate/drop the tables.\n"
));
}
@@ -0,0 +1,100 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
use newznab\utility\Utility;
Utility::clearScreen();
$pdo = new DB();
if (!isset($argv[1]) || (isset($argv[1]) && $argv[1] !== 'true'))
exit($pdo->log->error("\nThis script removes all releases and release related files. To run:\nphp resetdb.php true\n"));
echo $pdo->log->warning("This script removes all releases, nzb files, samples, previews , nfos, truncates all article tables and resets all groups.");
echo $pdo->log->header("Are you sure you want reset the DB? Type 'DESTROY' to continue: \n");
echo $pdo->log->warningOver("\n");
$line = fgets(STDIN);
if (trim($line) != 'DESTROY')
exit($pdo->log->error("This script is dangerous you must type DESTROY for it function."));
echo "\n";
echo $pdo->log->header("Thank you, continuing...\n\n");
$timestart = time();
$relcount = 0;
$ri = new \ReleaseImage($pdo);
$nzb = new \NZB($pdo);
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$pdo->queryExec("UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL");
echo $pdo->log->primary("Reseting all groups completed.");
$arr = [
"tvrage", "releasenfo", "releasecomment", 'sharing', 'sharing_sites',
"usercart", "usermovies", "userseries", "movieinfo", "musicinfo", "releasefiles",
"releaseaudio", "releasesubs", "releasevideo", "releaseextrafull", "parts",
"partrepair", "binaries", "collections", "releases", "spotnabsources"
];
foreach ($arr as &$value) {
$rel = $pdo->queryExec("TRUNCATE TABLE $value");
if ($rel !== false)
echo $pdo->log->primary("Truncating ${value} completed.");
}
unset($value);
$sql = "SHOW table status";
$tables = $pdo->query($sql);
foreach ($tables as $row) {
$tbl = $row['name'];
if (preg_match('/binaries_\d+/', $tbl) || preg_match('/parts_\d+/', $tbl) || preg_match('/collections_\d+/', $tbl) || preg_match('/partrepair_\d+/', $tbl) || preg_match('/\d+_binaries/', $tbl) || preg_match('/\d+_collections/', $tbl) || preg_match('/\d+_parts/', $tbl) || preg_match('/\d+_partrepair_\d+/', $tbl)) {
$rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl));
if ($rel !== false)
echo $pdo->log->primary("Dropping ${tbl} completed.");
}
}
(new \SphinxSearch())->truncateRTIndex('releases_rt');
$pdo->optimise(false, 'full');
$s = new Sites();
$site = $s->get();
echo $pdo->log->header("Deleting nzbfiles subfolders.");
try {
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($site->nzbpath, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
if (basename($file) != '.gitignore' && basename($file) != 'tmpunrar') {
$todo = ($file->isDir() ? 'rmdir' : 'unlink');
@$todo($file);
}
}
} catch (UnexpectedValueException $e) {
echo $pdo->log->error($e->getMessage());
}
echo $pdo->log->header("Deleting all images, previews and samples that still remain.");
try {
$dirItr = new \RecursiveDirectoryIterator(NN_COVERS);
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (basename($filePath) != '.gitignore' && basename($filePath) != 'no-cover.jpg' && basename($filePath) != 'no-backdrop.jpg') {
@unlink($filePath);
}
}
} catch (UnexpectedValueException $e) {
echo $pdo->log->error($e->getMessage());
}
echo $pdo->log->header("Getting Updated List of TV Shows from TVRage.");
$tvshows = @simplexml_load_file('http://services.tvrage.com/feeds/show_list.php');
if ($tvshows !== false) {
foreach ($tvshows->show as $rage) {
if (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name))
$pdo->queryInsert(sprintf('INSERT INTO tvrage (rageid, releasetitle, country) VALUES (%s, %s, %s)', $pdo->escapeString($rage->id), $pdo->escapeString($rage->name), $pdo->escapeString($rage->country)));
}
} else {
echo $pdo->log->error("TVRage site has a hard limit of 400 concurrent api requests. At the moment, they have reached that limit. Please wait before retrying again.");
}
echo $pdo->log->header("Deleted all releases, images, previews and samples. This script ran for " . $consoletools->convertTime(TIME() - $timestart));
@@ -0,0 +1,78 @@
<?php
use newznab\db\DB;
use newznab\utility\Utility;
$pdo = new DB();
$s = new Sites();
$site = $s->get();
if (isset($argv[1]) && ($argv[1] === "true" || $argv[1] === "delete")) {
$releases = new \Releases(['Settings' => $pdo]);
$nzb = new \NZB($pdo);
$releaseImage = new \ReleaseImage($pdo);
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$timestart = time();
$checked = $deleted = 0;
$couldbe = $argv[1] === "true" ? $couldbe = "could be " : "were ";
echo $pdo->log->header('Getting List of nzbs to check against db.');
$dirItr = new \RecursiveDirectoryIterator($site->nzbpath);
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/([a-f-0-9]+)\.nzb\.gz/', $filePath, $guid)) {
$nzbfile = Utility::unzipGzipFile($filePath);
if ($nzbfile) {
$nzbfile = @simplexml_load_string($nzbfile);
}
if ($nzbfile) {
$res = $pdo->queryOneRow(sprintf("SELECT id, guid FROM releases WHERE guid = %s", $pdo->escapeString(stristr($filePath->getFilename(), '.nzb.gz', true))));
if ($res === false) {
if ($argv[1] === "delete") {
@copy($filePath, NN_ROOT . "pooped/" . $guid[1] . ".nzb.gz");
$releases->deleteSingle(['g' => $guid[1], 'i' => false], $nzb, $releaseImage);
$deleted++;
}
} else if (isset($res)) {
$pdo->queryExec(sprintf("UPDATE releases SET nzbstatus = 1 WHERE id = %s", $res['id']));
}
} else {
if ($argv[1] === "delete") {
@copy($filePath, NN_ROOT . "pooped/" . $guid[1] . ".nzb.gz");
unlink($filePath);
$deleted++;
}
}
$time = $consoletools->convertTime(time() - $timestart);
$consoletools->overWritePrimary('Checking NZBs: ' . $deleted . ' nzbs of ' . ++$checked . ' releases checked ' . $couldbe . 'deleted from disk, Running time: ' . $time);
}
}
echo $pdo->log->header("\n" . number_format($checked) . ' nzbs checked, ' . number_format($deleted) . ' nzbs ' . $couldbe . 'deleted.');
$timestart = time();
$checked = $deleted = 0;
echo $pdo->log->header("Getting List of releases to check against nzbs.");
$res = $pdo->queryDirect('SELECT id, guid FROM releases');
if ($res instanceof \Traversable) {
foreach ($res as $row) {
$nzbpath = $nzb->getNZBPath($row["guid"]);
if (!file_exists($nzbpath)) {
if ($argv[1] === "delete") {
@copy($nzbpath, NN_ROOT . "pooped/" . $row["guid"] . ".nzb.gz");
$releases->deleteSingle(['g' => $row['guid'], 'i' => $row['id']], $nzb, $releaseImage);
}
$deleted++;
} else if (file_exists($nzbpath) && isset($row)) {
$pdo->queryExec(sprintf("UPDATE releases SET nzbstatus = 1 WHERE id = %s", $row['id']));
}
$time = $consoletools->convertTime(TIME() - $timestart);
$consoletools->overWritePrimary('Checking Releases: ' . $deleted . " releases have no nzb of " . ++$checked . " and " . $couldbe . "deleted from db, Running time: " . $time);
}
}
echo $pdo->log->header("\n" . number_format($checked) . " releases checked, " . number_format($deleted) . " releases " . $couldbe . "deleted.");
} else {
exit($pdo->log->error("\nThis script can remove all nzbs not found in the db and all releases with no nzbs found. It can also delete invalid nzbs.\n\n"
. "php $argv[0] true ...: For a dry run, to see how many would be deleted.\n"
. "php $argv[0] delete ...: To delete all affected.\n"));
}
@@ -0,0 +1,302 @@
<?php
// TODO: bunch of if/elses need converting to switches
use newznab\db\DB;
/*
*
* This was added because I starting writing this before
* all of the regexes were converted to by group in ReleaseCleaning.php
* and I do not want to convert these regexes to run per group.
* ReleaseCleaning.php is where the regexes should go
* so that all new releases can be effected by them
* instead of having to run this script to rename after the
* release has been created
*
*/
$pdo = new DB();
if (!(isset($argv[1]) && ($argv[1] == "all" || $argv[1] == "full" || $argv[1] == "preid" || is_numeric($argv[1])))) {
exit($pdo->log->error(
"\nThis script will attempt to rename releases using regexes first from ReleaseCleaning.php and then from this file.\n"
. "An optional last argument, show, will display the release name changes.\n\n"
. "php $argv[0] full ...: To process all releases not previously renamed.\n"
. "php $argv[0] 2 ...: To process all releases added in the previous 2 hours not previously renamed.\n"
. "php $argv[0] all ...: To process all releases.\n"
. "php $argv[0] full 155 ...: To process all releases in groupid 155 not previously renamed.\n"
. "php $argv[0] all 155 ...: To process all releases in groupid 155.\n"
. "php $argv[0] all '(155, 140)' ...: To process all releases in group_ids 155 and 140.\n"
. "php $argv[0] preid ...: To process all releases where not matched to predb.\n"
));
}
preName($argv, $argc);
function preName($argv, $argc)
{
global $pdo;
$groups = new \Groups(['Settings' => $pdo]);
$category = new \Categorize(['Settings' => $pdo]);
$internal = $external = $pre = 0;
$show = 2;
if ($argv[$argc - 1] === 'show') {
$show = 1;
} else if ($argv[$argc - 1] === 'bad') {
$show = 3;
}
$counter = 0;
$pdo->log = new \ColorCLI();
$full = $all = $usepre = false;
$what = $where = '';
if ($argv[1] === 'full') {
$full = true;
} else if ($argv[1] === 'all') {
$all = true;
} else if ($argv[1] === 'preid') {
$usepre = true;
} else if (is_numeric($argv[1])) {
$what = ' AND adddate > NOW() - INTERVAL ' . $argv[1] . ' HOUR';
}
if ($usepre === true) {
$where = '';
$why = ' WHERE prehashid = 0 AND nzbstatus = 1';
} else if (isset($argv[1]) && is_numeric($argv[1])) {
$where = '';
$why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
} else if (isset($argv[2]) && is_numeric($argv[2]) && $full === true) {
$where = ' AND groupid = ' . $argv[2];
$why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
} else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $full === true) {
$where = ' AND groupid IN ' . $argv[2];
$why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
} else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $all === true) {
$where = ' AND groupid IN ' . $argv[2];
$why = ' WHERE nzbstatus = 1';
} else if (isset($argv[2]) && is_numeric($argv[2]) && $all === true) {
$where = ' AND groupid = ' . $argv[2];
$why = ' WHERE nzbstatus = 1 and prehashid = 0';
} else if (isset($argv[2]) && is_numeric($argv[2])) {
$where = ' AND groupid = ' . $argv[2];
$why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
} else if ($full === true) {
$why = ' WHERE nzbstatus = 1 AND (isrenamed = 0 OR categoryid between 8000 AND 8999)';
} else if ($all === true) {
$why = ' WHERE nzbstatus = 1';
} else {
$why = ' WHERE 1=1';
}
resetSearchnames();
echo $pdo->log->header(
"SELECT id, name, searchname, fromname, size, groupid, categoryid FROM releases" . $why . $what .
$where . ";\n"
);
$res = $pdo->queryDirect("SELECT id, name, searchname, fromname, size, groupid, categoryid FROM releases" . $why . $what . $where);
$total = $res->rowCount();
if ($total > 0) {
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
foreach ($res as $row) {
$groupname = $groups->getByNameByID($row['groupid']);
$cleanerName = releaseCleaner($row['name'], $row['fromname'], $row['size'], $groupname, $usepre);
$preid = 0;
$predb = $predbfile = $increment = false;
if (!is_array($cleanerName)) {
$cleanName = trim((string)$cleanerName);
$propername = $increment = true;
if ($cleanName != '' && $cleanerName != false) {
$run = $pdo->queryOneRow("SELECT id FROM prehash WHERE title = " . $pdo->escapeString($cleanName));
if (isset($run['id'])) {
$preid = $run['id'];
$predb = true;
}
}
} else {
$cleanName = trim($cleanerName["cleansubject"]);
$propername = $cleanerName["properlynamed"];
if (isset($cleanerName["increment"])) {
$increment = $cleanerName["increment"];
}
if (isset($cleanerName["predb"])) {
$preid = $cleanerName["predb"];
$predb = true;
}
}
if ($cleanName != '') {
if (preg_match('/alt\.binaries\.e\-?book(\.[a-z]+)?/', $groupname)) {
if (preg_match('/^[0-9]{1,6}-[0-9]{1,6}-[0-9]{1,6}$/', $cleanName, $match)) {
$rf = new \ReleaseFiles($pdo);
$files = $rf->get($row['id']);
foreach ($files as $f) {
if (preg_match(
'/^(?P<title>.+?)(\\[\w\[\]\(\). -]+)?\.(pdf|htm(l)?|epub|mobi|azw|tif|doc(x)?|lit|txt|rtf|opf|fb2|prc|djvu|cb[rz])/', $f["name"],
$match
)
) {
$cleanName = $match['title'];
break;
}
}
}
}
//try to match clean name against predb filename
$prefile = $pdo->queryOneRow("SELECT id, title FROM prehash WHERE filename = " . $pdo->escapeString($cleanName));
if (isset($prefile['id'])) {
$preid = $prefile['id'];
$cleanName = $prefile['title'];
$predbfile = true;
$propername = true;
}
if ($cleanName != $row['name'] && $cleanName != $row['searchname']) {
if (strlen(utf8_decode($cleanName)) <= 3) {
} else {
$determinedcat = $category->determineCategory($row["groupid"], $cleanName);
if ($propername == true) {
$pdo->queryExec(
sprintf(
"UPDATE releases SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, "
. "iscategorized = 1, isrenamed = 1, searchname = %s, categoryid = %d, prehashid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id']
)
);
} else {
$pdo->queryExec(
sprintf(
"UPDATE releases SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, "
. "iscategorized = 1, searchname = %s, categoryid = %d, prehashid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id']
)
);
}
if ($increment === true) {
$internal++;
} else if ($predb === true) {
$pre++;
} else if ($predbfile === true) {
$pre++;
} else if ($propername === true) {
$external++;
}
if ($show === 1) {
$oldcatname = $category->getNameByID($row["categoryid"]);
$newcatname = $category->getNameByID($determinedcat);
\NameFixer::echoChangedReleaseName(array(
'new_name' => $cleanName,
'old_name' => $row["searchname"],
'new_category' => $newcatname,
'old_category' => $oldcatname,
'group' => $groupname,
'release_id' => $row["id"],
'method' => 'lib/testing/Dev/renametopre.php'
)
);
}
}
} else if ($show === 3 && preg_match('/^\[?\d*\].+?yEnc/i', $row['name'])) {
echo $pdo->log->primary($row['name']);
}
}
if ($cleanName == $row['name']) {
$pdo->queryExec(sprintf("UPDATE releases SET isrenamed = 1, iscategorized = 1 WHERE id = %d", $row['id']));
}
if ($show === 2 && $usepre === false) {
$consoletools->overWritePrimary("Renamed Releases: [Internal=" . number_format($internal) . "][External=" . number_format($external) . "][Predb=" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total));
} else if ($show === 2 && $usepre === true) {
$consoletools->overWritePrimary("Renamed Releases: [" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total));
}
}
}
echo $pdo->log->header("\n" . number_format($pre) . " renamed using preDB Match\n" . number_format($external) . " renamed using ReleaseCleaning.php\n" . number_format($internal) . " using renametopre.php\nout of " . number_format($total) . " releases.\n");
if (isset($argv[1]) && is_numeric($argv[1]) && !isset($argv[2])) {
echo $pdo->log->header("Categorizing all releases using searchname from the last ${argv[1]} hours. This can take a while, be patient.");
} else if (isset($argv[1]) && $argv[1] !== "all" && isset($argv[2]) && !is_numeric($argv[2]) && !preg_match('/\([\d, ]+\)/', $argv[2])) {
echo $pdo->log->header("Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient.");
} else if (isset($argv[1]) && isset($argv[2]) && (is_numeric($argv[2]) || preg_match('/\([\d, ]+\)/', $argv[2]))) {
echo $pdo->log->header("Categorizing all non-categorized releases in ${argv[2]} using searchname. This can take a while, be patient.");
} else {
echo $pdo->log->header("Categorizing all releases using searchname. This can take a while, be patient.");
}
$timestart = TIME();
if (isset($argv[1]) && is_numeric($argv[1])) {
$relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryid = 8010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true);
} else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $full === true) {
$relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true);
} else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $all === true) {
$relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true);
} else if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "full") {
$relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true);
} else if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "all") {
$relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true);
} else if (isset($argv[1]) && $argv[1] == "full") {
$relcount = catRelease("searchname", "WHERE categoryid = 8010 OR iscategorized = 0", true);
} else if (isset($argv[1]) && $argv[1] == "all") {
$relcount = catRelease("searchname", "", true);
} else if (isset($argv[1]) && $argv[1] == "preid") {
$relcount = catRelease("searchname", "WHERE prehashid = 0 AND nzbstatus = 1", true);
} else {
$relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryid = 8010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true);
}
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$time = $consoletools->convertTime(TIME() - $timestart);
echo $pdo->log->header("Finished categorizing " . number_format($relcount) . " releases in " . $time . " seconds, using the usenet subject.\n");
resetSearchnames();
}
function resetSearchnames()
{
global $pdo;
echo $pdo->log->header("Resetting blank searchnames.");
$bad = $pdo->queryDirect(
"UPDATE releases SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, "
. "prehashid = 0, searchname = name, isrenamed = 0, iscategorized = 0 WHERE searchname = ''"
);
$tot = $bad->rowCount();
if ($tot > 0) {
echo $pdo->log->primary(number_format($tot) . " Releases had no searchname.");
}
echo $pdo->log->header("Resetting searchnames that are 8 characters or less.");
$run = $pdo->queryDirect(
"UPDATE releases SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, "
. "prehashid = 0, searchname = name, isrenamed = 0, iscategorized = 0 WHERE LENGTH(searchname) <= 8 AND LENGTH(name) > 8"
);
$total = $run->rowCount();
if ($total > 0) {
echo $pdo->log->primary(number_format($total) . " Releases had searchnames that were 8 characters or less.");
}
}
// Categorizes releases.
// $type = name or searchname
// Returns the quantity of categorized releases.
function catRelease($type, $where, $echooutput = false)
{
global $pdo;
$cat = new \Categorize(['Settings' => $pdo]);
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
$relcount = 0;
echo $pdo->log->primary("SELECT id, " . $type . ", groupid FROM releases " . $where);
$resrel = $pdo->queryDirect("SELECT id, " . $type . ", groupid FROM releases " . $where);
$total = $resrel->rowCount();
if ($total > 0) {
foreach ($resrel as $rowrel) {
$catId = $cat->determineCategory($rowrel['groupid'], $rowrel[$type]);
$pdo->queryExec(sprintf("UPDATE releases SET iscategorized = 1, categoryid = %d WHERE id = %d", $catId, $rowrel['id']));
$relcount++;
if ($echooutput) {
$consoletools->overWritePrimary("Categorizing: " . $consoletools->percentString($relcount, $total));
}
}
}
if ($echooutput !== false && $relcount > 0) {
echo "\n";
}
return $relcount;
}
function releaseCleaner($subject, $fromName, $size, $groupname, $usepre)
{
$groups = new \Groups();
$releaseCleaning = new \ReleaseCleaning($groups->pdo);
$cleanerName = $releaseCleaning->releaseCleaner($subject, $fromName, $size, $groupname, $usepre);
if (!is_array($cleanerName) && $cleanerName != false) {
return array("cleansubject" => $cleanerName, "properlynamed" => true, "increment" => false);
} else {
return $cleanerName;
}
}
@@ -0,0 +1,191 @@
<?php
if (!isset($argv[1]) || !isset($argv[2])) {
exit (
'Argument 1 is a input string. ie PRE name.' . PHP_EOL .
'Argument 2 is a expected hash or encoding. ie MD5 string. Passing true on Argument 3 ignores this.' . PHP_EOL .
'Argument 3 (optional) False, exit on first match. True, write all matches to text file in current path.' . PHP_EOL .
'ie: php test_hash_algorithms.php Dog.with.a.Blog.S02E16.Love.Loss.and.a.Beanbag.Toss.HDTV.x264-QCF 11506192c6d92e0c9c795b9997d9396226dbdf62' . PHP_EOL .
'ie: php test_hash_algorithms.php Anchorman.2.The.Legend.Continues.2013.UNRATED.WEBRip.x264-FLS false true' . PHP_EOL
);
}
/**
* Test various hashing/encoding/etc on a string.
* Class hash_algorithms
*/
class HashAlgorithms
{
/**
* The input string.
* @var string
*/
protected $_inputString;
/**
* The string we are expecting to get.
* @var array
*/
protected $_expectedString;
/**
* Write results to file?
* @var bool
*/
protected $_writeToFile;
/**
* @param string $inputString
* @param string $expectedString
* @param bool $writeToFile
*
* @access public
*/
public function __construct($inputString, $expectedString, $writeToFile)
{
$this->_inputString = $inputString;
$this->_expectedString = array(
$expectedString,
strtolower($expectedString),
strtoupper($expectedString),
strrev($expectedString)
);
$this->_writeToFile = $writeToFile;
$this->_testStrings();
}
/**
* Test various hash algorithms on strings.
*
* @access protected
* @void
*/
protected function _testStrings()
{
if ($this->_writeToFile) {
file_put_contents('hash_matches.txt', '');
}
$firstArray = $this->_hashesToArray($this->_inputString);
$secondArray = array();
foreach ($firstArray as $key => $value) {
if (!$this->_writeToFile) {
if (in_array($value, $this->_expectedString)) {
exit(
'[' .
$this->_inputString .
']=>[' .
$key .
']=>' .
$value .
']' .
PHP_EOL
);
}
} else {
file_put_contents('hash_matches.txt', $key . "\t\t" . $value . PHP_EOL, FILE_APPEND);
}
$secondArray[$key] = $this->_hashesToArray($value);
}
$thirdArray = array();
foreach ($secondArray as $key => $value) {
foreach ($value as $key2 => $value2) {
if (!$this->_writeToFile) {
if (in_array($value2, $this->_expectedString)) {
exit(
'[' .
$this->_inputString .
']=>[' .
$key .
']=>[' .
$firstArray[$key] .
']=>[' .
$key2 .
']=>[' .
$value2 .
']' .
PHP_EOL
);
}
} else {
file_put_contents('hash_matches.txt', $key . ' => ' . $key2 . "\t\t" . $value2 . PHP_EOL, FILE_APPEND);
}
$thirdArray[$key][$key2] = $this->_hashesToArray($value2);
}
}
foreach ($thirdArray as $key => $value) {
foreach ($value as $key2 => $value2) {
foreach ($value2 as $key3 => $value3) {
if (!$this->_writeToFile) {
if (in_array($value3, $this->_expectedString)) {
exit(
'[' .
$this->_inputString .
']=>[' .
$key .
']=>[' .
$firstArray[$key] .
']=>[' .
$key2 .
']=>[' .
$value2 .
']=>[' .
$key3 .
']=>[' .
$value3 .
']' .
PHP_EOL
);
}
} else {
file_put_contents('hash_matches.txt',
$key . ' => ' . $key2 . ' => ' . $key3 . "\t\t" . $value3 . PHP_EOL, FILE_APPEND
);
}
}
}
}
}
/**
* Return various versions of a input string to hash.
*
* @param string $string
*
* @return array
*/
protected function _hashesToArray($string)
{
$strings = array(
'input' => $string,
'lower' => strtolower($string),
'lower_reverse' => strtolower(strrev($string)),
'upper_reverse' => strtoupper(strrev($string)),
'upper' => strtoupper($string),
'reverse' => strrev($string),
'reverse_upper' => strrev(strtoupper($string)),
'reverse_lower' => strrev(strtolower($string)),
);
$hashTypes = array('md5', 'md4', 'sha1', 'sha256', 'sha512');
$tmpArray = array();
foreach ($hashTypes as $hash) {
foreach ($strings as $key => $value) {
$tmpArray[$hash . '_' . $key] = hash($hash, $value, false);
}
}
foreach ($strings as $key => $value) {
$tmpArray['input_' . $key] = $value;
$tmpArray['base64_' . $key] = base64_encode($value);
$tmpArray['crc32_' . $key] = crc32($value);
}
return $tmpArray;
}
}
new HashAlgorithms($argv[1], $argv[2], ((isset($argv[3]) && strtolower($argv[3]) === 'true') ? true : false));
@@ -0,0 +1,34 @@
<?php
//This script will update all records in the consoleinfo table
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$console = new \Konsole(['Echo' => true, 'Settings' => $pdo]);
$res = $pdo->queryDirect(sprintf("SELECT searchname, id FROM releases WHERE consoleinfoid IS NULL AND categoryid BETWEEN 1000 AND 1999 ORDER BY id DESC" ));
if ($res instanceof \Traversable) {
echo $pdo->log->header("Updating console info for " . number_format($res->rowCount()) . " releases.");
foreach ($res as $arr) {
$starttime = microtime(true);
$gameInfo = $console->parseTitle($arr['searchname']);
if ($gameInfo !== false) {
$game = $console->updateConsoleInfo($gameInfo);
if ($game === false) {
echo $pdo->log->primary($gameInfo['release'] . ' not found');
}
}
// amazon limits are 1 per 1 sec
$diff = floor((microtime(true) - $starttime) * 1000000);
if (1000000 - $diff > 0) {
echo $pdo->log->alternate("Sleeping");
usleep(1000000 - $diff);
}
}
}
@@ -0,0 +1,41 @@
<?php
//This script will update all records in the gamesinfo table
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$game = new \Games(['Echo' => true, 'Settings' => $pdo]);
$res = $pdo->query(
sprintf("SELECT id, title FROM gamesinfo WHERE cover = 0 ORDER BY id DESC LIMIT 100")
);
$total = count($res);
if ($total > 0) {
echo $pdo->log->header("Updating game covers for " . number_format($total) . " releases.");
foreach ($res as $arr) {
$starttime = microtime(true);
$gameInfo = $game->parseTitle($arr['title']);
if ($gameInfo !== false) {
echo $pdo->log->primary('Looking up: ' . $gameInfo['release']);
$gameData = $game->updateGamesInfo($gameInfo);
if ($gameData === false) {
echo $pdo->log->primary($gameInfo['release'] . ' not found');
} else {
if (file_exists(NN_COVERS . 'games' . DS . $gameData . '.jpg')) {
$pdo->queryExec(sprintf('UPDATE gamesinfo SET cover = 1 WHERE id = %d', $arr['id']));
}
}
}
// amazon limits are 1 per 1 sec
$diff = floor((microtime(true) - $starttime) * 1000000);
if (1000000 - $diff > 0) {
echo $pdo->log->alternate("Sleeping");
usleep(1000000 - $diff);
}
}
}
@@ -0,0 +1,28 @@
<?php
//This script will update all records in the movieinfo table
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$c = new \ColorCLI();
$movie = new \Film(['Echo' => true, 'Settings' => $pdo]);
$movies = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE tmdbid IS NULL ORDER BY id ASC");
if ($movies instanceof \Traversable) {
echo $pdo->log->header("Updating movie info for " . number_format($movies->rowCount()) . " movies.");
foreach ($movies as $mov) {
$starttime = microtime(true);
$mov = $movie->updateMovieInfo($mov['imdbid']);
// tmdb limits are 30 per 10 sec, not certain for imdb
$diff = floor((microtime(true) - $starttime) * 1000000);
if (333333 - $diff > 0) {
echo "sleeping\n";
usleep(333333 - $diff);
}
}
echo "\n";
}
@@ -0,0 +1,26 @@
<?php
//This script will update all records in the movieinfo table where there is no cover
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$movie = new \Film(array('Echo' => true, 'Settings' => $pdo));
$movies = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE cover = 0 ORDER BY year ASC, id DESC");
if ($movies instanceof \Traversable) {
echo $pdo->log->primary("Updating " . number_format($movies->rowCount()) . " movie covers.");
foreach ($movies as $mov) {
$starttime = microtime(true);
$mov = $movie->updateMovieInfo($mov['imdbid']);
// tmdb limits are 30 per 10 sec, not certain for imdb
$diff = floor((microtime(true) - $starttime) * 1000000);
if (333333 - $diff > 0) {
echo "\nsleeping\n";
usleep(333333 - $diff);
}
}
echo "\n";
}
@@ -0,0 +1,27 @@
<?php
//This script will update all records in the xxxinfo table where there is no cover
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$movie = new XXX();
$c = new ColorCLI();
$movies = $pdo->queryDirect("SELECT title FROM xxxinfo WHERE cover = 0");
if ($movies instanceof Traversable) {
echo $c->primary("Updating " . number_format($movies->rowCount()) . " XXX movie covers.");
foreach ($movies as $mov) {
$starttime = microtime(true);
$mov = $movie->updateXXXInfo($mov['title']);
// sleep so that it's not ddos' the site
$diff = floor((microtime(true) - $starttime) * 1000000);
if (333333 - $diff > 0) {
echo "\nsleeping\n";
usleep(333333 - $diff);
}
}
echo "\n";
}
@@ -0,0 +1,44 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
if (!isset($argv[1]) || $argv[1] != 'true') {
exit($pdo->log->error("\nThis script will download all tvrage shows and insert into the db.\n\n"
. "php $argv[0] true ...: To run.\n"));
}
$newnames = $updated = 0;
echo "Attempting to fetch data file from TVRage...\n";
$tvshows = @simplexml_load_file('http://services.tvrage.com/feeds/show_list.php');
if ($tvshows !== false) {
echo "Starting to process file entries...\n";
foreach ($tvshows->show as $rage) {
echo "RageID: " . $rage->id . ", name: " . $rage->name . " - ";
$dupecheck = $pdo->queryOneRow(sprintf('SELECT COUNT(id) AS count FROM tvrage WHERE id = %s', $pdo->escapeString($rage->id)));
if (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name) &&
$dupecheck !== false && $dupecheck['count'] == 0) {
$pdo->queryInsert(sprintf('INSERT INTO tvrage (rageid, releasetitle, country) VALUES (%s, %s, %s)', $pdo->escapeString($rage->id), $pdo->escapeString($rage->name), $pdo->escapeString($rage->country)));
$updated++;
echo "added\n";
} elseif (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name) &&
$dupecheck !== false && $dupecheck['count'] > 0) {
echo "Up to date\n";
} else {
echo "FAILED\n";
}
}
} else {
exit($pdo->log->info("TVRage site has a hard limit of 400 concurrent API requests. At the moment, they have reached that limit. Please wait before retrying\n"));
}
if ($updated != 0) {
echo $pdo->log->info("Inserted " . $updated . " new shows into the TvRage table. To fill out the newly populated TvRage table\n"
. "php misc/update_scripts/nix_scripts/tmux/lib/testing/PostProc/updateTvRage.php\n");
} else {
echo "\n";
echo $pdo->log->info("TvRage database is already up to date!\n");
}
@@ -0,0 +1,47 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$covers = $updated = $deleted = 0;
if ($argc == 1 || $argv[1] != 'true') {
exit($pdo->log->error("\nThis script will check all images in covers/book and compare to db->bookinfo.\nTo run:\nphp $argv[0] true\n"));
}
$path2covers = NN_COVERS . 'book' . DS;
$dirItr = new \RecursiveDirectoryIterator($path2covers);
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/\d+\.jpg/', $filePath)) {
preg_match('/(\d+)\.jpg/', basename($filePath), $match);
if (isset($match[1])) {
$run = $pdo->queryDirect("UPDATE bookinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]);
if ($run->rowCount() >= 1) {
$covers++;
} else {
$run = $pdo->queryDirect("SELECT id FROM bookinfo WHERE id = " . $match[1]);
if ($run->rowCount() == 0) {
echo $pdo->log->info($filePath . " not found in db.");
}
}
}
}
}
$qry = $pdo->queryDirect("SELECT id FROM bookinfo WHERE cover = 1");
if ($qry instanceof \Traversable) {
foreach ($qry as $rows) {
if (!is_file($path2covers . $rows['id'] . '.jpg')) {
$pdo->queryDirect("UPDATE bookinfo SET cover = 0 WHERE cover = 1 AND id = " . $rows['id']);
echo $pdo->log->info($path2covers . $rows['id'] . ".jpg does not exist.");
$deleted++;
}
}
}
echo $pdo->log->header($covers . " covers set.");
echo $pdo->log->header($deleted . " books unset.");
@@ -0,0 +1,47 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$covers = $updated = $deleted = 0;
if ($argc == 1 || $argv[1] != 'true') {
exit($pdo->log->error("\nThis script will check all images in covers/console and compare to db->consoleinfo.\nTo run:\nphp $argv[0] true\n"));
}
$path2covers = NN_COVERS . 'console' . DS;
$dirItr = new \RecursiveDirectoryIterator($path2covers);
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/\d+\.jpg/', $filePath)) {
preg_match('/(\d+)\.jpg/', basename($filePath), $match);
if (isset($match[1])) {
$run = $pdo->queryDirect("UPDATE consoleinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]);
if ($run->rowCount() >= 1) {
$covers++;
} else {
$run = $pdo->queryDirect("SELECT id FROM consoleinfo WHERE id = " . $match[1]);
if ($run->rowCount() == 0) {
echo $pdo->log->info($filePath . " not found in db.");
}
}
}
}
}
$qry = $pdo->queryDirect("SELECT id FROM consoleinfo WHERE cover = 1");
if ($qry instanceof \Traversable) {
foreach ($qry as $rows) {
if (!is_file($path2covers . $rows['id'] . '.jpg')) {
$pdo->queryDirect("UPDATE consoleinfo SET cover = 0 WHERE cover = 1 AND id = " . $rows['id']);
echo $pdo->log->info($path2covers . $rows['id'] . ".jpg does not exist.");
$deleted++;
}
}
}
echo $pdo->log->header($covers . " covers set.");
echo $pdo->log->header($deleted . " consoles unset.");
@@ -0,0 +1,45 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$covers = $updated = $deleted = 0;
$c = new ColorCLI();
if ($argc == 1 || $argv[1] != 'true') {
exit($c->error("\nThis script will check all images in covers/games and compare to db->gamesinfo.\nTo run:\nphp $argv[0] true\n"));
}
$path2covers = NN_COVERS . 'games' . DS;
$dirItr = new RecursiveDirectoryIterator($path2covers);
$itr = new RecursiveIteratorIterator($dirItr, RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/\d+\.jpg/', $filePath)) {
preg_match('/(\d+)\.jpg/', basename($filePath), $match);
if (isset($match[1])) {
$run = $pdo->queryDirect("UPDATE gamesinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]);
if ($run !== false) {
if ($run->rowCount() >= 1) {
$covers++;
} else {
$run = $pdo->queryDirect("SELECT id FROM gamesinfo WHERE id = " . $match[1]);
if ($run !== false && $run->rowCount() == 0) {
echo $c->info($filePath . " not found in db.");
}
}
}
}
}
}
$qry = $pdo->queryDirect("SELECT id FROM gamesinfo WHERE cover = 1");
foreach ($qry as $rows) {
if (!is_file($path2covers . $rows['id'] . '.jpg')) {
$pdo->queryDirect("UPDATE gamesinfo SET cover = 0 WHERE cover = 1 AND id = " . $rows['id']);
echo $c->info($path2covers . $rows['id'] . ".jpg does not exist.");
$deleted++;
}
}
echo $c->header($covers . " covers set.");
echo $c->header($deleted . " games unset.");
@@ -0,0 +1,72 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$covers = $updated = $deleted = 0;
if ($argc == 1 || $argv[1] != 'true') {
exit($pdo->log->error("\nThis script will check all images in covers/movies and compare to db->movieinfo.\nTo run:\nphp $argv[0] true\n"));
}
$path2covers = NN_COVERS . 'movies' . DS;
$dirItr = new \RecursiveDirectoryIterator($path2covers);
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/-cover\.jpg/', $filePath)) {
preg_match('/(\d+)-cover\.jpg/', basename($filePath), $match);
if (isset($match[1])) {
$run = $pdo->queryDirect("UPDATE movieinfo SET cover = 1 WHERE cover = 0 AND imdbid = " . $match[1]);
if ($run->rowCount() >= 1) {
$covers++;
} else {
$run = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE imdbid = " . $match[1]);
if ($run->rowCount() == 0) {
echo $pdo->log->info($filePath . " not found in db.");
}
}
}
}
if (is_file($filePath) && preg_match('/-backdrop\.jpg/', $filePath)) {
preg_match('/(\d+)-backdrop\.jpg/', basename($filePath), $match1);
if (isset($match1[1])) {
$run = $pdo->queryDirect("UPDATE movieinfo SET backdrop = 1 WHERE backdrop = 0 AND imdbid = " . $match1[1]);
if ($run->rowCount() >= 1) {
$updated++;
printf("UPDATE movieinfo SET backdrop = 1 WHERE backdrop = 0 AND imdbid = " . $match1[1] . "\n");
} else {
$run = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE imdbid = " . $match1[1]);
if ($run->rowCount() == 0) {
echo $pdo->log->info($filePath . " not found in db.");
}
}
}
}
}
$qry = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE cover = 1");
if ($qry instanceof \Traversable) {
foreach ($qry as $rows) {
if (!is_file($path2covers . $rows['imdbid'] . '-cover.jpg')) {
$pdo->queryDirect("UPDATE movieinfo SET cover = 0 WHERE cover = 1 AND imdbid = " . $rows['imdbid']);
echo $pdo->log->info($path2covers . $rows['imdbid'] . "-cover.jpg does not exist.");
$deleted++;
}
}
}
$qry1 = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE backdrop = 1");
if ($qry1 instanceof \Traversable) {
foreach ($qry1 as $rows) {
if (!is_file($path2covers . $rows['imdbid'] . '-backdrop.jpg')) {
$pdo->queryDirect("UPDATE movieinfo SET backdrop = 0 WHERE backdrop = 1 AND imdbid = " . $rows['imdbid']);
echo $pdo->log->info($path2covers . $rows['imdbid'] . "-backdrop.jpg does not exist.");
$deleted++;
}
}
}
echo $pdo->log->header($covers . " covers set.");
echo $pdo->log->header($updated . " backdrops set.");
echo $pdo->log->header($deleted . " movies unset.");
@@ -0,0 +1,46 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$covers = $updated = $deleted = 0;
if ($argc == 1 || $argv[1] != 'true') {
exit($pdo->log->error("\nThis script will check all images in covers/music and compare to db->musicinfo.\nTo run:\nphp $argv[0] true\n"));
}
$path2covers = NN_COVERS . 'music' . DS;
$dirItr = new \RecursiveDirectoryIterator($path2covers);
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/\d+\.jpg/', $filePath)) {
preg_match('/(\d+)\.jpg/', basename($filePath), $match);
if (isset($match[1])) {
$run = $pdo->queryDirect("UPDATE musicinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]);
if ($run->rowCount() >= 1) {
$covers++;
} else {
$run = $pdo->queryDirect("SELECT id FROM musicinfo WHERE id = " . $match[1]);
if ($run->rowCount() == 0) {
echo $pdo->log->info($filePath . " not found in db.");
}
}
}
}
}
$qry = $pdo->queryDirect("SELECT id FROM musicinfo WHERE cover = 1");
if ($qry instanceof \Traversable) {
foreach ($qry as $rows) {
if (!is_file($path2covers . $rows['id'] . '.jpg')) {
$pdo->queryDirect("UPDATE musicinfo SET cover = 0 WHERE cover = 1 AND id = " . $rows['id']);
echo $pdo->log->info($path2covers . $rows['id'] . ".jpg does not exist.");
$deleted++;
}
}
}
echo $pdo->log->header($covers . " covers set.");
echo $pdo->log->header($deleted . " music unset.");
@@ -0,0 +1,65 @@
<?php
//This script downloads covert art for Tv Shows -- it is intended to be run at interval, generally after the TvRage database is populated
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
use newznab\utility\Utility;
$pdo = new DB();
$tvrage = new \TvAnger(['Settings' => $pdo, 'Echo' => true]);
$shows = $pdo->queryDirect("SELECT rageid FROM tvrage WHERE imgdata IS NULL ORDER BY rageid DESC LIMIT 2000");
if ($shows->rowCount() > 0) {
echo "\n";
echo $pdo->log->header("Updating " . number_format($shows->rowCount()) . " tv shows.\n");
} else {
echo "\n";
echo $pdo->log->info("All shows in TvRage database have been updated.\n");
usleep(5000000);
}
$loop = 0;
if ($shows instanceof \Traversable) {
foreach ($shows as $show) {
$starttime = microtime(true);
$rageid = $show['rageid'];
$tvrShow = $tvrage->getRageInfoFromService($rageid);
$genre = '';
if (isset($tvrShow['genres']) && is_array($tvrShow['genres']) && !empty($tvrShow['genres'])) {
if (is_array($tvrShow['genres']['genre'])) {
$genre = @implode('|', $tvrShow['genres']['genre']);
} else {
$genre = $tvrShow['genres']['genre'];
}
}
$country = '';
if (isset($tvrShow['country']) && !empty($tvrShow['country'])) {
$country = $tvrage->countryCode($tvrShow['country']);
}
$rInfo = $tvrage->getRageInfoFromPage($rageid);
$desc = '';
if (isset($rInfo['desc']) && !empty($rInfo['desc'])) {
$desc = $rInfo['desc'];
}
$imgbytes = '';
if (isset($rInfo['imgurl']) && !empty($rInfo['imgurl'])) {
$img =Utility::getUrl(['url' => $rInfo['imgurl']]);
if ($img !== false) {
$im = @imagecreatefromstring($img);
if ($im !== false) {
$imgbytes = $img;
}
}
}
$pdo->queryDirect(sprintf("UPDATE tvrage SET description = %s, genre = %s, country = %s, imgdata = %s WHERE rageid = %d", $pdo->escapeString(substr($desc, 0, 10000)), $pdo->escapeString(substr($genre, 0, 64)), $pdo->escapeString($country), $pdo->escapeString($imgbytes), $rageid));
$name = $pdo->query("Select releasetitle from tvrage where rageid = " . $rageid);
echo $pdo->log->primary("Updated: " . $name[0]['releasetitle']);
$diff = floor((microtime(true) - $starttime) * 1000000);
if (1000000 - $diff > 0) {
echo $pdo->log->alternate("Sleeping");
usleep(1000000 - $diff);
}
}
}
@@ -0,0 +1,73 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$c = new ColorCLI();
$covers = $updated = $deleted = 0;
if ($argc == 1 || $argv[1] != 'true') {
exit($c->error("\nThis script will check all images in covers/xxx and compare to db->xxxinfo.\nTo run:\nphp $argv[0] true\n"));
}
$path2covers = NN_COVERS . 'xxx' . DS;
$dirItr = new RecursiveDirectoryIterator($path2covers);
$itr = new RecursiveIteratorIterator($dirItr, RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($itr as $filePath) {
if (is_file($filePath) && preg_match('/-cover\.jpg/', $filePath)) {
preg_match('/(\d+)-cover\.jpg/', basename($filePath), $match);
if (isset($match[1])) {
$run = $pdo->queryDirect("UPDATE xxxinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]);
if ($run->rowCount() >= 1) {
$covers++;
} else {
$run = $pdo->queryDirect("SELECT id FROM xxxinfo WHERE id = " . $match[1]);
if ($run->rowCount() == 0) {
echo $c->info($filePath . " not found in db.");
}
}
}
}
if (is_file($filePath) && preg_match('/-backdrop\.jpg/', $filePath)) {
preg_match('/(\d+)-backdrop\.jpg/', basename($filePath), $match1);
if (isset($match1[1])) {
$run = $pdo->queryDirect("UPDATE xxxinfo SET backdrop = 1 WHERE backdrop = 0 AND id = " . $match1[1]);
if ($run->rowCount() >= 1) {
$updated++;
printf("UPDATE xxxinfo SET backdrop = 1 WHERE backdrop = 0 AND id = " . $match1[1] . "\n");
} else {
$run = $pdo->queryDirect("SELECT id FROM xxxinfo WHERE id = " . $match1[1]);
if ($run->rowCount() == 0) {
echo $c->info($filePath . " not found in db.");
}
}
}
}
}
$qry = $pdo->queryDirect("SELECT id FROM xxxinfo WHERE cover = 1");
if ($qry instanceof Traversable) {
foreach ($qry as $rows) {
if (!is_file($path2covers . $rows['id'] . '-cover.jpg')) {
$pdo->queryDirect("UPDATE xxxinfo SET cover = 0 WHERE cover = 1 AND id = " . $rows['id']);
echo $c->info($path2covers . $rows['id'] . "-cover.jpg does not exist.");
$deleted++;
}
}
}
$qry1 = $pdo->queryDirect("SELECT id FROM xxxinfo WHERE backdrop = 1");
if ($qry1 instanceof Traversable) {
foreach ($qry1 as $rows) {
if (!is_file($path2covers . $rows['id'] . '-backdrop.jpg')) {
$pdo->queryDirect("UPDATE xxxinfo SET backdrop = 0 WHERE backdrop = 1 AND id = " . $rows['id']);
echo $c->info($path2covers . $rows['id'] . "-backdrop.jpg does not exist.");
$deleted++;
}
}
}
echo $c->header($covers . " covers set.");
echo $c->header($updated . " backdrops set.");
echo $c->header($deleted . " movies unset.");
@@ -0,0 +1,51 @@
<?php
require_once(dirname(__FILE__) . "/../../../bin/config.php");
// New line for CLI.
$n = PHP_EOL;
// Include config.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));
@@ -0,0 +1,84 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see LICENSE.txt in the base directory. If
* not, see:
*
* @link <http://www.gnu.org/licenses/>.
* @author niel / kevin
* @copyright 2014 nZEDb
*/
if (!isset($argv[1]) || !in_array($argv[1], ['1'])) {
exit(
'Options: (enter a number, it\'s not recommended to rerun the same fix)' . PHP_EOL .
'1: 2014-07-28: Add unique key to binaryhash to be able to do multiple updates in 1 statement.' . PHP_EOL
);
}
require_once(dirname(__FILE__) . "/../../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
$s = new Sites();
$site = $s->get();
if (!$site->tablepergroup) {
exit("Tables per groups is not enabled, quitting!");
}
$groups = $pdo->queryDirect('SELECT id FROM groups WHERE active = 1 OR backfill = 1');
if ($groups === false) {
echo "No active groups. Fix not needed.\n";
} else {
$queries = array();
switch ($argv[1]) {
case 1:
// Drop this index, as we will recreate it as a unique.
$queries[] = ['t' => 1, 'q' => 'ALTER TABLE binaries_%d DROP INDEX ix_binary_binaryhash'];
// Recreate the index as unique so we can use on duplicate key update, saving select / update query.
$queries[] = ['t' => 1, 'q' => 'ALTER IGNORE TABLE binaries_%d ADD UNIQUE INDEX ix_binary_binaryhash(binaryhash)'];
break;
default:
exit();
}
$groupCount = $groups->rowCount();
if ($groups instanceof \Traversable && count($queries) && $groupCount) {
foreach ($groups as $group) {
echo 'Fixing group ' . $group['id'] . PHP_EOL;
foreach ($queries as $query) {
switch ($query['t']) {
// Queries needing 1 group id.
case 1:
$pdo->queryExec(sprintf($query['q'], $group['id']), true);
break;
// Queries needing 2 group IDs.
case 2:
$pdo->queryExec(sprintf($query['q'], $group['id'], $group['id']), true);
break;
// Queries needing 3 group IDs.
case 3:
$pdo->queryExec(sprintf($query['q'], $group['id'], $group['id'], $group['id']), true);
break;
}
}
echo 'Finished fixing group ' . $group['id'] . ', ' . (--$groupCount) . ' to go!' .PHP_EOL;
}
}
echo 'All done!' . PHP_EOL;
}
@@ -0,0 +1,80 @@
<?php
require_once(dirname(__FILE__) . "/../../bin/config.php");
$n = PHP_EOL;
// Print usage.
if (count($argv) !== 6) {
exit(
'This will import NZB files(.nzb or .nzb.gz), into your newznab 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], ['true', 'false'])) {
exit('Error: arg2 must be true or false' . $n);
}
if (!in_array($argv[3], ['true', 'false'])) {
exit('Error: arg3 must be true or false' . $n);
}
if (!in_array($argv[4], ['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 = [];
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;
}
@@ -0,0 +1,18 @@
<?php
/* This script is designed to gather all show data from anidb and add it to the anidb table for newznab, as part of this process we need the number of PI queries that can be executed max and whether or not we want debuging the first argument if unset will try to do the entire list (a good way to get banned), the second option can be blank or true for debugging.
* IF you are using this script then then you also want to edit anidb.php in www/lib and locate "604800" and replace it with 1204400, this will make sure it never tries to connect to anidb as this will fail
*/
require_once(dirname(__FILE__) . "/../../bin/config.php");
use newznab\db\DB;
$pdo = new DB();
if ($argc > 1 && $argv[1] == true) {
(new \PopulateAniDB(['Settings' => $pdo, 'Echo' => true]))->populateTable('full');
} else {
$pdo->log->doEcho(PHP_EOL . $pdo->log->error(
"To execute this script you must provide a boolean argument." . PHP_EOL .
"Argument1: true|false to run this script or not"), true
);
}
@@ -0,0 +1,250 @@
<?php
/* TODO better tune the queries for performance, including using prepared statements and
pre-fetching groupid and other data for faster inclusion in the main query.
*/
use newznab\db\DB;
use newznab\utility\Utility;
$config = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
'config.php';
if (!is_file($config)) {
exit('Place this script in the lib/testing folder of tmux.' . PHP_EOL);
}
require_once $config;
unset($config);
if (!Utility::isWin()) {
$fullPath = DS;
$paths = preg_split('#/#', NN_RES);
foreach ($paths as $path) {
if ($path !== '') {
$fullPath .= $path . DS;
if (!is_readable($fullPath) || !is_executable($fullPath)) {
exit('The (' . $fullPath . ') folder must be readable and executable by all.' .
PHP_EOL);
}
}
}
unset($fullPath, $paths, $path);
}
if (!is_writable(NN_RES)) {
exit('The (' . NN_RES . ') folder must be writable.' . PHP_EOL);
}
$progress = rw_progress(settings_array());
if (!isset($argv[1]) || !is_numeric($argv[1]) && $argv[1] != 'progress' || !isset($argv[2]) ||
!in_array($argv[2], ['local', 'remote']) || !isset($argv[3]) ||
!in_array($argv[3], ['true', 'false'])
) {
exit('This script quickly imports the daily PreDB dumps.' . PHP_EOL .
'Argument 1: Enter the unix time of the patch to start at.' . PHP_EOL .
'You can find the unix time in the file name of the patch, it\'s the long number.' .
PHP_EOL .
'You can put in 0 to import all the daily PreDB dumps.' . PHP_EOL .
'You can put in progress to track progress of the imports and only import newer ones.' .
PHP_EOL .
'Argument 2: If your MySQL server is local, type local else type remote.' . PHP_EOL .
'Argument 3: Show output of dump_predb.php or not, true | false' . PHP_EOL
);
}
$fileName = '_predb_dump.csv.gz';
$innerUrl = 'fb2pffwwriruyco';
$baseUrl = 'https://www.dropbox.com/sh/' . $innerUrl;
$folderUrl['url'] = $baseUrl . '/AACy9Egno_v2kcziVHuvWbbxa';
$result = Utility::getUrl($folderUrl);
if (!$result) {
exit('Error connecting to dropbox.com, try again later?' . PHP_EOL);
}
$result = preg_match_all('/<a href="https:\/\/www.dropbox.com\/sh\/' . $innerUrl . '\/(\S+\/\d+' .
$fileName . '\?dl=0)"/',
$result,
$all_matches);
if ($result) {
exec('clear');
$all_matches = array_unique($all_matches[1]);
$total = count($all_matches);
$pdo = new DB();
if ($argv[1] != 'progress') {
$progress['last'] = !is_numeric($argv[1]) ? time() : $argv[1];
}
$pdo->queryExec('DROP TABLE IF EXISTS tmp_pre');
$pdo->queryExec('CREATE TABLE tmp_pre LIKE prehash');
// Drop id as it is not needed and incurs overhead creating each id.
$pdo->queryExec('ALTER TABLE tmp_pre DROP COLUMN id');
// Add a column for the group's name which is included instead of the groupid, which may be
// different between individual databases
$pdo->queryExec('ALTER TABLE tmp_pre ADD COLUMN groupname VARCHAR (255)');
// Drop indexes on tmp_pre
$pdo->queryExec('ALTER TABLE tmp_pre DROP INDEX `ix_prehash_nfo`, DROP INDEX `ix_prehash_predate`, DROP INDEX `ix_prehash_source`, DROP INDEX `ix_prehash_title`, DROP INDEX `ix_prehash_requestid`');
foreach ($all_matches as $matches) {
if (preg_match('#^(.+)/(\d+)_#', $matches, $match)) {
$timematch = -1 + $progress['last'];
// Skip patches the user does not want.
if ($match[2] < $timematch) {
echo 'Skipping dump ' . $match[2] . ', as your minimum unix time argument is ' .
$timematch . PHP_EOL;
--$total;
continue;
}
// Download the dump.
$file['url'] = $baseUrl . '/' . $match[1] . '/' . $match[2] . $fileName . '?dl=1';
$dump = Utility::getUrl($file);
if (!$dump) {
echo 'Error downloading dump ' . $match[2] . ' you can try manually importing it.' .
PHP_EOL;
continue;
}
// Make sure we didn't get a HTML page.
if (strlen($dump) < 5000 && strpos($dump, '<!DOCTYPE html>') !== false) {
echo 'The dump file ' . $match[2] . ' might be missing from dropbox.' . PHP_EOL;
continue;
}
// Decompress.
$dump = gzdecode($dump);
if (!$dump) {
echo 'Error decompressing dump ' . $match[2] . '.' . PHP_EOL;
continue;
}
// Store the dump.
$dumpFile = NN_RES . $match[2] . '_predb_dump.csv';
$fetched = file_put_contents($dumpFile, $dump);
if (!$fetched) {
echo 'Error storing dump file ' . $match[2] . ' in (' . NN_RES . ').' . PHP_EOL;
continue;
}
// Make sure it's readable by all.
chmod($dumpFile, 0777);
$local = strtolower($argv[2]) == 'local' ? true : false;
$verbose = $argv[3] == true ? true : false;
importDump($dumpFile, $local, $verbose);
// Delete the dump.
// unlink($dumpFile);
$progress = rw_progress(settings_array($match[2] + 1, $progress), false);
echo 'Successfully imported PreDB dump ' . $match[2] . ' ' . (--$total) .
' dumps remaining to import.' . PHP_EOL;
}
}
// Drop tmp_pre table
$pdo->queryExec('DROP TABLE IF EXISTS tmp_pre');
}
function settings_array($last = null, $settings = null)
{
if (is_null($settings)) {
$settings['last'] = 0;
}
if (!is_null($last)) {
$settings['last'] = $last;
}
return $settings;
}
function rw_progress($settings, $read = true)
{
if (!$read || !is_file(__DIR__ . DS . 'prehash_progress.txt')) {
file_put_contents(__DIR__ . DS . 'prehash_progress.txt', base64_encode(serialize($settings)));
} else {
$settings = unserialize(base64_decode(file_get_contents(__DIR__ . DS .
'prehash_progress.txt')));
}
return $settings;
}
// This function duplicates how dump_predb works but does not drop the hashes/triggers as recreating
// potentially millions for the small addition that dailies add, isn't worth it.
function importDump($path, $local, $verbose = true, $table = 'prehash')
{
global $pdo;
// Create temp table to allow updating
if ($verbose) {
echo $pdo->log->info("Creating temporary table");
}
// TRuncate to clear any old data
$pdo->queryDirect("TRUNCATE TABLE tmp_pre");
// Import file into tmp_pre
$sqlLoad = sprintf(
"LOAD DATA %s INFILE '%s' IGNORE INTO TABLE tmp_pre FIELDS TERMINATED BY '\\t\\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\\r\\n' (title, nfo, size, files, filename, nuked, nukereason, category, predate, source, requestid, groupname);",
($local === false ? 'LOCAL' : ''),
$path
);
if (NN_DEBUG) {
echo $pdo->log->header($sqlLoad);
}
$pdo->queryDirect($sqlLoad);
// Remove any titles where length <=8
if ($verbose) {
echo $pdo->log->info("Deleting any records where title <=8 from Temporary Table");
}
$pdo->queryDirect("DELETE FROM tmp_pre WHERE LENGTH(title) <= 8");
// Add any groups that do not currently exist
$sqlAddGroups = <<<SQL_ADD_GROUPS
INSERT IGNORE INTO groups (`name`, description)
SELECT groupname, 'Added by predb import script'
FROM tmp_pre AS t LEFT JOIN groups AS g ON t.`groupname` = g.`name`
WHERE t.`groupname` IS NOT NULL AND g.`name` IS NULL
GROUP BY groupname;
SQL_ADD_GROUPS;
$pdo->queryDirect($sqlAddGroups);
// Fill the groupid
$pdo->queryDirect("UPDATE tmp_pre AS t SET groupid = (SELECT id FROM groups WHERE name = t.groupname) WHERE groupname IS NOT NULL");
// Insert and update table
$sqlInsert = <<<SQL_INSERT
INSERT INTO $table (title, nfo, size, files, filename, nuked, nukereason, category, predate, SOURCE, requestid, groupid)
SELECT t.title, t.nfo, t.size, t.files, t.filename, t.nuked, t.nukereason, t.category, t.predate, t.source, t.requestid, t.groupid
FROM tmp_pre AS t
ON DUPLICATE KEY UPDATE prehash.nfo = IF(prehash.nfo IS NULL, t.nfo, prehash.nfo),
prehash.size = IF(prehash.size IS NULL, t.size, prehash.size),
prehash.files = IF(prehash.files IS NULL, t.files, prehash.files),
prehash.filename = IF(prehash.filename = '', t.filename, prehash.filename),
prehash.nuked = IF(t.nuked > 0, t.nuked, prehash.nuked),
prehash.nukereason = IF(t.nuked > 0, t.nukereason, prehash.nukereason),
prehash.category = IF(prehash.category IS NULL, t.category, prehash.category),
prehash.requestid = IF(prehash.requestid = 0, t.requestid, prehash.requestid),
prehash.groupid = IF(prehash.groupid = 0, t.groupid, prehash.groupid);
SQL_INSERT;
echo $pdo->log->info("Inserting records from temporary table into $table");
if (NN_DEBUG) {
echo $pdo->log->primary($sqlInsert);
}
if ($pdo->queryDirect($sqlInsert) === false) {
echo "FAILED\n";
}
}
@@ -0,0 +1,117 @@
<?php
require_once(dirname(__FILE__) . "/../../bin/config.php");
use newznab\db\DB;
$c = new ColorCLI();
if (!(isset($argv[1]) && ($argv[1] == "all" || $argv[1] == "misc" || preg_match('/\([\d, ]+\)/', $argv[1]) || is_numeric($argv[1])))) {
exit($c->error(
"\nThis script will attempt to re-categorize releases and is useful if changes have been made to Category.php.\n"
. "No updates will be done unless the category changes\n"
. "An optional last argument, test, will display the number of category changes that would be made\n"
. "but will not update the database.\n\n"
. "php $argv[0] all ...: To process all releases.\n"
. "php $argv[0] misc ...: To process all releases in misc categories.\n"
. "php $argv[0] 155 ...: To process all releases in groupid 155.\n"
. "php $argv[0] '(155, 140)' ...: To process all releases in group_ids 155 and 140.\n"
));
}
reCategorize($argv);
function reCategorize($argv)
{
$c = new ColorCLI();
$where = '';
$update = true;
if (isset($argv[1]) && is_numeric($argv[1])) {
$where = ' AND groupid = ' . $argv[1];
} else if (isset($argv[1]) && preg_match('/\([\d, ]+\)/', $argv[1])) {
$where = ' AND groupid IN ' . $argv[1];
} else if (isset($argv[1]) && $argv[1] === 'misc') {
$where = ' AND categoryid IN (1090, 2020, 3050, 4040, 5050, 6050, 7050, 8010)';
}
if (isset($argv[2]) && $argv[2] === 'test') {
$update = false;
}
if (isset($argv[1]) && (is_numeric($argv[1]) || preg_match('/\([\d, ]+\)/', $argv[1]))) {
echo $c->header("Categorizing all releases in ${argv[1]} using searchname. This can take a while, be patient.");
} else if (isset($argv[1]) && $argv[1] == "misc") {
echo $c->header("Categorizing all releases in misc categories using searchname. This can take a while, be patient.");
} else {
echo $c->header("Categorizing all releases using searchname. This can take a while, be patient.");
}
$timestart = TIME();
if (isset($argv[1]) && (is_numeric($argv[1]) || preg_match('/\([\d, ]+\)/', $argv[1])) || $argv[1] === 'misc') {
$chgcount = categorizeRelease($update, str_replace(" AND", "WHERE", $where), true);
} else {
$chgcount = categorizeRelease($update, "", true);
}
$consoletools = new ConsoleTools();
$time = $consoletools->convertTime(TIME() - $timestart);
if ($update === true) {
echo $c->header("Finished re-categorizing " . number_format($chgcount) . " releases in " . $time . " , using the searchname.\n");
} else {
echo $c->header("Finished re-categorizing in " . $time . " , using the searchname.\n"
. "This would have changed " . number_format($chgcount) . " releases but no updates were done.\n"
);
}
}
// Categorizes releases.
// Returns the quantity of categorized releases.
function categorizeRelease($update = true, $where, $echooutput = false)
{
$pdo = new DB();
$cat = new Categorize();
$consoletools = new consoleTools();
$relcount = $chgcount = 0;
$c = new ColorCLI();
echo $c->primary("SELECT id, searchname, groupid, categoryid FROM releases " . $where);
$resrel = $pdo->queryDirect("SELECT id, searchname, groupid, categoryid FROM releases " . $where);
$total = $resrel->rowCount();
if ($total > 0) {
foreach ($resrel as $rowrel) {
$catId = $cat->determineCategory($rowrel['groupid'], $rowrel['searchname']);
if ($rowrel['categoryid'] != $catId) {
if ($update === true) {
$pdo->queryExec(
sprintf("
UPDATE releases
SET iscategorized = 1,
rageid = -1,
seriesfull = NULL,
season = NULL,
episode = NULL,
tvtitle = NULL,
tvairdate = NULL,
imdbid = NULL,
musicinfoid = NULL,
consoleinfoid = NULL,
gamesinfo_id = 0,
xxxinfo_id = 0,
bookinfoid = NULL,
anidbid = NULL,
categoryid = %d
WHERE id = %d",
$catId,
$rowrel['id']
)
);
}
$chgcount++;
}
$relcount++;
if ($echooutput) {
$consoletools->overWritePrimary("Re-Categorized: [" . number_format($chgcount) . "] " . $consoletools->percentString($relcount, $total));
}
}
}
if ($echooutput !== false && $relcount > 0) {
echo "\n";
}
return $chgcount;
}