mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-31 02:08:57 +00:00
Move files to logical positions, no more copying of files.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
processAlternate*
|
||||
processAdditional*
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . "/../../../../../www/config.php");
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . "/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\processing\PProcess;
|
||||
|
||||
$c = new ColorCLI();
|
||||
if (!isset($argv[1])) {
|
||||
exit($c->error("This script is not intended to be run manually, it is called from fixreleasenames_threaded.py."));
|
||||
} else if (isset($argv[1])) {
|
||||
$db = new Settings();
|
||||
$namefixer = new \NameFixer(['Settings' => $pdo]);
|
||||
$pieces = explode(' ', $argv[1]);
|
||||
if (isset($pieces[1]) && $pieces[0] == 'nfo') {
|
||||
$release = $pieces[1];
|
||||
if ($res = $db->queryOneRow(sprintf('SELECT rel.guid AS guid, nfo.releaseid AS nfoid, rel.groupid, rel.categoryid, rel.name, rel.searchname, uncompress(nfo) AS textstring, rel.id AS releaseid FROM releases rel INNER JOIN releasenfo nfo ON (nfo.releaseid = rel.id) WHERE rel.id = %d', $release))) {
|
||||
//ignore encrypted nfos
|
||||
if (preg_match('/^=newz\[NZB\]=\w+/', $res['textstring'])) {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
$db->queryDirect(sprintf('UPDATE releases SET proc_nfo = 1 WHERE id = %d', $res['releaseid']));
|
||||
$namefixer->checked++;
|
||||
echo '.';
|
||||
} else {
|
||||
//echo $res['textstring']."\n";
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
if ($namefixer->checkName($res, true, 'NFO, ', 1, 1) !== true) {
|
||||
echo '.';
|
||||
}
|
||||
$namefixer->checked++;
|
||||
}
|
||||
}
|
||||
} else if (isset($pieces[1]) && $pieces[0] == 'filename') {
|
||||
$release = $pieces[1];
|
||||
if ($res = $db->queryOneRow(sprintf('SELECT relfiles.name AS textstring, rel.categoryid, rel.searchname, '
|
||||
. 'rel.groupid, relfiles.releaseid AS fileid, rel.id AS releaseid, rel.name FROM releases rel '
|
||||
. 'INNER JOIN releasefiles relfiles ON (relfiles.releaseid = rel.id) WHERE rel.id = %d', $release))) {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
if ($namefixer->checkName($res, true, 'Filenames, ', 1, 1) !== true) {
|
||||
echo '.';
|
||||
}
|
||||
$namefixer->checked++;
|
||||
}
|
||||
} else if (isset($pieces[1]) && $pieces[0] == 'md5') {
|
||||
$release = $pieces[1];
|
||||
if ($res = $db->queryOneRow(sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.groupid, dehashstatus, rf.name AS filename FROM releases r LEFT JOIN releasefiles rf ON r.id = rf.releaseid WHERE r.id = %d', $release))) {
|
||||
if (preg_match('/[a-fA-F0-9]{32,40}/i', $res['name'], $matches)) {
|
||||
$namefixer->matchPredbHash($matches[0], $res, 1, 1, true, 1);
|
||||
} else if (preg_match('/[a-fA-F0-9]{32,40}/i', $res['filename'], $matches)) {
|
||||
$namefixer->matchPredbHash($matches[0], $res, 1, 1, true, 1);
|
||||
} else {
|
||||
$db->queryExec(sprintf("UPDATE releases SET dehashstatus = %d - 1 WHERE id = %d", $res['dehashstatus'], $res['releaseid']));
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
} else if (isset($pieces[1]) && $pieces[0] == 'par2') {
|
||||
$nntp = new NNTP();
|
||||
if ($nntp->doConnect() === false) {
|
||||
exit($c->error("Unable to connect to usenet."));
|
||||
}
|
||||
|
||||
$relID = $pieces[1];
|
||||
$guid = $pieces[2];
|
||||
$groupID = $pieces[3];
|
||||
$nzbcontents = new NZBContents(array('echo' => true, 'nntp' => $nntp, 'nfo' => new Info(), 'db' => $db, 'pp' => new PProcess(['Settings' => $pdo, 'Nfo' => $Nfo, 'NameFixer' => $namefixer])));
|
||||
$res = $nzbcontents->checkPAR2($guid, $relID, $groupID, 1, 1);
|
||||
if ($res === false) {
|
||||
echo '.';
|
||||
}
|
||||
|
||||
$nntp->doQuit();
|
||||
|
||||
} else if (isset($pieces[1]) && $pieces[0] == 'predbft') {
|
||||
$pre = $pieces[1];
|
||||
if ($res = $db->queryOneRow(sprintf('SELECT id AS preid, title, source, searched FROM prehash '
|
||||
. 'WHERE id = %d', $pre
|
||||
)
|
||||
)
|
||||
) {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
$ftmatched = $searched = 0;
|
||||
$ftmatched = $namefixer->matchPredbFT($res, 1, 1, true, 1);
|
||||
if ($ftmatched > 0) {
|
||||
$searched = 1;
|
||||
} elseif ($ftmatched < 0) {
|
||||
$searched = -6;
|
||||
echo "*";
|
||||
} else {
|
||||
$searched = $res['searched'] - 1;
|
||||
echo ".";
|
||||
}
|
||||
$db->queryExec(sprintf("UPDATE prehash SET searched = %d WHERE id = %d", $searched, $res['preid']));
|
||||
$namefixer->checked++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\processing\PProcess;
|
||||
|
||||
$pdo = new Settings();
|
||||
$s = new Sites();
|
||||
$site = $s->get();
|
||||
|
||||
if (!isset($argv[1])) {
|
||||
exit($pdo->log->error("This script is not intended to be run manually, it is called from groupfixrelnames_threaded.py."));
|
||||
} else if (isset($argv[1])) {
|
||||
$namefixer = new \NameFixer(['Settings' => $pdo]);
|
||||
$pieces = explode(' ', $argv[1]);
|
||||
$guidChar = $pieces[1];
|
||||
$maxperrun = $pieces[2];
|
||||
$thread = $pieces[3];
|
||||
|
||||
switch (true) {
|
||||
case $pieces[0] === 'nfo' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
|
||||
$releases = $pdo->queryDirect(
|
||||
sprintf('
|
||||
SELECT r.id AS releaseid, r.guid, r.groupid, r.categoryid, r.name, r.searchname,
|
||||
uncompress(nfo) AS textstring
|
||||
FROM releases r
|
||||
INNER JOIN releasenfo rn ON r.id = rn.releaseid
|
||||
WHERE r.guid %s
|
||||
AND r.nzbstatus = 1
|
||||
AND r.proc_nfo = 0
|
||||
AND r.nfostatus = 1
|
||||
AND r.prehashid = 0
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT %s',
|
||||
$pdo->likeString($guidChar, false, true),
|
||||
$maxperrun
|
||||
)
|
||||
);
|
||||
|
||||
if ($releases instanceof Traversable) {
|
||||
foreach ($releases as $release) {
|
||||
if (preg_match('/^=newz\[NZB\]=\w+/', $release['textstring'])) {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
$pdo->queryDirect(sprintf('UPDATE releases SET proc_nfo = 1 WHERE id = %d', $release['releaseid']));
|
||||
$namefixer->checked++;
|
||||
echo '.';
|
||||
} else {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
if ($namefixer->checkName($release, true, 'NFO, ', 1, 1) !== true) {
|
||||
echo '.';
|
||||
}
|
||||
$namefixer->checked++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case $pieces[0] === 'filename' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
|
||||
$releases = $pdo->queryDirect(
|
||||
sprintf('
|
||||
SELECT rf.name AS textstring, rf.releaseid AS fileid,
|
||||
r.id AS releaseid, r.name, r.searchname, r.categoryid, r.groupid
|
||||
FROM releases r
|
||||
INNER JOIN releasefiles rf ON r.id = rf.releaseid
|
||||
WHERE r.guid %s
|
||||
AND r.nzbstatus = 1 AND r.proc_files = 0
|
||||
AND r.prehashid = 0
|
||||
ORDER BY r.postdate ASC
|
||||
LIMIT %s',
|
||||
$pdo->likeString($guidChar, false, true),
|
||||
$maxperrun
|
||||
)
|
||||
);
|
||||
|
||||
if ($releases instanceof Traversable) {
|
||||
foreach ($releases as $release) {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
if ($namefixer->checkName($release, true, 'Filenames, ', 1, 1) !== true) {
|
||||
echo '.';
|
||||
}
|
||||
$namefixer->checked++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case $pieces[0] === 'md5' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
|
||||
$releases = $pdo->queryDirect(
|
||||
sprintf('
|
||||
SELECT DISTINCT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.groupid, r.dehashstatus,
|
||||
rf.name AS filename
|
||||
FROM releases r
|
||||
LEFT OUTER JOIN releasefiles rf ON r.id = rf.releaseid AND rf.ishashed = 1
|
||||
WHERE r.guid %s
|
||||
AND nzbstatus = 1 AND r.ishashed = 1
|
||||
AND r.dehashstatus BETWEEN -6 AND 0
|
||||
AND r.prehashid = 0
|
||||
ORDER BY r.dehashstatus DESC, r.postdate ASC
|
||||
LIMIT %s',
|
||||
$pdo->likeString($guidChar, false, true),
|
||||
$maxperrun
|
||||
)
|
||||
);
|
||||
|
||||
if ($releases instanceof Traversable) {
|
||||
foreach ($releases as $release) {
|
||||
if (preg_match('/[a-fA-F0-9]{32,40}/i', $release['name'], $matches)) {
|
||||
$namefixer->matchPredbHash($matches[0], $release, 1, 1, true, 1);
|
||||
} else if (preg_match('/[a-fA-F0-9]{32,40}/i', $release['filename'], $matches)) {
|
||||
$namefixer->matchPredbHash($matches[0], $release, 1, 1, true, 1);
|
||||
} else {
|
||||
$pdo->queryExec(sprintf("UPDATE releases SET dehashstatus = %d - 1 WHERE id = %d", $release['dehashstatus'], $release['releaseid']));
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case $pieces[0] === 'par2' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
|
||||
$releases = $pdo->queryDirect(
|
||||
sprintf('
|
||||
SELECT r.id AS releaseid, r.guid, r.groupid
|
||||
FROM releases r
|
||||
WHERE r.guid %s
|
||||
AND r.nzbstatus = 1
|
||||
AND r.proc_par2 = 0
|
||||
AND r.prehashid = 0
|
||||
ORDER BY r.postdate ASC
|
||||
LIMIT %s',
|
||||
$pdo->likeString($guidChar, false, true),
|
||||
$maxperrun
|
||||
)
|
||||
);
|
||||
|
||||
if ($releases instanceof Traversable) {
|
||||
$nntp = new NNTP(['Settings' => $pdo]);
|
||||
if (($site->alternate_nntp == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) {
|
||||
exit($pdo->log->error("Unable to connect to usenet."));
|
||||
}
|
||||
|
||||
$Nfo = new Info(['Settings' => $pdo, 'Echo' => true]);
|
||||
$nzbcontents = new NZBContents(
|
||||
array(
|
||||
'Echo' => true, 'NNTP' => $nntp, 'Nfo' => $Nfo, 'Settings' => $pdo,
|
||||
'PostProcess' => new PProcess(['Settings' => $pdo, 'Nfo' => $Nfo, 'NameFixer' => $namefixer])
|
||||
)
|
||||
);
|
||||
foreach ($releases as $release) {
|
||||
$res = $nzbcontents->checkPAR2($release['guid'], $release['releaseid'], $release['groupid'], 1, 1);
|
||||
if ($res === false) {
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case $pieces[0] === 'miscsorter' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
|
||||
$releases = $pdo->queryDirect(
|
||||
sprintf('
|
||||
SELECT r.id AS releaseid
|
||||
FROM releases r
|
||||
WHERE r.guid %s
|
||||
AND r.nzbstatus = 1 AND r.nfostatus = 1
|
||||
AND r.proc_sorter = 0 AND r.isrenamed = 0
|
||||
AND r.prehashid = 0
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT %s',
|
||||
$pdo->likeString($guidChar, false, true),
|
||||
$maxperrun
|
||||
)
|
||||
);
|
||||
|
||||
if ($releases instanceof Traversable) {
|
||||
$sorter = new MiscSorter(true, $pdo);
|
||||
foreach ($releases as $release) {
|
||||
$res = $sorter->nfosorter(null, $release['releaseid']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case $pieces[0] === 'predbft' && isset($maxperrun) && is_numeric($maxperrun) && isset($thread) && is_numeric($thread):
|
||||
$pres = $pdo->queryDirect(
|
||||
sprintf('
|
||||
SELECT p.id AS prehashid, p.title, p.source, p.searched
|
||||
FROM prehash p
|
||||
WHERE LENGTH(title) >= 15 AND title NOT REGEXP "[\"\<\> ]"
|
||||
AND searched = 0
|
||||
AND DATEDIFF(NOW(), predate) > 1
|
||||
ORDER BY predate ASC
|
||||
LIMIT %s
|
||||
OFFSET %s',
|
||||
$maxperrun,
|
||||
$thread * $maxperrun - $maxperrun
|
||||
)
|
||||
);
|
||||
|
||||
if ($pres instanceof Traversable) {
|
||||
foreach ($pres as $pre) {
|
||||
$namefixer->done = $namefixer->matched = false;
|
||||
$ftmatched = $searched = 0;
|
||||
$ftmatched = $namefixer->matchPredbFT($pre, 1, 1, true, 1);
|
||||
if ($ftmatched > 0) {
|
||||
$searched = 1;
|
||||
} elseif ($ftmatched < 0) {
|
||||
$searched = -6;
|
||||
echo "*";
|
||||
} else {
|
||||
$searched = $pre['searched'] - 1;
|
||||
echo ".";
|
||||
}
|
||||
$pdo->queryExec(sprintf("UPDATE prehash SET searched = %d WHERE id = %d", $searched, $pre['prehashid']));
|
||||
$namefixer->checked++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . '/config.php');
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\processing\PProcess;
|
||||
|
||||
$pdo = new Settings();
|
||||
$s = new Sites();
|
||||
$site = $s->get();
|
||||
/**
|
||||
Array with possible arguments for run and
|
||||
whether or not those methods of operation require NNTP
|
||||
**/
|
||||
|
||||
$args = array(
|
||||
'additional' => true,
|
||||
'all' => true,
|
||||
'allinf' => true,
|
||||
'amazon' => false,
|
||||
'anime' => false,
|
||||
'book' => false,
|
||||
'console' => false,
|
||||
'games' => false,
|
||||
'movies' => false,
|
||||
'music' => false,
|
||||
'nfo' => true,
|
||||
'pre' => true,
|
||||
'sharing' => true,
|
||||
'spotnab' => true,
|
||||
'tv' => false,
|
||||
'tvdb' => false,
|
||||
'xxx' => false,
|
||||
);
|
||||
|
||||
$bool = array(
|
||||
'true',
|
||||
'false'
|
||||
);
|
||||
|
||||
if (!isset($argv[1]) || !in_array($argv[1], $args) || !isset($argv[2]) || !in_array($argv[2], $bool)) {
|
||||
exit(
|
||||
$pdo->log->error(
|
||||
"\nIncorrect arguments.\n"
|
||||
. "The second argument (true/false) determines wether to echo or not.\n\n"
|
||||
. "php postprocess.php all true ...: Does all the types of post processing.\n"
|
||||
. "php postprocess.php pre true ...: Processes all Predb sites.\n"
|
||||
. "php postprocess.php nfo true ...: Processes NFO files.\n"
|
||||
. "php postprocess.php movies true ...: Processes movies.\n"
|
||||
. "php postprocess.php music true ...: Processes music.\n"
|
||||
. "php postprocess.php console true ...: Processes console games.\n"
|
||||
. "php postprocess.php games true ...: Processes games.\n"
|
||||
. "php postprocess.php book true ...: Processes books.\n"
|
||||
. "php postprocess.php anime true ...: Processes anime.\n"
|
||||
. "php postprocess.php tv true ...: Processes tv.\n"
|
||||
. "php postprocess.php tvdb true ...: Processes tvdb.\n"
|
||||
. "php postprocess.php xxx true ...: Processes xxx.\n"
|
||||
. "php postprocess.php additional true ...: Processes previews/mediainfo/etc...\n"
|
||||
. "php postprocess.php sharing true ...: Processes uploading/downloading comments.\n"
|
||||
. "php postprocess.php spotnab true ...: Processes uploading/downloading comments from spotnab.\n"
|
||||
. "php postprocess.php allinf true ...: Does all the types of post processing on a loop, sleeping 15 seconds between.\n"
|
||||
. "php postprocess.php amazon true ...: Does all the amazon (books/console/games/music/xxx).\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$nntp = null;
|
||||
if ($args[$argv[1]] === true) {
|
||||
$nntp = new NNTP(['Settings' => $pdo]);
|
||||
if (($site->alternate_nntp == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) {
|
||||
exit($pdo->log->error("Unable to connect to usenet." . PHP_EOL));
|
||||
}
|
||||
}
|
||||
|
||||
$postProcess = new PProcess(['Settings' => $pdo, 'Echo' => ($argv[2] === 'true' ? true : false)]);
|
||||
|
||||
$charArray = ['a','b','c','d','e','f','0','1','2','3','4','5','6','7','8','9'];
|
||||
|
||||
switch ($argv[1]) {
|
||||
|
||||
case 'all':
|
||||
$postProcess->processAll($nntp);
|
||||
break;
|
||||
case 'allinf':
|
||||
$i = 1;
|
||||
while ($i = 1) {
|
||||
$postProcess->processAll($nntp);
|
||||
sleep(15);
|
||||
}
|
||||
break;
|
||||
case 'additional':
|
||||
$postProcess->processAdditional($nntp, '', (isset($argv[3]) && in_array($argv[3], $charArray) ? $argv[3] : ''));
|
||||
break;
|
||||
case 'amazon':
|
||||
$postProcess->processBooks();
|
||||
$postProcess->processConsoles();
|
||||
$postProcess->processGames();
|
||||
$postProcess->processMusic();
|
||||
$postProcess->processXXX();
|
||||
break;
|
||||
case 'anime':
|
||||
$postProcess->processAnime();
|
||||
break;
|
||||
case 'book':
|
||||
$postProcess->processBooks();
|
||||
break;
|
||||
case 'console':
|
||||
$postProcess->processConsoles();
|
||||
break;
|
||||
case 'games':
|
||||
$postProcess->processGames();
|
||||
break;
|
||||
case 'nfo':
|
||||
$postProcess->processNfos($nntp, '', (isset($argv[3]) && in_array($argv[3], $charArray) ? $argv[3] : ''));
|
||||
break;
|
||||
case 'movies':
|
||||
$postProcess->processMovies('', (isset($argv[3]) && in_array($argv[3], $charArray) ? $argv[3] : ''));
|
||||
break;
|
||||
case 'music':
|
||||
$postProcess->processMusic();
|
||||
break;
|
||||
case 'pre':
|
||||
break;
|
||||
case 'sharing':
|
||||
$postProcess->processSharing($nntp);
|
||||
break;
|
||||
case 'spotnab':
|
||||
$postProcess->processSpotnab();
|
||||
break;
|
||||
case 'tv':
|
||||
$postProcess->processTV('', (isset($argv[3]) && in_array($argv[3], $charArray) ? $argv[3] : ''));
|
||||
break;
|
||||
case 'tvdb':
|
||||
$postProcess->processTvDB();
|
||||
break;
|
||||
case 'xxx':
|
||||
$postProcess->processXXX();
|
||||
break;
|
||||
default:
|
||||
exit;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/config.php');
|
||||
|
||||
use newznab\processing\PProcess;
|
||||
|
||||
|
||||
$c = new ColorCLI();
|
||||
if (!isset($argv[1])) {
|
||||
exit($c->error("This script is not intended to be run manually, it is called from postprocess_threaded.py."));
|
||||
}
|
||||
|
||||
|
||||
$tmux = new Tmux;
|
||||
$torun = $tmux->get()->post;
|
||||
|
||||
$pieces = explode(' =+= ', $argv[1]);
|
||||
|
||||
$postprocess = new PProcess(['Echo' => true]);
|
||||
if (isset($pieces[6])) {
|
||||
// Create the connection here and pass
|
||||
$nntp = new NNTP();
|
||||
if ($nntp->doConnect() === false) {
|
||||
exit($c->error("Unable to connect to usenet."));
|
||||
}
|
||||
|
||||
$postprocess->processAdditional($nntp, $argv[1]);
|
||||
$nntp->doQuit();
|
||||
} else if (isset($pieces[3])) {
|
||||
// Create the connection here and pass
|
||||
$nntp = new NNTP();
|
||||
if ($nntp->doConnect() === false) {
|
||||
exit($c->error("Unable to connect to usenet."));
|
||||
}
|
||||
|
||||
$postprocess->processNfos($argv[1], $nntp);
|
||||
$nntp->doQuit();
|
||||
|
||||
} else if (isset($pieces[2])) {
|
||||
$postprocess->processMovies($argv[1]);
|
||||
echo '.';
|
||||
} else if (isset($pieces[1])) {
|
||||
$postprocess->processTv($argv[1]);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
//This script is ported from nZEDb and adapted for newznab
|
||||
require_once('config.php');
|
||||
|
||||
// This script is simply so I can show sleep progress in bash script
|
||||
$consoletools = new ConsoleTools();
|
||||
if (isset($argv[1]) && is_numeric($argv[1]))
|
||||
{
|
||||
$consoletools->showsleep($argv[1]);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . "/config.php");
|
||||
|
||||
|
||||
$time = TIME();
|
||||
$c = new ColorCLI();
|
||||
|
||||
if (isset($argv[1])) {
|
||||
$group = $argv[1];
|
||||
echo $c->header("Updating group {$group}");
|
||||
|
||||
$g = new Groups;
|
||||
$group = $g->getByName($group);
|
||||
|
||||
$bin = new Binaries;
|
||||
$bin->updateGroup($group);
|
||||
} else {
|
||||
$binaries = new Binaries;
|
||||
$binaries->updateAllGroups();
|
||||
}
|
||||
|
||||
function relativeTime($_time)
|
||||
{
|
||||
$d = array();
|
||||
$d[0] = array(1, "sec");
|
||||
$d[1] = array(60, "min");
|
||||
$d[2] = array(3600, "hr");
|
||||
$d[3] = array(86400, "day");
|
||||
$d[4] = array(31104000, "yr");
|
||||
|
||||
$w = array();
|
||||
|
||||
$return = "";
|
||||
$now = TIME();
|
||||
$diff = ($now - $_time);
|
||||
$secondsLeft = $diff;
|
||||
|
||||
for ($i = 4; $i > -1; $i--) {
|
||||
$w[$i] = intval($secondsLeft / $d[$i][0]);
|
||||
$secondsLeft -= ($w[$i] * $d[$i][0]);
|
||||
if ($w[$i] != 0) {
|
||||
//$return.= abs($w[$i]). " " . $d[$i][1] . (($w[$i]>1)?'s':'') ." ";
|
||||
$return .= $w[$i] . " " . $d[$i][1] . (($w[$i] > 1) ? 's' : '') . " ";
|
||||
}
|
||||
}
|
||||
|
||||
//$return .= ($diff>0)?"ago":"left";
|
||||
return $return;
|
||||
}
|
||||
|
||||
echo $c->header("Group update process completed in: " . relativeTime($time) . "\n");
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . '/config.php');
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
$start = TIME();
|
||||
$pdo = new Settings();
|
||||
$consoleTools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
|
||||
// Create the connection here and pass
|
||||
$nntp = new \NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect() !== true) {
|
||||
exit($pdo->log->error("Unable to connect to usenet."));
|
||||
}
|
||||
|
||||
echo $pdo->log->header("Getting first/last for all your active groups.");
|
||||
$data = $nntp->getGroups();
|
||||
if ($nntp->isError($data)) {
|
||||
exit($pdo->log->error("Failed to getGroups() from nntp server."));
|
||||
}
|
||||
|
||||
echo $pdo->log->header("Inserting new values into shortgroups table.");
|
||||
|
||||
$pdo->queryExec('TRUNCATE TABLE shortgroups');
|
||||
|
||||
// Put into an array all active groups
|
||||
$res = $pdo->query('SELECT name FROM groups WHERE active = 1 OR backfill = 1');
|
||||
|
||||
foreach ($data as $newgroup) {
|
||||
if (myInArray($res, $newgroup['group'], 'name')) {
|
||||
$pdo->queryInsert(sprintf('INSERT INTO shortgroups (name, first_record, last_record, updated) VALUES (%s, %s, %s, NOW())', $pdo->escapeString($newgroup['group']), $pdo->escapeString($newgroup['first']), $pdo->escapeString($newgroup['last'])));
|
||||
echo $pdo->log->primary('Updated ' . $newgroup['group']);
|
||||
}
|
||||
}
|
||||
echo $pdo->log->header('Running time: ' . $consoleTools->convertTimer(TIME() - $start));
|
||||
|
||||
function myInArray($array, $value, $key)
|
||||
{
|
||||
//loop through the array
|
||||
foreach ($array as $val) {
|
||||
//if $val is an array cal myInArray again with $val as array input
|
||||
if (is_array($val)) {
|
||||
if (myInArray($val, $value, $key)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
//else check if the given key has $value as value
|
||||
if ($array[$key] == $value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\processing\ProcessReleases;
|
||||
|
||||
$s = new \Sites();
|
||||
$site = $s->get();
|
||||
$pdo = new Settings();
|
||||
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
// Create the connection here and pass
|
||||
$nntp = new \NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect() !== true) {
|
||||
exit($pdo->log->error("Unable to connect to usenet."));
|
||||
}
|
||||
}
|
||||
if ($site->tablepergroup === 1) {
|
||||
exit($pdo->log->error("You are using 'tablepergroup', you must use .../misc/update_scripts/nix_scripts/multiprocessing/releases.php"));
|
||||
}
|
||||
|
||||
$groupName = isset($argv[3]) ? $argv[3] : '';
|
||||
if (isset($argv[1]) && isset($argv[2])) {
|
||||
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
$releases = new ProcessReleases(['Settings' => $pdo, 'ConsoleTools' => $consoletools]);
|
||||
if ($argv[1] == 1 && $argv[2] == 'true') {
|
||||
$releases->processReleases(1, 1, $groupName, $nntp, true);
|
||||
} else if ($argv[1] == 1 && $argv[2] == 'false') {
|
||||
$releases->processReleases(1, 2, $groupName, $nntp, true);
|
||||
} else if ($argv[1] == 2 && $argv[2] == 'true') {
|
||||
$releases->processReleases(2, 1, $groupName, $nntp, true);
|
||||
} else if ($argv[1] == 2 && $argv[2] == 'false') {
|
||||
$releases->processReleases(2, 2, $groupName, $nntp, true);
|
||||
} else if ($argv[1] == 4 && ($argv[2] == 'true' || $argv[2] == 'false')) {
|
||||
echo $pdo->log->header("Moving all releases to other -> misc, this can take a while, be patient.");
|
||||
$releases->resetCategorize();
|
||||
} else if ($argv[1] == 5 && ($argv[2] == 'true' || $argv[2] == 'false')) {
|
||||
echo $pdo->log->header("Categorizing all non-categorized releases in other->misc using usenet subject. This can take a while, be patient.");
|
||||
$timestart = TIME();
|
||||
$relcount = $releases->categorizeRelease('name', 'WHERE iscategorized = 0 AND categoryid = 8010');
|
||||
$time = $consoletools->convertTime(TIME() - $timestart);
|
||||
echo $pdo->log->primary("\n" . 'Finished categorizing ' . $relcount . ' releases in ' . $time . " seconds, using the usenet subject.");
|
||||
} else if ($argv[1] == 6 && $argv[2] == 'true') {
|
||||
echo $pdo->log->header("Categorizing releases in all sections using the searchname. This can take a while, be patient.");
|
||||
$timestart = TIME();
|
||||
$relcount = $releases->categorizeRelease('searchname', '');
|
||||
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
$time = $consoletools->convertTime(TIME() - $timestart);
|
||||
echo $pdo->log->primary("\n" . 'Finished categorizing ' . $relcount . ' releases in ' . $time . " seconds, using the search name.");
|
||||
} else if ($argv[1] == 6 && $argv[2] == 'false') {
|
||||
echo $pdo->log->header("Categorizing releases in misc sections using the searchname. This can take a while, be patient.");
|
||||
$timestart = TIME();
|
||||
$relcount = $releases->categorizeRelease('searchname', 'WHERE categoryid IN (1090, 2020, 3050, 5050, 6050, 8010)');
|
||||
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
$time = $consoletools->convertTime(TIME() - $timestart);
|
||||
echo $pdo->log->primary("\n" . 'Finished categorizing ' . $relcount . ' releases in ' . $time . " seconds, using the search name.");
|
||||
} else {
|
||||
exit($pdo->log->error("Wrong argument, type php update_releases.php to see a list of valid arguments."));
|
||||
}
|
||||
} else {
|
||||
exit($pdo->log->error("\nWrong set of arguments.\n"
|
||||
. "php update_releases.php 1 true ...: Creates releases and attempts to categorize new releases\n"
|
||||
. "php update_releases.php 2 true ...: Creates releases and leaves new releases in other -> misc\n"
|
||||
. "\nYou must pass a second argument whether to post process or not, true or false\n"
|
||||
. "You can pass a third optional argument, a group name (ex.: alt.binaries.multimedia).\n"
|
||||
. "\nExtra commands::\n"
|
||||
. "php update_releases.php 4 true ...: Puts all releases in other-> misc (also resets to look like they have never been categorized)\n"
|
||||
. "php update_releases.php 5 true ...: Categorizes all releases in other-> misc (which have not been categorized already)\n"
|
||||
. "php update_releases.php 6 false ...: Categorizes releases in misc sections using the search name\n"
|
||||
. "php update_releases.php 6 true ...: Categorizes releases in all sections using the search name\n"));
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
tmux_user.conf
|
||||
my.cnf
|
||||
@@ -0,0 +1,58 @@
|
||||
##
|
||||
# You should look at the following URL's in order to grasp a solid understanding
|
||||
# of Nginx configuration files in order to fully unleash the power of Nginx.
|
||||
# http://wiki.nginx.org/Pitfalls
|
||||
# http://wiki.nginx.org/QuickStart
|
||||
# http://wiki.nginx.org/Configuration
|
||||
# http://interfacelab.com/nginx-php-fpm-apc-awesome/
|
||||
#
|
||||
# Generally, you will want to move this file somewhere, and start with a clean
|
||||
# file but keep this around for reference. Or just disable in sites-enabled.
|
||||
#
|
||||
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
|
||||
##
|
||||
|
||||
server {
|
||||
# Change these settings to match your machine
|
||||
listen 80; ## listen for ipv4; this line is default and implied
|
||||
listen [::]:80 default_server ipv6only=on; ## listen for ipv6
|
||||
server_name localhost; #this must be change to an ip or fqdn or else redirects will not work
|
||||
|
||||
# Everything below here doesn't need to be changed
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
root /var/www/newznab/www/;
|
||||
index index.html index.htm index.php;
|
||||
|
||||
location ~* \.(?:ico|css|js|gif|inc|txt|gz|xml|png|jpe?g) {
|
||||
expires max;
|
||||
add_header Pragma public;
|
||||
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
|
||||
}
|
||||
|
||||
location / { try_files $uri $uri/ @rewrites; }
|
||||
|
||||
location @rewrites {
|
||||
rewrite ^/([^/\.]+)/([^/]+)/([^/]+)/? /index.php?page=$1&id=$2&subpage=$3 last;
|
||||
rewrite ^/([^/\.]+)/([^/]+)/?$ /index.php?page=$1&id=$2 last;
|
||||
rewrite ^/([^/\.]+)/?$ /index.php?page=$1 last;
|
||||
}
|
||||
|
||||
location /admin { }
|
||||
location /install { }
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
|
||||
|
||||
# With php5-cgi alone:
|
||||
#fastcgi_pass 127.0.0.1:9000;
|
||||
# With php5-fpm:
|
||||
fastcgi_pass unix:/var/run/php5-fpm.sock;
|
||||
#fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
#include /etc/nginx/fastcgi_params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
# C-b is not acceptable -- Vim uses it
|
||||
set-option -g prefix C-a
|
||||
bind-key C-a last-window
|
||||
|
||||
# use UTF8
|
||||
set -g utf8
|
||||
set-window-option -g utf8 on
|
||||
|
||||
# Start numbering at 1
|
||||
#set -g base-index 1
|
||||
|
||||
# Start panes at 1 instead of 0. tmux 1.6 only
|
||||
#setw -g pane-base-index 1
|
||||
|
||||
# Allows for faster key repetition
|
||||
set -s escape-time 0
|
||||
|
||||
#set 256 color display
|
||||
set -g default-terminal "screen-256color"
|
||||
|
||||
# Set status bar
|
||||
set -g status-bg black
|
||||
set -g status-fg white
|
||||
set -g status-left ""
|
||||
set -g status-right "#[fg=green]#H"
|
||||
|
||||
# Rather than constraining window size to the maximum size of any client
|
||||
# connected to the *session*, constrain window size to the maximum size of any
|
||||
# client connected to *that window*. Much more reasonable.
|
||||
setw -g aggressive-resize on
|
||||
|
||||
# Allows us to use C-a a <command> to send commands to a TMUX session inside
|
||||
# another TMUX session
|
||||
bind-key a send-prefix
|
||||
|
||||
# Activity monitoring
|
||||
setw -g monitor-activity on
|
||||
#set -g visual-activity on
|
||||
|
||||
# # Refresh the status bar every 30 seconds. Try to keep the nzb folder to a reasonable number
|
||||
set-option -g status-interval 1
|
||||
|
||||
# Example of using a shell command in the status line
|
||||
#set -g status-right "#[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
#set -g status-right "#[fg=red]#(ls -1 changeme | wc -l) NZB's left to process #[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
#set -g status-right "#[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Used: \"$3\" MB\";}') #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Free: \"$4\" MB\";}') \
|
||||
#[fg=yellow]#(free -m | grep 'Swap' | awk '{ print \"Swap Used: \"$3\" MB\";}') #[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
|
||||
set -g status-right "#[fg=yellow]#(free -m | grep '+' | awk '{ print \"Ram Used: \"$3\" MB, Ram Free: \"$4\" MB\";}')#(free -m | grep 'Swap' | awk '{ print \",Swap Used: \"$3\" MB\";}') #[fg=cyan,bold]%m-%d-%Y #(uptime)"
|
||||
|
||||
set-option -g status-right-length 200
|
||||
#set -g status-right '#[fg=green][#[fg=blue]%Y-%m-%d #[fg=white]%H:%M#[default] #($HOME/bin/battery)#[fg=green]]'
|
||||
|
||||
# Highlight active window
|
||||
set-window-option -g window-status-current-bg red
|
||||
|
||||
#reduce memory and scrollback buffer
|
||||
set -g history-limit 1000
|
||||
|
||||
#mouse - allows selct pane and resize with mouse
|
||||
set -g mode-mouse on
|
||||
set -g mouse-resize-pane on
|
||||
set -g mouse-select-pane on
|
||||
set -g mouse-select-window on
|
||||
|
||||
set -g set-remain-on-exit on
|
||||
|
||||
bind m \
|
||||
set -g mode-mouse on \;\
|
||||
set -g mouse-resize-pane on \;\
|
||||
set -g mouse-select-pane on \;\
|
||||
set -g mouse-select-window on \;\
|
||||
display 'Mouse: ON'
|
||||
|
||||
bind M \
|
||||
set -g mode-mouse off \;\
|
||||
set -g mouse-resize-pane off \;\
|
||||
set -g mouse-select-pane off \;\
|
||||
set -g mouse-select-window off \;\
|
||||
display 'Mouse: OFF'
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
// This script can dump all tables or just binaries/parts/partrepair/groups.
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
$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"
|
||||
. "**Two Tables (binaries, parts)\n"
|
||||
. "php $argv[0] test dump /path/to/save/to ...: To dump binaries, parts tables.\n"
|
||||
. "php $argv[0] test restore /path/to/restore/from ...: To restore binaries, 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,197 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
// Function inspired by : http://stackoverflow.com/questions/1883079/best-practice-import-mysql-file-in-php-split-queries/2011454#2011454
|
||||
function SplitSQL($file, $delimiter = ';')
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
if (is_file($file) === true) {
|
||||
$file = fopen($file, 'r');
|
||||
|
||||
if (is_resource($file) === true) {
|
||||
$query = array();
|
||||
$db = new Settings();
|
||||
$dbsys = DB_TYPE;
|
||||
$c = new ColorCLI();
|
||||
|
||||
while (feof($file) === false) {
|
||||
$query[] = fgets($file);
|
||||
if (preg_match('~' . preg_quote($delimiter, '~') . '\s*$~iS', end($query)) === 1) {
|
||||
$query = trim(implode('', $query));
|
||||
|
||||
if ($dbsys == "pgsql") {
|
||||
$query = str_replace(array("`", chr(96)), '', $query);
|
||||
}
|
||||
try {
|
||||
$qry = $db->prepare($query);
|
||||
$qry->execute();
|
||||
echo $c->alternateOver('SUCCESS: ') . $c->primary($query);
|
||||
} catch (PDOException $e) {
|
||||
if ($e->errorInfo[1] == 1091 || $e->errorInfo[1] == 1060 || $e->errorInfo[1] == 1054 || $e->errorInfo[1] == 1061 || $e->errorInfo[1] == 1062 || $e->errorInfo[1] == 1071 || $e->errorInfo[1] == 1072 || $e->errorInfo[1] == 1146 || $e->errorInfo[0] == 23505 || $e->errorInfo[0] == 42701 || $e->errorInfo[0] == 42703 || $e->errorInfo[0] == '42P07' || $e->errorInfo[0] == '42P16') {
|
||||
if ($e->errorInfo[1] == 1060) {
|
||||
echo $c->error($query . " The column already exists - Not Fatal {" . $e->errorInfo[1] . "}.\n");
|
||||
} else {
|
||||
echo $c->error($query . " Skipped - Not Fatal {" . $e->errorInfo[1] . "}.\n");
|
||||
}
|
||||
} else {
|
||||
if (preg_match('/ALTER IGNORE/i', $query)) {
|
||||
$db->queryExec("SET SESSION old_alter_table = 1");
|
||||
try {
|
||||
$qry = $db->prepare($query);
|
||||
$qry->execute();
|
||||
echo $c->alternateOver('SUCCESS: ') . $c->primary($query);
|
||||
} catch (PDOException $e) {
|
||||
exit($c->error($query . " Failed {" . $e->errorInfo[1] . "}\n\t" . $e->errorInfo[2]));
|
||||
}
|
||||
} else {
|
||||
exit($c->error($query . " Failed {" . $e->errorInfo[1] . "}\n\t" . $e->errorInfo[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
if (is_string($query) === true) {
|
||||
$query = array();
|
||||
}
|
||||
}
|
||||
return fclose($file);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function BackupDatabase()
|
||||
{
|
||||
$db = new Settings();
|
||||
$c = new ColorCLI();
|
||||
$DIR = dirname (__FILE__);
|
||||
|
||||
if (Utility::hasCommand("php5")) {
|
||||
$PHP = "php5";
|
||||
} else {
|
||||
$PHP = "php";
|
||||
}
|
||||
|
||||
//Backup based on database system
|
||||
if ($db->dbSystem() == "mysql") {
|
||||
system("$PHP ${DIR}mysqldump_tables.php db dump ../../");
|
||||
} else if ($db->dbSystem() == "pgsql") {
|
||||
exit($c->error("Currently not supported on this platform."));
|
||||
}
|
||||
}
|
||||
|
||||
$os = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? "windows" : "unix";
|
||||
|
||||
if (isset($argv[1]) && $argv[1] == "safe") {
|
||||
$safeupgrade = true;
|
||||
} else {
|
||||
$safeupgrade = false;
|
||||
}
|
||||
|
||||
if (isset($os) && $os == "unix") {
|
||||
$t = new Tmux();
|
||||
$tmux = $t->get();
|
||||
$currentversion = $tmux->sqlpatch;
|
||||
$patched = 0;
|
||||
$patches = array();
|
||||
$db = new Settings();
|
||||
$backedup = false;
|
||||
$c = new ColorCLI();
|
||||
$DIR = dirname (__FILE__);
|
||||
$path = $DIR.'/patches/';
|
||||
|
||||
|
||||
// Open the patch folder.
|
||||
if ($handle = @opendir($path)) {
|
||||
while (false !== ($patch = readdir($handle))) {
|
||||
$patches[] = $patch;
|
||||
}
|
||||
closedir($handle);
|
||||
} else {
|
||||
exit($c->error("\nHave you changed the path to the patches folder, or do you have the right permissions?\n"));
|
||||
}
|
||||
|
||||
/* if ($db->dbSystem() == "mysql")
|
||||
$patchpath = preg_replace('/\/misc\/testing\/DB/i', '/db/patches/mysql/',
|
||||
NN_ROOT);
|
||||
else if ($db->dbSystem() == "pgsql")
|
||||
$patchpath = preg_replace('/\/misc\/testing\/DB/i', '/db/patches/pgsql/', nZEDb_ROOT);
|
||||
*/ sort($patches);
|
||||
|
||||
foreach ($patches as $patch) {
|
||||
if (preg_match('/\.sql$/i', $patch)) {
|
||||
$filepath = $path . $patch;
|
||||
$file = fopen($filepath, "r");
|
||||
$patch = fread($file, filesize($filepath));
|
||||
if (preg_match('/UPDATE `?tmux`? SET `?value`? = \'?(\d{1,})\'? WHERE `?setting`? = \'sqlpatch\'/i', $patch, $patchnumber)) {
|
||||
if ($patchnumber['1'] > $currentversion) {
|
||||
if ($safeupgrade == true && $backedup == false) {
|
||||
BackupDatabase();
|
||||
$backedup = true;
|
||||
}
|
||||
SplitSQL($filepath);
|
||||
$patched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isset($os) && $os == "windows") {
|
||||
$t = new Tmux();
|
||||
$tmux = $t->get();
|
||||
$currentversion = $tmux->sqlpatch;
|
||||
$patched = 0;
|
||||
$patches = array();
|
||||
|
||||
// Open the patch folder.
|
||||
if (!isset($argv[1])) {
|
||||
exit($c->error("\nYou must supply the directory to the patches.\n"));
|
||||
}
|
||||
if ($handle = @opendir($argv[1])) {
|
||||
while (false !== ($patch = readdir($handle))) {
|
||||
$patches[] = $patch;
|
||||
}
|
||||
closedir($handle);
|
||||
} else {
|
||||
exit($c->error("\nHave you changed the path to the patches folder, or do you have the right permissions?\n"));
|
||||
}
|
||||
|
||||
sort($patches);
|
||||
foreach ($patches as $patch) {
|
||||
if (preg_match('/\.sql$/i', $patch)) {
|
||||
$filepath = $argv[1] . $patch;
|
||||
$file = fopen($filepath, "r");
|
||||
$patch = fread($file, filesize($filepath));
|
||||
if (preg_match('/UPDATE `?tmux`? SET `?value`? = \'?(\d{1,})\'? WHERE `?setting`? = \'sqlpatch\'/i', $patch, $patchnumber)) {
|
||||
if ($patchnumber['1'] > $currentversion) {
|
||||
if ($safeupgrade == true && $backedup == false) {
|
||||
BackupDatabase();
|
||||
$backedup = true;
|
||||
}
|
||||
SplitSQL($filepath);
|
||||
$patched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exit($c->error("\nUnable to determine OS.\n"));
|
||||
}
|
||||
|
||||
if ($patched == 0) {
|
||||
exit($c->info("After patch 149 this file is no longer used.Nothing to patch, you are already on patch version " . $currentversion));
|
||||
}
|
||||
if ($patched > 0) {
|
||||
echo $c->header($patched . " patch(es) applied. After patch 149 this file is no longer used");
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
ALTER TABLE site
|
||||
ADD section VARCHAR(25) NOT NULL DEFAULT '',
|
||||
ADD subsection VARCHAR(25) NOT NULL DEFAULT '',
|
||||
ADD name VARCHAR(25) NOT NULL DEFAULT '',
|
||||
ADD hint TEXT NOT NULL;
|
||||
ALTER TABLE site DROP COLUMN id;
|
||||
ALTER TABLE site DROP INDEX setting;
|
||||
UPDATE site SET name = setting;
|
||||
ALTER TABLE site
|
||||
ADD PRIMARY KEY (section, subsection, name),
|
||||
ADD UNIQUE INDEX ui_settings_setting (setting);
|
||||
RENAME TABLE site TO settings;
|
||||
INSERT IGNORE INTO settings (name, setting, value) VALUES('sqlpatch', 'sqlpatch', 149);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/settings.php
|
||||
@@ -0,0 +1,9 @@
|
||||
These scripts run IRC bots to get PRE information.
|
||||
|
||||
You must first copy settings_example.php to settings.php and change the settings in the file (settings.php).
|
||||
|
||||
Next you can run scrape.php, it will tell you all the options.
|
||||
|
||||
scrape.sh runs the bots with text output, if you cancel the script, one of the bots will still run, you must kill it manually.
|
||||
|
||||
scrape_daemon.sh runs the bots with no text output and lets go of the terminal lock (if you want to restart the script later, you MUST kill the bots first).
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../bin/config.php");
|
||||
|
||||
if (!is_file(NN_TMUX . 'lib' . DS . 'IRCScraper' .DS . 'settings.php')) {
|
||||
exit('Copy settings_example.php to settings.php and change the settings.' . PHP_EOL);
|
||||
}
|
||||
|
||||
if (!isset($argv[1]) || $argv[1] !== 'true') {
|
||||
exit(
|
||||
'Argument 1: false|true ; false prints this help screen, true runs the scraper.' . PHP_EOL .
|
||||
'Argument 2: (optional) false|true ; true runs in silent mode (no text output)' . PHP_EOL .
|
||||
'Argument 3: (optional) false|true ; true turns on debug (shows sent/received messages from the socket)' . PHP_EOL .
|
||||
'examples:' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true ; Scrapes PRE with text output.' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true true > /dev/null 2>&1 ; (unix) Scrapes PRE with no text output, in the background (you can close your terminal window).' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true false true ; Scrapes PRE with text output and debug output.' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true true true ; Scrapes PRE with debug but no text output.' . PHP_EOL
|
||||
);
|
||||
}
|
||||
|
||||
require_once (NN_TMUX . 'lib' . DS . 'IRCScraper' .DS . 'settings.php');
|
||||
|
||||
if (!defined('SCRAPE_IRC_NICKNAME')) {
|
||||
exit('ERROR! You must update settings.php using settings_example.php.');
|
||||
}
|
||||
|
||||
if (SCRAPE_IRC_NICKNAME == '') {
|
||||
exit("ERROR! You must put a username in settings.php" . PHP_EOL);
|
||||
}
|
||||
|
||||
$silent = ((isset($argv[2]) && $argv[2] === 'true') ? true : false);
|
||||
$debug = ((isset($argv[3]) && $argv[3] === 'true') ? true : false);
|
||||
|
||||
// Start scraping.
|
||||
new IRCScraper($silent, $debug);
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
cmd1="/usr/bin/php scrape.php corrupt";
|
||||
cmd2="/usr/bin/php scrape.php efnet";
|
||||
|
||||
# Kill corrupt if it's already open.
|
||||
`ps -ef | grep "php corrupt" | awk '{print $2}' | xargs kill`
|
||||
sleep 2
|
||||
|
||||
# Run corrupt in the background.
|
||||
$cmd1 &
|
||||
sleep 3
|
||||
echo ""
|
||||
echo "This started scrapeCorrupt in the background, if you cancel this script, it will still run, so you must kill it manually."
|
||||
echo "scrapeEfnet, will close however, since it was not started in the background."
|
||||
echo ""
|
||||
echo `ps aux | grep 'php corrupt' | awk '{print $2}'`
|
||||
echo "To kill it, in the message above, you see a number, in a command line, type kill theNumber (theNumber, is the number over this line, the one to the left)"
|
||||
echo ""
|
||||
sleep 3
|
||||
$cmd2
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This runs IRCScraper silently in the background.
|
||||
|
||||
cmd1="/usr/bin/php scrape.php corrupt true";
|
||||
cmd2="/usr/bin/php scrape.php efnet true";
|
||||
|
||||
echo "Started IRCScraping in daemon mode."
|
||||
|
||||
# Kill corrupt if it's already open.
|
||||
`ps -ef | grep "php corrupt" | awk '{print $2}' | xargs kill`
|
||||
sleep 2
|
||||
# Kill efnet if it's already open.
|
||||
`ps -ef | grep "php efnet" | awk '{print $2}' | xargs kill`
|
||||
sleep 2
|
||||
|
||||
# Run corrupt
|
||||
$cmd1 &
|
||||
sleep 3
|
||||
# Run efnet
|
||||
$cmd2 &
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// If lazy set all usernames/nicknames/names here.
|
||||
// MAKE SURE THIS IS UNIQUE, IF SOMEONE HAS THE USERNAME ALREADY YOU WILL GET A BUNCH OF ERRORS, YOU HAVE BEEN WARNED.
|
||||
$username = '';
|
||||
|
||||
// https://www.synirc.net/servers Try another server if you have issues.
|
||||
define('SCRAPE_IRC_SERVER', 'irc.synirc.net');
|
||||
// Use Port 6697 or 7001 and set SCRAPE_IRC_TLS to true for encryption.
|
||||
define('SCRAPE_IRC_PORT', '6667');
|
||||
define('SCRAPE_IRC_TLS', false);
|
||||
define('SCRAPE_IRC_NICKNAME', "$username");
|
||||
define('SCRAPE_IRC_REALNAME', "$username");
|
||||
define('SCRAPE_IRC_USERNAME', "$username");
|
||||
// Set to false if you need no password. Use a string (quoted text) if you need a password.
|
||||
define('SCRAPE_IRC_PASSWORD', false);
|
||||
// Regex to ignore categories. Leave empty ('') to not exclude any category.
|
||||
// Case sensitive example: '/^(XXX|PDA|EBOOK|MP3)$/'
|
||||
// Case insensitive (note the i): '/^(X264|TV)$/i'
|
||||
define('SCRAPE_IRC_CATEGORY_IGNORE', '');
|
||||
// Set to true to ignore a source.
|
||||
define('SCRAPE_IRC_SOURCE_IGNORE',
|
||||
serialize(
|
||||
array(
|
||||
'#a.b.cd.image' => false,
|
||||
'#a.b.console.ps3' => false,
|
||||
'#a.b.dvd' => false,
|
||||
'#a.b.erotica' => false,
|
||||
'#a.b.flac' => false,
|
||||
'#a.b.foreign' => false,
|
||||
'#a.b.games.nintendods' => false,
|
||||
'#a.b.inner-sanctum' => false,
|
||||
'#a.b.moovee' => false,
|
||||
'#a.b.movies.divx' => false,
|
||||
'#a.b.sony.psp' => false,
|
||||
'#a.b.sounds.mp3.complete_cd' => false,
|
||||
'#a.b.teevee' => false,
|
||||
'#a.b.games.wii' => false,
|
||||
'#a.b.warez' => false,
|
||||
'#a.b.games.xbox360' => false,
|
||||
'#pre@corrupt' => false,
|
||||
'#scnzb' => false,
|
||||
'#tvnzb' => false,
|
||||
'omgwtfnzbs' => false,
|
||||
'orlydb' => false,
|
||||
'prelist' => false,
|
||||
'srrdb' => false,
|
||||
'u4all.eu' => false,
|
||||
'zenet' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
if (!isset($argv[1]) || ($argv[1] != "all" && $argv[1] != "full" && !is_numeric($argv[1]))) {
|
||||
exit($pdo->log->error(
|
||||
"\nThis script tries to match hashes of the releases.name or releases.searchname to predb hashes.\n"
|
||||
. "To display the changes, use 'show' as the second argument.\n\n"
|
||||
. "php decrypt_hashes.php 1000 ...: to limit to 1000 sorted by newest postdate.\n"
|
||||
. "php decrypt_hashes.php full ...: to run on full database.\n"
|
||||
. "php decrypt_hashes.php all ...: to run on all hashed releases(including previously renamed).\n"
|
||||
));
|
||||
}
|
||||
|
||||
echo $pdo->log->header("\nDecrypt Hashes (${argv[1]}) Started at " . date('g:i:s'));
|
||||
echo $pdo->log->primary("Matching predb hashes to hash(releases.name or releases.searchname)");
|
||||
|
||||
getPreName($argv);
|
||||
|
||||
function getPreName($argv)
|
||||
{
|
||||
global $pdo;
|
||||
$timestart = time();
|
||||
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
$namefixer = new \NameFixer(['Settings' => $pdo, 'ConsoleTools' => $consoletools]);
|
||||
|
||||
$res = false;
|
||||
if (isset($argv[1]) && $argv[1] === "all") {
|
||||
$res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, groupid, categoryid, dehashstatus FROM releases WHERE prehashid = 0 AND ishashed = 1');
|
||||
} else if (isset($argv[1]) && $argv[1] === "full") {
|
||||
$res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, groupid, categoryid, dehashstatus FROM releases WHERE categoryid = 8020 AND dehashstatus BETWEEN -6 AND 0');
|
||||
} else if (isset($argv[1]) && is_numeric($argv[1])) {
|
||||
$res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, groupid, categoryid, dehashstatus FROM releases WHERE categoryid = 8020 AND dehashstatus BETWEEN -6 AND 0 ORDER BY postdate DESC LIMIT ' . $argv[1]);
|
||||
}
|
||||
|
||||
$counter = $counted = $total = 0;
|
||||
if ($res !== false) {
|
||||
$total = $res->rowCount();
|
||||
}
|
||||
$show = (!isset($argv[2]) || $argv[2] !== 'show') ? 0 : 1;
|
||||
if ($total > 0) {
|
||||
echo $pdo->log->header("\n" . number_format($total) . ' releases to process.');
|
||||
sleep(2);
|
||||
|
||||
foreach ($res as $row) {
|
||||
$success = 0;
|
||||
if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['name'], $matches)) {
|
||||
$success = $namefixer->matchPredbHash($matches[0], $row, 1, 1, true, $show);
|
||||
} else if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['searchname'], $matches)) {
|
||||
$success = $namefixer->matchPredbHash($matches[0], $row, 1, 1, true, $show);
|
||||
}
|
||||
|
||||
if ($success === 0) {
|
||||
$pdo->queryDirect(sprintf('UPDATE releases SET dehashstatus = dehashstatus - 1 WHERE id = %d', $row['releaseid']));
|
||||
} else {
|
||||
$counted++;
|
||||
}
|
||||
if ($show === 0) {
|
||||
$consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $consoletools->percentString(++$counter, $total));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($total > 0) {
|
||||
echo $pdo->log->header("\nRenamed " . $counted . " releases in " . $consoletools->convertTime(TIME() - $timestart) . ".");
|
||||
} else {
|
||||
echo $pdo->log->info("\nNothing to do.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This script attemps to clean release names using the NFO, file name and release name, Par2 file.
|
||||
* A good way to use this script is to use it in this order: php fixReleaseNames.php 3 true other yes
|
||||
* php fixReleaseNames.php 5 true other yes
|
||||
* If you used the 4th argument yes, but you want to reset the status,
|
||||
* there is another script called resetRelnameStatus.php
|
||||
*/
|
||||
require_once(dirname(__FILE__) . "/../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
$n = "\n";
|
||||
$pdo = new Settings();
|
||||
$namefixer = new \NameFixer(['Settings' => $pdo]);
|
||||
$predb = new \PreHash(['Echo' => true, 'Settings' => $pdo]);
|
||||
$s = new Sites();
|
||||
$site = $s->get();
|
||||
|
||||
if (isset($argv[1]) && isset($argv[2]) && isset($argv[3]) && isset($argv[4])) {
|
||||
$update = ($argv[2] == "true") ? 1 : 2;
|
||||
$other = 1;
|
||||
if ($argv[3] === 'all') {
|
||||
$other = 2;
|
||||
} else if ($argv[3] === 'preid') {
|
||||
$other = 3;
|
||||
}
|
||||
$setStatus = ($argv[4] == "yes") ? 1 : 2;
|
||||
|
||||
$show = 2;
|
||||
if (isset($argv[5]) && $argv[5] === 'show') {
|
||||
$show = 1;
|
||||
}
|
||||
|
||||
$nntp = null;
|
||||
if ($argv[1] == 7 || $argv[1] == 8) {
|
||||
$nntp = new \NNTP(['Settings' => $pdo]);
|
||||
if (($site->alternate_nntp == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) {
|
||||
echo $pdo->log->error("Unable to connect to usenet.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($argv[1]) {
|
||||
case 1:
|
||||
$predb->parseTitles(1, $update, $other, $setStatus, $show);
|
||||
break;
|
||||
case 2:
|
||||
$predb->parseTitles(2, $update, $other, $setStatus, $show);
|
||||
break;
|
||||
case 3:
|
||||
$namefixer->fixNamesWithNfo(1, $update, $other, $setStatus, $show);
|
||||
break;
|
||||
case 4:
|
||||
$namefixer->fixNamesWithNfo(2, $update, $other, $setStatus, $show);
|
||||
break;
|
||||
case 5:
|
||||
$namefixer->fixNamesWithFiles(1, $update, $other, $setStatus, $show);
|
||||
break;
|
||||
case 6:
|
||||
$namefixer->fixNamesWithFiles(2, $update, $other, $setStatus, $show);
|
||||
break;
|
||||
case 7:
|
||||
$namefixer->fixNamesWithPar2(1, $update, $other, $setStatus, $show, $nntp);
|
||||
break;
|
||||
case 8:
|
||||
$namefixer->fixNamesWithPar2(2, $update, $other, $setStatus, $show, $nntp);
|
||||
break;
|
||||
default :
|
||||
exit($pdo->log->error("\nERROR: Wrong argument, type php $argv[0] to see a list of valid arguments." . $n));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
exit($pdo->log->error("\nYou must supply 4 arguments.\n"
|
||||
. "The 2nd argument, false, will display the results, but not change the name, type true to have the names changed.\n"
|
||||
. "The 3rd argument, other, will only do against other categories, to do against all categories use all, or preid to process all not matched to predb.\n"
|
||||
. "The 4th argument, yes, will set the release as checked, so the next time you run it will not be processed, to not set as checked type no.\n"
|
||||
. "The 5th argument (optional), show, wiil display the release changes or only show a counter.\n\n"
|
||||
. "php $argv[0] 1 false other no ...: Fix release names using the usenet subject in the past 3 hours with predb information.\n"
|
||||
. "php $argv[0] 2 false other no ...: Fix release names using the usenet subject with predb information.\n"
|
||||
. "php $argv[0] 3 false other no ...: Fix release names using NFO in the past 6 hours.\n"
|
||||
. "php $argv[0] 4 false other no ...: Fix release names using NFO.\n"
|
||||
. "php $argv[0] 5 false other no ...: Fix release names in misc categories using File Name in the past 6 hours.\n"
|
||||
. "php $argv[0] 6 false other no ...: Fix release names in misc categories using File Name.\n"
|
||||
. "php $argv[0] 7 false other no ...: Fix release names in misc categories using Par2 Files in the past 6 hours.\n"
|
||||
. "php $argv[0] 8 false other no ...: Fix release names in misc categories using Par2 Files.\n"));
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../bin/config.php");
|
||||
|
||||
(new \PreHash(['Echo' => true]))->checkPre((isset($argv[1]) && is_numeric($argv[1]) ? $argv[1] : false));
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// This script is adapted FROM nZEDb
|
||||
/*
|
||||
* This script deletes releases that match certain criteria, type php removeCrapReleases.php false for details.
|
||||
*/
|
||||
require_once(dirname(__FILE__) . "/../bin/config.php");
|
||||
|
||||
$cli = new \ColorCLI();
|
||||
$n = PHP_EOL;
|
||||
|
||||
$argCnt = count($argv);
|
||||
if ($argCnt === 1) {
|
||||
exit(
|
||||
$cli->error(
|
||||
$n .
|
||||
'Run fixReleaseNames.php first to attempt to fix release names.'. $n .
|
||||
'This will miss some releases if you have not set fixReleaseNames to set the release as checked.' . $n . $n .
|
||||
"php $argv[0] false Display full usage of this script." . $n .
|
||||
"php $argv[0] true full Run this script with all options."
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($argCnt === 2) {
|
||||
if ($argv[1] === 'false') {
|
||||
exit(
|
||||
"php $argv[0] arg1 arg2 arg3 arg4" . $n . $n .
|
||||
'arg1 (Required) = true/false' . $n .
|
||||
' true = Run this script and delete releases.' . $n .
|
||||
' false = Run this script and show what could be deleted.' . $n . $n .
|
||||
'arg2 (Required) = full/number' . $n .
|
||||
' full = Run without a time limit.' . $n .
|
||||
' number = Run on releases up to this old.' . $n . $n .
|
||||
'arg3 (Optional) = blacklist | blfiles | executable | gibberish | hashed | installbin | passworded | passwordurl | sample | scr | short | size | wmv' . $n .
|
||||
' blacklist = Remove releases using the enabled blacklists in admin section of site.' . $n .
|
||||
' blfiles = Remove releases using the enabled blacklists in admin section of site against filenames.' . $n .
|
||||
' executable = Remove releases containing an exe file.' . $n .
|
||||
' gibberish = Remove releases where the name is letters/numbers only and 15 characters or longer.' . $n .
|
||||
' hashed = Remove releases where the name is letters/numbers only and 25 characters or longer.' . $n .
|
||||
' installbin = Remove releases which contain an install.bin file.' . $n .
|
||||
' passworded = Remove releases which contain the word password in the title.' . $n .
|
||||
' passwordurl = Remove releases which contain a password.url file.' . $n .
|
||||
' sample = Remove releases that are smaller than 40MB more than 1 file and have sample in the title' . $n .
|
||||
' scr = Remove releases where .scr extension is found in the files or subject.' . $n .
|
||||
' short = Remove releases where the name is only numbers or letters and is 5 characters or less.' . $n .
|
||||
' codec = Remove releases where the release contains WMV file, x264 name, and Codec\Setup.exe file (Spammer).' . $n .
|
||||
' size = Remove releases smaller than 2MB and have only 1 file and not in books or mp3 section.' . $n .
|
||||
' huge = Remove releases bigger than 200MB with just a single file.' . $n . $n .
|
||||
'arg4 (Optional) = blacklist regular expression id number. Only works when blacklist is selected as third argument.' . $n .
|
||||
' 100001 = Remove releases where the Binary Blacklist id is 100001.' . $n . $n .
|
||||
'examples:' . $n .
|
||||
"php $argv[0] true 12 blacklist = Remove releases up to 12 hours old using site blacklists." . $n .
|
||||
"php $argv[0] false full = Show what releases could have been removed." . $n .
|
||||
"php $argv[0] true full installbin = Remove releases which containing an install.bin file." . $n .
|
||||
"php $argv[0] true full blacklist 1 = Remove releases matching blacklist id 1." . $n
|
||||
);
|
||||
} else {
|
||||
exit ($cli->error("Wrong usage! Type php $argv[0] false"));
|
||||
}
|
||||
}
|
||||
if ($argCnt < 3) {
|
||||
exit ($cli->error("Wrong usage! Type php $argv[0] false"));
|
||||
}
|
||||
|
||||
if (isset($argv[3]) && $argv[3] === 'blacklist' && isset($argv[4])) {
|
||||
$blacklistID = $argv[4];
|
||||
}
|
||||
|
||||
$RR = new \ReleaseRemover();
|
||||
$RR->removeCrap(($argv[1] === 'true' ? true : false), $argv[2], (isset($argv[3]) ? $argv[3] : ''), (isset($blacklistID) ? $argv[4] : ''));
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../bin/config.php");
|
||||
|
||||
$cli = new \ColorCLI();
|
||||
|
||||
if (!isset($argv[1]) || ($argv[1] != "all" && $argv[1] != "full" && $argv[1] != "web" && !is_numeric($argv[1])) || !isset($argv[2]) || !in_array($argv[2], ['true', 'false'])) {
|
||||
exit ($cli->error(
|
||||
PHP_EOL
|
||||
. "This script tries to match a release request id by group to a PreDB request id by group doing local lookup only." . PHP_EOL
|
||||
. "In addition an optional final argument is time, in minutes, to check releases that have previously been checked." . PHP_EOL . PHP_EOL
|
||||
. "Argument 1: full|all|number|web => (mandatory)" . PHP_EOL
|
||||
. "all does only requestid releases, full does full database, number limits to x amount of releases, web does web requestid's" . PHP_EOL
|
||||
. "Argument 2: true|false => (mandatory) Display full info on how the release was renamed or not." . PHP_EOL
|
||||
. "Argument 3: number => (optional) This is to limit how old the releases to work on (in hours)." . PHP_EOL
|
||||
. "php requestid.php 1000 true => to limit to 1000 sorted by newest postdate and show renaming." . PHP_EOL . PHP_EOL
|
||||
. "php requestid.php full true => to run on full database and show renaming." . PHP_EOL
|
||||
. "php requestid.php all true => to run on all requestid releases (including previously renamed) and show renaming." . PHP_EOL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($argv[1] === 'web') {
|
||||
(new \RequestIDWeb())->lookupRequestIDs(
|
||||
['limit' => 1000, 'show' => $argv[2], 'time' => (isset($argv[3]) && is_numeric($argv[3]) && $argv[3] > 0 ? $argv[3] : 0)]
|
||||
);
|
||||
} else {
|
||||
(new \RequestIDLocal())->lookupRequestIDs(
|
||||
['limit' => $argv[1], 'show' => $argv[2], 'time' => (isset($argv[3]) && is_numeric($argv[3]) && $argv[3] > 0 ? $argv[3] : 0)]
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
/* 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 Settings();
|
||||
|
||||
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\Settings;
|
||||
|
||||
$cli = new \ColorCLI();
|
||||
|
||||
$pdo = new Settings(['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,173 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
$debug = false;
|
||||
$pdo = new Settings();
|
||||
$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 collections/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 c/b/p to tpg leaving current collections/binaries/parts tables in-tact.\n"
|
||||
. "php $argv[0] true delete ...: Convert c/b/p to tpg and TRUNCATE current collections/binaries/parts tables.\n"
|
||||
));
|
||||
}
|
||||
|
||||
$clen = $pdo->queryOneRow('SELECT COUNT(*) AS total FROM collections;');
|
||||
$cdone = 0;
|
||||
$ccount = 1;
|
||||
$gdone = 1;
|
||||
$actgroups = $groups->getActive();
|
||||
$glen = count($actgroups);
|
||||
$newtables = $glen * 3;
|
||||
$begintime = time();
|
||||
|
||||
echo "Creating new collections, 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 ($cdone < $clen['total']) {
|
||||
// Only load 1000 collections per loop to not overload memory.
|
||||
$collections = $pdo->queryAssoc('select * from collections limit ' . $cdone . ',1000;');
|
||||
|
||||
if ($collections instanceof \Traversable) {
|
||||
foreach ($collections as $collection) {
|
||||
$collection['subject'] = $pdo->escapeString($collection['subject']);
|
||||
$collection['fromname'] = $pdo->escapeString($collection['fromname']);
|
||||
$collection['date'] = $pdo->escapeString($collection['date']);
|
||||
$collection['collectionhash'] = $pdo->escapeString($collection['collectionhash']);
|
||||
$collection['dateadded'] = $pdo->escapeString($collection['dateadded']);
|
||||
$collection['xref'] = $pdo->escapeString($collection['xref']);
|
||||
$collection['releaseid'] = $pdo->escapeString($collection['releaseid']);
|
||||
$oldcid = array_shift($collection);
|
||||
if ($debug) {
|
||||
echo "\n\nCollection insert:\n";
|
||||
print_r($collection);
|
||||
echo sprintf("\nINSERT INTO collections_%d (subject, fromname, date, xref, totalfiles, group_id, collectionhash, dateadded, filecheck, filesize, releaseid) VALUES (%s)\n\n", $collection['group_id'], implode(', ', $collection));
|
||||
}
|
||||
$newcid = array('collection_id' => $pdo->queryInsert(sprintf('INSERT INTO collections_%d (subject, fromname, date, xref, totalfiles, group_id, collectionhash, dateadded, filecheck, filesize, releaseid) VALUES (%s);', $collection['group_id'], implode(', ', $collection))));
|
||||
$consoletools->overWrite('Collections Completed: ' . $consoletools->percentString($ccount, $clen['total']));
|
||||
|
||||
//Get binaries and split to correct group tables.
|
||||
$binaries = $pdo->queryAssoc('SELECT * FROM binaries WHERE collection_id = ' . $oldcid . ';');
|
||||
|
||||
if ($binaries instanceof \Traversable) {
|
||||
foreach ($binaries as $binary) {
|
||||
$binary['name'] = $pdo->escapeString($binary['name']);
|
||||
$binary['binaryhash'] = $pdo->escapeString($binary['binaryhash']);
|
||||
$oldbid = array_shift($binary);
|
||||
$binarynew = array_replace($binary, $newcid);
|
||||
if ($debug) {
|
||||
echo "\n\nBinary insert:\n";
|
||||
print_r($binarynew);
|
||||
echo sprintf("\nINSERT INTO binaries_%d (name, collection_id, filenumber, totalparts, currentparts, binaryhash, partcheck, partsize) VALUES (%s)\n\n", $collection['group_id'], implode(', ', $binarynew));
|
||||
}
|
||||
$newbid = array('binaryid' => $pdo->queryInsert(sprintf('INSERT INTO binaries_%d (name, collection_id, filenumber, totalparts, currentparts, binaryhash, partcheck, partsize) VALUES (%s);', $collection['group_id'], 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, collection_id) VALUES %s;\n\n", $collection['group_id'], $partsnew);
|
||||
}
|
||||
$sql = sprintf('INSERT INTO parts_%d (binaryid, messageid, number, partnumber, size, collection_id) VALUES %s;', $collection['group_id'], $partsnew);
|
||||
$pdo->queryExec($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
$ccount++;
|
||||
}
|
||||
}
|
||||
$cdone += 1000;
|
||||
}
|
||||
|
||||
if ($DoPartRepair === true) {
|
||||
foreach ($actgroups as $group) {
|
||||
$pcount = 1;
|
||||
$pdone = 0;
|
||||
$sql = sprintf('SELECT COUNT(*) AS total FROM partrepair where group_id = %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 group_id = %d limit %d, 10000;', $group['id'], $pdone));
|
||||
if ($partrepairs instanceof \Traversable) {
|
||||
foreach ($partrepairs as $partrepair) {
|
||||
$partrepair['numberid'] = $pdo->escapeString($partrepair['numberid']);
|
||||
$partrepair['group_id'] = $pdo->escapeString($partrepair['group_id']);
|
||||
$partrepair['attempts'] = $pdo->escapeString($partrepair['attempts']);
|
||||
if ($debug) {
|
||||
echo "\n\nPart Repair insert:\n";
|
||||
print_r($partrepair);
|
||||
echo sprintf("\nINSERT INTO partrepair_%d (numberid, group_id, attempts) VALUES (%s, %s, %s)\n\n", $group['id'], $partrepair['numberid'], $partrepair['group_id'], $partrepair['attempts']);
|
||||
}
|
||||
$pdo->queryExec(sprintf('INSERT INTO partrepair_%d (numberid, group_id, attempts) VALUES (%s, %s, %s);', $group['id'], $partrepair['numberid'], $partrepair['group_id'], $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 collections;');
|
||||
$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\Settings;
|
||||
|
||||
|
||||
|
||||
// This script can dump all tables or just collections/binaries/parts/partrepair/groups.
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
$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\Settings;
|
||||
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 Settings();
|
||||
$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->NZBPath($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\Settings();
|
||||
|
||||
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\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
Utility::clearScreen();
|
||||
$pdo = new Settings();
|
||||
|
||||
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\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
/*
|
||||
*
|
||||
* 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 Settings();
|
||||
|
||||
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,58 @@
|
||||
<?php
|
||||
// --------------------------------------------------------------
|
||||
// Scan for releases missing previews on disk
|
||||
// --------------------------------------------------------------
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
$row = $pdo->queryOneRow("SELECT value FROM site WHERE setting = 'coverspath'");
|
||||
if ($row !== false) {
|
||||
Utility::setCoversConstant($row['value']);
|
||||
} else {
|
||||
die("Unable to determine covers path!\n");
|
||||
}
|
||||
|
||||
$path2preview = NN_COVERS . 'preview' . DS;
|
||||
|
||||
if (isset($argv[1]) && ($argv[1] === "true" || $argv[1] === "check")) {
|
||||
$releases = new Releases(['Settings' => $pdo]);
|
||||
$nzb = new NZB($pdo);
|
||||
$releaseImage = new ReleaseImage($pdo);
|
||||
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
$couldbe = $argv[1] === "true" ? $couldbe = "were " : "could be ";
|
||||
$limit = $counterfixed = 0;
|
||||
if (isset($argv[2]) && is_numeric($argv[2])) {
|
||||
$limit = $argv[2];
|
||||
}
|
||||
echo $pdo->log->header("Scanning for releases missing previews");
|
||||
$res = $pdo->queryDirect("SELECT id, guid FROM releases where nzbstatus = 1 AND haspreview = 1");
|
||||
if ($res instanceof \Traversable) {
|
||||
foreach ($res as $row) {
|
||||
$nzbpath = $path2preview . $row["guid"] . "_thumb.jpg";
|
||||
if (!file_exists($nzbpath)) {
|
||||
$counterfixed++;
|
||||
echo $pdo->log->warning("Missing preview " . $nzbpath);
|
||||
if ($argv[1] === "true") {
|
||||
$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 = %s", $row['id']));
|
||||
}
|
||||
}
|
||||
|
||||
if (($limit > 0) && ($counterfixed >= $limit)) {
|
||||
break;
|
||||
} // QUAD!
|
||||
}
|
||||
}
|
||||
echo $pdo->log->header("Total releases missing previews that " . $couldbe . "reset for reprocessing= " . number_format($counterfixed));
|
||||
} else {
|
||||
exit($pdo->log->header("\nThis script checks if release previews actually exist on disk.\n\n"
|
||||
. "Releases without previews may be reset for post-processing, thus regenerating them and related meta data.\n\n"
|
||||
. "Useful for recovery after filesystem corruption, or as an alternative re-postprocessing tool.\n\n"
|
||||
. "Optional LIMIT parameter restricts number of releases to be reset.\n\n"
|
||||
. "php $argv[0] check [LIMIT] ...: Dry run, displays missing previews.\n"
|
||||
. "php $argv[0] true [LIMIT] ...: Re-process releases missing previews.\n"));
|
||||
}
|
||||
@@ -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\Settings;
|
||||
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
$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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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,54 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
$pdo = new Settings();
|
||||
$covers = $updated = $deleted = 0;
|
||||
|
||||
if ($argc == 1 || $argv[1] != 'true') {
|
||||
exit($pdo->log->error("\nThis script will check all images in covers/games and compare to db->gamesinfo.\nTo run:\nphp $argv[0] true\n"));
|
||||
}
|
||||
|
||||
$row = $pdo->queryOneRow("SELECT value FROM site WHERE setting = 'coverspath'");
|
||||
if ($row !== false) {
|
||||
Utility::setCoversConstant($row['value']);
|
||||
} else {
|
||||
die("Unable to set Covers' constant!\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 $pdo->log->info($filePath . " not found in db.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$qry = $pdo->queryDirect("SELECT id FROM gamesinfo WHERE cover = 1");
|
||||
if ($qry instanceof \Traversable) {
|
||||
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 $pdo->log->info($path2covers . $rows['id'] . ".jpg does not exist.");
|
||||
$deleted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo $pdo->log->header($covers . " covers set.");
|
||||
echo $pdo->log->header($deleted . " games unset.");
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$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));
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?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
|
||||
* @copyright 2014 nZEDb
|
||||
*/
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$s = new Sites();
|
||||
$site = $s->get();
|
||||
|
||||
if (!$site->tablepergroup) {
|
||||
exit("Tables per groups is not enabled, quitting!");
|
||||
}
|
||||
|
||||
// Doing it this way in case there are tables existing not related to the active/backfill list (i.e. I don't have a clue when these tables get deleted so I'm doing any that are there).
|
||||
$tables = $pdo->queryDirect("SELECT SUBSTR(TABLE_NAME, 12) AS suffix FROM information_schema.TABLES WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND TABLE_NAME LIKE 'collections%' ORDER BY TABLE_NAME");
|
||||
|
||||
$query1 = "ALTER table collections%s add noise char(32) not null default '' after releaseid";
|
||||
|
||||
if ($tables instanceof \Traversable) {
|
||||
foreach ($tables as $table) {
|
||||
echo "Updating table collections{$table['suffix']}" . PHP_EOL;
|
||||
$pdo->queryExec(sprintf($query1, $table['suffix']), true);
|
||||
}
|
||||
echo 'All done!' . PHP_EOL;
|
||||
}
|
||||
@@ -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\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
$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\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
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\Settings;
|
||||
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 Settings();
|
||||
|
||||
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\Settings;
|
||||
|
||||
|
||||
$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 Settings();
|
||||
$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;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
*.log
|
||||
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
require_once dirname(__FILE__) . '/../../../../www/config.php';
|
||||
|
||||
use newznab\db\Settings;
|
||||
use newznab\utility\Utility;
|
||||
|
||||
|
||||
$pdo = new Settings();
|
||||
$tRun = new \TmuxRun($pdo);
|
||||
$tOut = new \TmuxOutput($pdo);
|
||||
|
||||
$runVar['paths']['misc'] = NN_MISC;
|
||||
$runVar['paths']['lib'] = NN_LIB;
|
||||
$db_name = DB_NAME;
|
||||
$dbtype = DB_TYPE;
|
||||
$tmux = $tRun->get('niceness');
|
||||
|
||||
$tmux_niceness = (isset($tmux->niceness) ? $tmux->niceness : 2);
|
||||
|
||||
$runVar['constants'] = $pdo->queryOneRow($tRun->getConstantSettings());
|
||||
|
||||
$PHP = ($tRun->command_exist("php5") ? 'php5' : 'php');
|
||||
$PYTHON = ($tRun->command_exist("python3") ? 'python3 -OOu' : 'python -OOu');
|
||||
|
||||
//assign shell commands
|
||||
$show_time = (NN_DEBUG ? "/usr/bin/time" : "");
|
||||
$runVar['commands']['_php'] = $show_time . " nice -n{$tmux_niceness} $PHP";
|
||||
$runVar['commands']['_phpn'] = "nice -n{$tmux_niceness} $PHP";
|
||||
$runVar['commands']['_python'] = $show_time . " nice -n{$tmux_niceness} $PYTHON";
|
||||
$runVar['commands']['_sleep'] = "{$runVar['commands']['_phpn']} {$runVar['paths']['misc']}update_scripts/nix_scripts/tmux/bin/showsleep.php";
|
||||
|
||||
//spawn IRCScraper as soon as possible
|
||||
$tRun->runPane('scraper', $runVar);
|
||||
|
||||
//get list of panes by name
|
||||
$runVar['panes'] = $tRun->getListOfPanes($runVar['constants']);
|
||||
|
||||
//totals per category in db, results by parentid
|
||||
$catcntqry = "SELECT c.parentid AS parentid, COUNT(r.id) AS count FROM category c, releases r WHERE r.categoryid = c.id GROUP BY c.parentid";
|
||||
|
||||
//create timers and set to now
|
||||
$runVar['timers']['timer1'] = $runVar['timers']['timer2'] = $runVar['timers']['timer3'] =
|
||||
$runVar['timers']['timer4'] = $runVar['timers']['timer5'] = time();
|
||||
|
||||
$runVar['timers']['query']['tmux_time'] = $runVar['timers']['query']['split_time'] = $runVar['timers']['query']['init_time'] = $runVar['timers']['query']['proc1_time'] =
|
||||
$runVar['timers']['query']['proc2_time'] = $runVar['timers']['query']['proc3_time'] = $runVar['timers']['query']['split1_time'] = $runVar['timers']['query']['init1_time'] =
|
||||
$runVar['timers']['query']['proc11_time'] = $runVar['timers']['query']['proc21_time'] = $runVar['timers']['query']['proc31_time'] = $runVar['timers']['query']['tpg_time'] =
|
||||
$runVar['timers']['query']['tpg1_time'] = 0;
|
||||
|
||||
// Analyze tables
|
||||
printf($pdo->log->info("\nAnalyzing your tables to refresh your indexes."));
|
||||
$pdo->optimise(false, 'analyze', false, ['releases']);
|
||||
Utility::clearScreen();
|
||||
|
||||
$runVar['settings']['monitor'] = 0;
|
||||
$runVar['counts']['iterations'] = 1;
|
||||
$runVar['modsettings']['fc']['firstrun'] = true;
|
||||
$runVar['modsettings']['fc']['num'] = 0;
|
||||
|
||||
$tblCount = "SELECT TABLE_ROWS AS count FROM information_schema.TABLES WHERE TABLE_NAME = :table AND TABLE_SCHEMA = " . $pdo->escapeString($db_name);
|
||||
$psTableRowCount = $pdo->Prepare($tblCount);
|
||||
|
||||
while ($runVar['counts']['iterations'] > 0) {
|
||||
|
||||
//check the db connection
|
||||
if ($pdo->ping(true) == false) {
|
||||
unset($pdo);
|
||||
$pdo = new Settings();
|
||||
}
|
||||
|
||||
$timer01 = time();
|
||||
// These queries are very fast, run every loop -- tmux and site settings
|
||||
$runVar['settings'] = $pdo->queryOneRow($tRun->getMonitorSettings(), false);
|
||||
$runVar['timers']['query']['tmux_time'] = (time() - $timer01);
|
||||
|
||||
$runVar['settings']['book_reqids'] = (!empty($runVar['settings']['book_reqids'])
|
||||
? $runVar['settings']['book_reqids'] : \Category::CAT_PARENT_BOOK);
|
||||
|
||||
//get usenet connection info
|
||||
$runVar['connections'] = $tOut->getConnectionsInfo($runVar['constants']);
|
||||
|
||||
$runVar['modsettings']['clean'] = ($runVar['settings']['post_non'] == 2 ? ' clean ' : ' ');
|
||||
$runVar['constants']['pre_lim'] = ($runVar['counts']['iterations'] > 1 ? '7' : '');
|
||||
|
||||
//assign scripts
|
||||
$runVar['scripts']['releases'] = ($runVar['constants']['tablepergroup'] == 0
|
||||
? "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update_scripts/nix_scripts/tmux/bin/update_releases.php 1 false"
|
||||
: "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update_scripts/nix_scripts/multiprocessing/releases.php"
|
||||
);
|
||||
|
||||
switch((int) $runVar['settings']['binaries_run']) {
|
||||
case 1:
|
||||
$runVar['scripts']['binaries'] = "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update_scripts/nix_scripts/multiprocessing/binaries.php 0";
|
||||
break;
|
||||
case 2:
|
||||
$runVar['scripts']['binaries'] = "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update_scripts/nix_scripts/multiprocessing/safe.php binaries";
|
||||
break;
|
||||
default:
|
||||
$runVar['scripts']['binaries'] = 0;
|
||||
}
|
||||
|
||||
switch ((int) $runVar['settings']['backfill']) {
|
||||
case 1:
|
||||
$runVar['scripts']['backfill'] = "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update_scripts/nix_scripts/multiprocessing/backfill.php";
|
||||
break;
|
||||
case 2:
|
||||
$runVar['scripts']['backfill'] = "{$runVar['commands']['_python']} {$runVar['paths']['misc']}update_scripts/nix_scripts/tmux/python/backfill_threaded.py group";
|
||||
break;
|
||||
case 4:
|
||||
$runVar['scripts']['backfill'] = "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update_scripts/nix_scripts/multiprocessing/safe.php backfill";
|
||||
}
|
||||
|
||||
//get usenet connection counts
|
||||
unset ($runVar['conncounts']);
|
||||
$runVar['conncounts'] = $tOut->getUSPConnections('primary', $runVar['connections']);
|
||||
|
||||
if ($runVar['constants']['alternate_nntp'] == 1) {
|
||||
$runVar['conncounts'] += $tOut->getUSPConnections('alternate', $runVar['connections']);
|
||||
}
|
||||
|
||||
//run queries only after time exceeded, these queries can take awhile
|
||||
if ($runVar['counts']['iterations'] == 1 || (time() - $runVar['timers']['timer2'] >= $runVar['settings']['monitor'] && $runVar['settings']['is_running'] == 1)) {
|
||||
|
||||
$runVar['counts']['proc1'] = $runVar['counts']['proc2'] = $runVar['counts']['proc3'] = $splitqry = $newOldqry = false;
|
||||
$runVar['counts']['now']['total_work'] = 0;
|
||||
$runVar['modsettings']['fix_crap'] = explode(', ', ($runVar['settings']['fix_crap']));
|
||||
|
||||
echo $pdo->log->info("\nThe numbers(queries) above are currently being refreshed. \nNo pane(script) can be (re)started until these have completed.\n");
|
||||
$timer02 = time();
|
||||
|
||||
$splitqry = $newOldqry = '';
|
||||
|
||||
$splitqry = $tRun->proc_query(4, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name);
|
||||
$newOldqry = $tRun->proc_query(6, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name);
|
||||
|
||||
$splitres = $pdo->queryOneRow($splitqry, false);
|
||||
$runVar['timers']['newOld'] = $pdo->queryOneRow($newOldqry, false);
|
||||
|
||||
//assign split query results to main var
|
||||
if (is_array($splitres)) {
|
||||
foreach ($splitres AS $splitkey => $split) {
|
||||
$runVar['counts']['now'][$splitkey] = $split;
|
||||
}
|
||||
}
|
||||
|
||||
$runVar['timers']['query']['split_time'] = (time() - $timer02);
|
||||
$runVar['timers']['query']['split1_time'] = (time() - $timer01);
|
||||
|
||||
$timer03 = time();
|
||||
|
||||
//This is subpartition compatible -- loops through all partitions and adds their total row counts instead of doing a slow query count
|
||||
$partitions = $pdo->queryDirect(
|
||||
sprintf("
|
||||
SELECT SUM(TABLE_ROWS) AS count, PARTITION_NAME AS category
|
||||
FROM INFORMATION_SCHEMA.PARTITIONS
|
||||
WHERE TABLE_NAME = 'releases'
|
||||
AND TABLE_SCHEMA = %s
|
||||
GROUP BY PARTITION_NAME",
|
||||
$pdo->escapeString($db_name)
|
||||
)
|
||||
);
|
||||
foreach ($partitions as $partition) {
|
||||
$runVar['counts']['now'][$partition['category']] = $partition['count'];
|
||||
}
|
||||
unset($partitions);
|
||||
|
||||
$runVar['timers']['query']['init_time'] = (time() - $timer03);
|
||||
$runVar['timers']['query']['init1_time'] = (time() - $timer01);
|
||||
|
||||
$timer04 = time();
|
||||
$proc1qry = $tRun->proc_query(1, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name);
|
||||
$proc1res = $pdo->queryOneRow(($proc1qry !== false ? $proc1qry : ''), $tRun->rand_bool($runVar['counts']['iterations']));
|
||||
$runVar['timers']['query']['proc1_time'] = (time() - $timer04);
|
||||
$runVar['timers']['query']['proc11_time'] = (time() - $timer01);
|
||||
|
||||
$timer05 = time();
|
||||
$proc2qry = $tRun->proc_query(2, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name);
|
||||
$proc2res = $pdo->queryOneRow(($proc2qry !== false ? $proc2qry : ''), $tRun->rand_bool($runVar['counts']['iterations']));
|
||||
$runVar['timers']['query']['proc2_time'] = (time() - $timer05);
|
||||
$runVar['timers']['query']['proc21_time'] = (time() - $timer01);
|
||||
|
||||
$timer06 = time();
|
||||
$proc3qry = $tRun->proc_query(3, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name);
|
||||
$proc3res = $pdo->queryOneRow(($proc3qry !== false ? $proc3qry : ''), $tRun->rand_bool($runVar['counts']['iterations']));
|
||||
$runVar['timers']['query']['proc3_time'] = (time() - $timer06);
|
||||
$runVar['timers']['query']['proc31_time'] = (time() - $timer01);
|
||||
|
||||
$timer07 = time();
|
||||
if ($runVar['constants']['tablepergroup'] == 1) {
|
||||
$sql = 'SHOW TABLE STATUS';
|
||||
|
||||
$tables = $pdo->queryDirect($sql);
|
||||
$age = time();
|
||||
|
||||
$runVar['counts']['now']['collections_table'] = $runVar['counts']['now']['binaries_table'] = 0;
|
||||
$runVar['counts']['now']['parts_table'] = $runVar['counts']['now']['parterpair_table'] = 0;
|
||||
|
||||
if ($psTableRowCount === false) {
|
||||
echo "Unable to prepare statement, skipping monitor updates!";
|
||||
} else {
|
||||
if ($tables instanceof \Traversable) {
|
||||
foreach ($tables as $row) {
|
||||
$tbl = $row['name'];
|
||||
$stamp = 'UNIX_TIMESTAMP(MIN(dateadded))';
|
||||
|
||||
switch (true) {
|
||||
case strpos($tbl, 'collections_') !== false:
|
||||
$runVar['counts']['now']['collections_table'] += getTableRowCount($psTableRowCount,
|
||||
$tbl);
|
||||
$added = $pdo->queryOneRow(
|
||||
sprintf('SELECT %s AS dateadded FROM %s',
|
||||
$stamp,
|
||||
$tbl
|
||||
)
|
||||
);
|
||||
if (isset($added['dateadded']) && is_numeric($added['dateadded']) &&
|
||||
$added['dateadded'] < $age
|
||||
) {
|
||||
$age = $added['dateadded'];
|
||||
}
|
||||
break;
|
||||
case strpos($tbl, 'binaries_') !== false:
|
||||
$runVar['counts']['now']['binaries_table'] += getTableRowCount($psTableRowCount,
|
||||
$tbl);
|
||||
break;
|
||||
// This case must come before the 'parts_' one.
|
||||
case strpos($tbl, 'partrepair_') !== false:
|
||||
$runVar['counts']['now']['partrepair_table'] += getTableRowCount($psTableRowCount,
|
||||
$tbl);
|
||||
|
||||
break;
|
||||
case strpos($tbl, 'parts_') !== false:
|
||||
$runVar['counts']['now']['parts_table'] += getTableRowCount($psTableRowCount,
|
||||
$tbl);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
$runVar['timers']['newOld']['oldestcollection'] = $age;
|
||||
|
||||
//free up memory used by now stale data
|
||||
unset($age, $added, $tables);
|
||||
|
||||
$runVar['timers']['query']['tpg_time'] = (time() - $timer07);
|
||||
$runVar['timers']['query']['tpg1_time'] = (time() - $timer01);
|
||||
}
|
||||
}
|
||||
}
|
||||
$runVar['timers']['timer2'] = time();
|
||||
|
||||
//assign postprocess values from $proc
|
||||
if (is_array($proc1res)) {
|
||||
foreach ($proc1res AS $proc1key => $proc1) {
|
||||
$runVar['counts']['now'][$proc1key] = $proc1;
|
||||
}
|
||||
} else {
|
||||
errorOnSQL($pdo);
|
||||
}
|
||||
|
||||
if (is_array($proc2res)) {
|
||||
foreach ($proc2res AS $proc2key => $proc2) {
|
||||
$runVar['counts']['now'][$proc2key] = $proc2;
|
||||
}
|
||||
} else {
|
||||
errorOnSQL($pdo);
|
||||
}
|
||||
if (is_array($proc3res)) {
|
||||
foreach ($proc3res AS $proc3key => $proc3) {
|
||||
$runVar['counts']['now'][$proc3key] = $proc3;
|
||||
}
|
||||
} else {
|
||||
errorOnSQL($pdo);
|
||||
}
|
||||
|
||||
// now that we have merged our query data we can unset these to free up memory
|
||||
unset($proc1res, $proc2res, $proc3res, $splitres);
|
||||
|
||||
// Zero out any post proc counts when that type of pp has been turned off
|
||||
foreach ($runVar['settings'] as $settingkey => $setting) {
|
||||
if (strpos($settingkey, 'process') == 0 && $setting == 0) {
|
||||
$runVar['counts']['now'][$settingkey] = $runVar['counts']['start'][$settingkey] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//set initial start postproc values from work queries -- this is used to determine diff variables
|
||||
if ($runVar['counts']['iterations'] == 1) {
|
||||
$runVar['counts']['start'] = $runVar['counts']['now'];
|
||||
}
|
||||
|
||||
foreach ($runVar['counts']['now'] as $key => $proc) {
|
||||
|
||||
//if key is a process type, add it to total_work
|
||||
if (strpos($key, 'process') === 0) {
|
||||
$runVar['counts']['now']['total_work'] += $proc;
|
||||
}
|
||||
|
||||
//calculate diffs
|
||||
$runVar['counts']['diff'][$key] = number_format($proc - $runVar['counts']['start'][$key]);
|
||||
|
||||
//calculate percentages -- if user has no releases, set 0 for each key or this will fail on divide by zero
|
||||
$runVar['counts']['percent'][$key] = ($runVar['counts']['now']['releases'] > 0
|
||||
? sprintf("%02s", floor(($proc / $runVar['counts']['now']['releases']) * 100)) : 0);
|
||||
}
|
||||
|
||||
$runVar['counts']['now']['total_work'] += $runVar['counts']['now']['work'];
|
||||
|
||||
// Set initial total work count for diff
|
||||
if ($runVar['counts']['iterations'] == 1) {
|
||||
$runVar['counts']['start']['total_work'] = $runVar['counts']['now']['total_work'];
|
||||
}
|
||||
|
||||
// Set diff total work count
|
||||
$runVar['counts']['diff']['total_work'] = number_format($runVar['counts']['now']['total_work'] - $runVar['counts']['start']['total_work']);
|
||||
}
|
||||
|
||||
//set kill switches
|
||||
$runVar['killswitch']['pp'] = (($runVar['settings']['postprocess_kill'] < $runVar['counts']['now']['total_work']) && ($runVar['settings']['postprocess_kill'] != 0)
|
||||
? true
|
||||
: false
|
||||
);
|
||||
$runVar['killswitch']['coll'] = (($runVar['settings']['collections_kill'] < $runVar['counts']['now']['collections_table']) && ($runVar['settings']['collections_kill'] != 0)
|
||||
? true
|
||||
: false
|
||||
);
|
||||
|
||||
$tOut->updateMonitorPane($runVar);
|
||||
|
||||
//begin pane run execution
|
||||
if ($runVar['settings']['is_running'] === '1') {
|
||||
|
||||
//run main updating function(s)
|
||||
$tRun->runPane('main', $runVar);
|
||||
|
||||
//run nzb-import
|
||||
$tRun->runPane('import', $runVar);
|
||||
|
||||
//run postprocess_releases amazon
|
||||
$tRun->runPane('amazon', $runVar);
|
||||
|
||||
//respawn IRCScraper if it has been killed
|
||||
$tRun->runPane('scraper', $runVar);
|
||||
|
||||
//run sharing regardless of sequential setting
|
||||
$tRun->runPane('sharing', $runVar);
|
||||
|
||||
//update tv and theaters
|
||||
$tRun->runPane('updatetv', $runVar);
|
||||
|
||||
//run these if complete sequential not set
|
||||
if ($runVar['constants']['sequential'] != 2) {
|
||||
|
||||
//fix names
|
||||
$tRun->runPane('fixnames', $runVar);
|
||||
|
||||
//dehash releases
|
||||
$tRun->runPane('dehash', $runVar);
|
||||
|
||||
// Remove crap releases.
|
||||
$tRun->runPane('removecrap', $runVar);
|
||||
|
||||
//run postprocess_releases additional
|
||||
$tRun->runPane('ppadditional', $runVar);
|
||||
|
||||
//run postprocess_releases non amazon
|
||||
$tRun->runPane('nonamazon', $runVar);
|
||||
}
|
||||
|
||||
} else if ($runVar['settings']['is_running'] === '0') {
|
||||
$tRun->runPane('notrunning', $runVar);
|
||||
}
|
||||
|
||||
$runVar['counts']['iterations']++;
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
function errorOnSQL($pdo)
|
||||
{
|
||||
echo $pdo->log->error(PHP_EOL . "Monitor encountered severe errors retrieving process data from MySQL. Please diagnose and try running again." . PHP_EOL);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getTableRowCount(PDOStatement &$ps, $table)
|
||||
{
|
||||
$success = $ps->execute([':table' => $table]);
|
||||
if ($success) {
|
||||
$result = $ps->fetch();
|
||||
|
||||
return is_numeric($result['count']) ? $result['count'] : 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
segments/np_mpd
|
||||
segments/xkb_layout
|
||||
*.swp
|
||||
@@ -0,0 +1,34 @@
|
||||
Please append you name/nick here when you have contributed with something!
|
||||
|
||||
Erik Westrup <erik.westrup@gmail.com>
|
||||
Suvash Thapaliya <suvash@gmail.com>
|
||||
Erik Jansson <erikjansson90@gmail.com>
|
||||
Yuku Takahashi <taka84u9@gmail.com>
|
||||
Oscar Olsson <osse.olsson@gmail.com>
|
||||
Ryo Katsuma
|
||||
negipo
|
||||
Sina Siadat
|
||||
Vivien Leroy <fantattitude@me.com>
|
||||
Gino Lucero
|
||||
Derek Ashley Thomas <derekathomas@gmail.com>
|
||||
LuRsT
|
||||
Tomokazu Hirai <tomokazu.hirai@gmail.com>
|
||||
Matt Black
|
||||
krieiter
|
||||
Viktor Jackson
|
||||
flytreeleft <flytreeleft@126.com>
|
||||
Conner McDaniel
|
||||
David Francos <me@davidfrancos.net>
|
||||
Travis Thompson <butters08@gmail.com>
|
||||
Jonathon Klobucar
|
||||
Dylan Copeland <me@dylancopeland.com>
|
||||
Pete Johns <paj-github@johnsy.com>
|
||||
Robert Murray McMahon
|
||||
Jeff Felchner
|
||||
tobetoby
|
||||
Matthew Lanigan
|
||||
Hadret <hadret@gmail.com>
|
||||
antiAgainst <antiAgainst@gmail.com>
|
||||
Alexander Luberg <alex@luberg.me>
|
||||
Stanislaw Pusep <stas@sysd.org>
|
||||
Austin Beam
|
||||
@@ -0,0 +1,14 @@
|
||||
tmux-powerline - Statusbar configuration for tmux that looks like vim-powerline and consist of dynamic segments.
|
||||
|
||||
Copyright (c) 2012, see AUTHORS
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
http://opensource.org/licenses/BSD-3-Clause
|
||||
@@ -0,0 +1,198 @@
|
||||
# tmux-powerline
|
||||
This is a set of scripts for making a nice and dynamic tmux statusbar consisting of segments. This is much like [Lokaltog/vim-powerline](https://github.com/Lokaltog/vim-powerline) but for tmux.
|
||||
|
||||
The following segments exists for now:
|
||||
* LAN & WAN IP addresses.
|
||||
* Now Playing for MPD, Spotify (GNU/Linux native or wine, OS X), iTunes (OS X), Rhythmbox, Banshee, MOC, Audacious, Rdio (OS X), cmus, Pithos and Last.fm (last scrobbled track).
|
||||
* New mail count for GMail, Maildir, mbox and Apple Mail.
|
||||
* GNU/Linux and Macintosh OS X battery status (uses [richo/dotfiles/bin/battery](https://github.com/richoH/dotfiles/blob/master/bin/battery)).
|
||||
* Weather in Celsius, Fahrenheit and Kelvin using Yahoo Weather.
|
||||
* System load, cpu usage and uptime.
|
||||
* Git, SVN and Mercurial branch in CWD.
|
||||
* Date and time.
|
||||
* Hostname.
|
||||
* tmux info.
|
||||
* CWD in pane.
|
||||
* Current X keyboard layout.
|
||||
* Network download/upload speed.
|
||||
* Earthquake warnings.
|
||||
|
||||
# Screenshots
|
||||
**Full screenshot**
|
||||
|
||||

|
||||
|
||||
**left-status**
|
||||
|
||||
Current tmux session, window and pane, hostname and LAN & WAN IP address.
|
||||
|
||||

|
||||
|
||||
**right-status**
|
||||
|
||||
New mails, now playing, average load, weather, date and time.
|
||||
|
||||

|
||||
|
||||
Now I've read my inbox so the mail segment disappears!
|
||||
|
||||

|
||||
|
||||
After pausing the music there's no need for showing NP anymore. Also the weather has become much nicer!
|
||||
|
||||

|
||||
|
||||
Remaining battery.
|
||||
|
||||

|
||||
|
||||
# Requirements
|
||||
Requirements for the lib to work are:
|
||||
|
||||
* Recent tmux version
|
||||
* `bash --version` >= 3.2 (Does not have to be your default shell.)
|
||||
* A patched font. Follow instructions at [Lokaltog/vim-powerline/fontpatcher](https://github.com/Lokaltog/vim-powerline/tree/develop/fontpatcher) or [download](https://github.com/Lokaltog/vim-powerline/wiki/Patched-fonts) a new one. However you can use other substitute symbols as well; see `config.sh`.
|
||||
|
||||
## Segment Requirements
|
||||
Requirements for some segments. You only need to fulfill the requirements for those segments you want to use.
|
||||
|
||||
* `wan_ip.sh`, `now_playing.sh` (last.fm), `weather_yahoo.sh`: curl, bc
|
||||
* `now_playing.sh` (mpd) : [libmpdclient](http://sourceforge.net/projects/musicpd/files/libmpdclient/)
|
||||
* `xkb_layout.sh`: X11, XKB
|
||||
* `mailcount.sh` (gmail): wget.
|
||||
* `ifstat.sh`: ifstat (there is a simpler segment not using ifstat but samples /sys/class/net)
|
||||
* `tmux_mem_cpu_load.sh`: [tmux-mem-cpu-load](https://github.com/thewtex/tmux-mem-cpu-load)
|
||||
* `rainbarf.sh`: [rainbarf](https://github.com/creaktive/rainbarf)
|
||||
* `weather.sh`: GNU `grep` with Perl regexp enabled (FreeBSD specific)
|
||||
|
||||
## OS X specific requirements
|
||||
|
||||
The `grep` tool is outdated on OS X 10.8 Mountain Lion so you might have to upgrade it. Unfortunately the main homebrew repo
|
||||
[does not contain grep](https://github.com/mxcl/homebrew/pull/3473) so use the following command to get the lastest version.
|
||||
|
||||
```bash
|
||||
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/grep.rb
|
||||
```
|
||||
|
||||
or if you have heightened security set up, just tap the homebrew dupes and install grep
|
||||
|
||||
```bash
|
||||
brew tap homebrew/dupes
|
||||
brew install homebrew/dupes/grep
|
||||
```
|
||||
|
||||
## FreeBSD specific requirements
|
||||
|
||||
Preinstalled `grep` in FreeBSD doesn't support Perl regexp. Solution is rather simple -- you need to use `textproc/gnugrep` port instead. You also need to make sure, that it has support for PCRE and is compiled with `--enable-perl-regexp` flag.
|
||||
|
||||
|
||||
# Installation
|
||||
Start with checking out the repository with:
|
||||
|
||||
```console
|
||||
$ cd ~/some/path/
|
||||
$ git clone git://github.com/erikw/tmux-powerline.git
|
||||
```
|
||||
|
||||
Now edit your `~/.tmux.conf` to use the scripts:
|
||||
|
||||
<!-- Close syntax enough. -->
|
||||
```vim
|
||||
set-option -g status on
|
||||
set-option -g status-interval 2
|
||||
set-option -g status-utf8 on
|
||||
set-option -g status-justify "centre"
|
||||
set-option -g status-left-length 60
|
||||
set-option -g status-right-length 90
|
||||
set-option -g status-left "#(~/path/to/tmux-powerline/powerline.sh left)"
|
||||
set-option -g status-right "#(~/path/to/tmux-powerline/powerline.sh right)"
|
||||
```
|
||||
|
||||
Set the maximum lengths to something that suits your configuration of segments and size of terminal (the maximum segments length will be handled better in the future).
|
||||
|
||||
The window list can be powerlineified if you'd like by adding the following line to the same file:
|
||||
|
||||
```vim
|
||||
set-window-option -g window-status-current-format "#[fg=colour235, bg=colour27]⮀#[fg=colour255, bg=colour27] #I ⮁ #W #[fg=colour27, bg=colour235]⮀"
|
||||
```
|
||||
|
||||
You can toggle the visibility of the statusbars by adding the following lines:
|
||||
|
||||
```vim
|
||||
bind C-[ run '~/path/to/tmux-powerline/mute_powerline.sh left' # Mute left statusbar.
|
||||
bind C-] run '~/path/to/tmux-powerline/mute_powerline.sh right' # Mute right statusbar.
|
||||
```
|
||||
|
||||
Some segments e.g. cwd and cvs_branch needs to find the current working directory of the active pane. To achieve this we let tmux save the path each time the shell prompt is displayed. Put the line below in your `~/.bashrc` or where you define you PS1 variable. zsh users can put it in e.g. `~/.zshrc` and may change `PS1` to `PROMPT` (but that's not necessary).
|
||||
|
||||
```bash
|
||||
PS1="$PS1"'$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#D" | tr -d %) "$PWD")'
|
||||
```
|
||||
|
||||
# Configuration
|
||||
|
||||
The default segments that are shown are defined in `themes/default.sh`. You will probably want to change those to fit your needs. To do so you can edit that file directly but preferable, for easier updating of the repo, you can make a copy and edit that one (or see how to use custom themes directory below). A palette of colors that can be used can be obtained by running the script `color_palette.sh`.
|
||||
|
||||
```console
|
||||
$ cp themes/default.sh themes/mytheme.sh
|
||||
$ $EDITOR themes/mytheme.sh
|
||||
```
|
||||
Now generate a default configuration file by doing
|
||||
|
||||
```console
|
||||
$ ./generate_rc.sh
|
||||
$ mv ~/.tmux-powerlinerc.default ~/.tmux-powerlinerc
|
||||
$ $EDITOR ~/.tmux-powerlinerc
|
||||
```
|
||||
and change theme to use and values for segments you want to use. If you want to keep the repo checkout clean you can set custom segment and theme paths in the general section and then store your files outside the repo.
|
||||
|
||||
# Debugging
|
||||
|
||||
Some segments might not work on your system for various reasons such as missing programs or different versions not having the same options. To find out which segment is not working it may help to enable the debug setting in `~/.tmux-powerlinerc`. However this may not be enough to determine the error so you can inspect all executed bash commands (will be a long output) by doing
|
||||
|
||||
```console
|
||||
$ bash -x powerline.sh (left|right)
|
||||
```
|
||||
|
||||
To debug smaller portions of code, say if you think the problem lies in a specific segment, insert these lines at the top and bottom of that file (or region you want to inspect there)
|
||||
|
||||
```bash
|
||||
set -x
|
||||
exec 2>/tmp/tmux-powerline.log
|
||||
<code to debug>
|
||||
set +x
|
||||
```
|
||||
|
||||
and then inspect the outputs like
|
||||
|
||||
```console
|
||||
less /tmp/tmux-powerline.log
|
||||
tail -f /tmp/tmux-powerline.log # or follow output like this.
|
||||
```
|
||||
|
||||
If you can not solve the problems you can post an [issue](https://github.com/erikw/tmux-powerline/issues?state=open) and be sure to include relevant information about your system and script output (from bash -x) and/or screenshots if needed.
|
||||
|
||||
## Common problems
|
||||
|
||||
### VCS_branch / PWD is not updating
|
||||
The issue is probably that the update of the current directory in the active pane is not updated correctly. Make sure that your PS1 or PROMPT variable actually contains the line from the installation step above by simply inspecting the output of `echo $PS1`. You might have placed the PS1 line in you shell configuration such that it is overwritten later. The simplest solution is to put it at the very end to make sure that nothing overwrites it. See [issue #52](https://github.com/erikw/tmux-powerline/issues/52).
|
||||
|
||||
### Nothing is displayed
|
||||
You have edited `~/.tmux.conf` but no powerline is displayed. This might be because tmux is not aware of the changes so you have to restart your tmux session or reloaded that file by typing this on the command line (or in tmux command mode with `prefix :`)
|
||||
|
||||
```console
|
||||
$ tmux source-file ~/.tmux.conf
|
||||
```
|
||||
### Multiple lines in bash or no powerline in zsh using iTerm (OS X)
|
||||
If your tmux looks like [this](https://github.com/erikw/tmux-powerline/issues/125) then you may have to in iTerm uncheck [Unicode East Asian Ambiguous characters are wide] in Preferences -> Settings -> Advanced.
|
||||
|
||||
# Hacking
|
||||
|
||||
This project can only gain positively from contributions. Fork today and make your own enhancements and segments to share back! If you'd like, add your name and E-mail to AUTHORS before making a pull request so you can get some credit for your work :-)
|
||||
|
||||
## How to make a segment
|
||||
If you want to (of course you do!) send a pull request for a cool segment you written make sure that it follows the style of existing segments, unless you have good reason for it. Each segment resides in the `segments/` directory with a descriptive and simple name. A segment must have at least one function and that is `run_segment` which is like the main function that is called from the tmux-powerline lib. What ever text is echoed out from this function to stdout is the text displayed in the tmux statusbar. If the segment at a certain point does not have anything to show, simply don't echo anything out and the segment will be hidden. A successful execution of the `run_segment` function should return an exit code of 0. If the segment failed to execute in a fatal way return a non-zero exit code so the user can pick up the error and fix it when debug mode is on (e.g. missing program that is needed for the segment).
|
||||
|
||||
Usage of helper function to organize the work of a segment is encourage and should be named in the format `__helper_func`. If a segment has settings it should have a function `generate_rc` which outputs default values of all settings and a short explanation of the setting and its values. Study e.g. `segments/now_playing.sh` to see how it is done. A segment having settings should typically call a helper function `__process_settings` as the first statement in `run_segment` that sets default values to the settings that has not been set by the user.
|
||||
|
||||
Also, don't use bash4 features as requiring bash4 complicates installation for OS X user quite a bit. Use tabs for indentation ([discussion](https://github.com/erikw/tmux-powerline/pull/92)),
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# Print tmux color palette.
|
||||
# Idea from http://superuser.com/questions/285381/how-does-the-tmux-color-palette-work
|
||||
|
||||
for i in $(seq 0 4 255); do
|
||||
for j in $(seq $i $(expr $i + 3)); do
|
||||
for k in $(seq 1 $(expr 3 - ${#j})); do
|
||||
printf " "
|
||||
done
|
||||
printf "\x1b[38;5;${j}mcolour${j}"
|
||||
[[ $(expr $j % 4) != 3 ]] && printf " "
|
||||
done
|
||||
printf "\n"
|
||||
done
|
||||
@@ -0,0 +1,9 @@
|
||||
# Other settings and helper functions.
|
||||
|
||||
debug_mode_enabled() {
|
||||
[ -n "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" -a "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" != "false" ];
|
||||
}
|
||||
|
||||
patched_font_in_use() {
|
||||
[ -z "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" -o "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" != "false" ];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# Paths
|
||||
|
||||
export TMUX_POWERLINE_DIR_LIB="$TMUX_POWERLINE_DIR_HOME/lib"
|
||||
export TMUX_POWERLINE_DIR_SEGMENTS="$TMUX_POWERLINE_DIR_HOME/segments"
|
||||
export TMUX_POWERLINE_DIR_TEMPORARY="/tmp/tmux-powerline_${USER}"
|
||||
export TMUX_POWERLINE_DIR_THEMES="$TMUX_POWERLINE_DIR_HOME/themes"
|
||||
export TMUX_POWERLINE_RCFILE="$HOME/.tmux-powerlinerc"
|
||||
export TMUX_POWERLINE_RCFILE_DEFAULT="$HOME/.tmux-powerlinerc.default"
|
||||
|
||||
if [ ! -d "$TMUX_POWERLINE_DIR_TEMPORARY" ]; then
|
||||
mkdir "$TMUX_POWERLINE_DIR_TEMPORARY"
|
||||
fi
|
||||
@@ -0,0 +1,18 @@
|
||||
# Shell Configuration
|
||||
# vi: sw=8 ts=8 noet
|
||||
|
||||
export SHELL_PLATFORM='unknown'
|
||||
|
||||
case "$OSTYPE" in
|
||||
*'linux'* ) SHELL_PLATFORM='linux' ;;
|
||||
*'darwin'* ) SHELL_PLATFORM='osx' ;;
|
||||
*'bsd'* ) SHELL_PLATFORM='bsd' ;;
|
||||
esac
|
||||
|
||||
shell_is_linux() { [[ $SHELL_PLATFORM == 'linux' || $SHELL_PLATFORM == 'bsd' ]]; }
|
||||
shell_is_osx() { [[ $SHELL_PLATFORM == 'osx' ]]; }
|
||||
shell_is_bsd() { [[ $SHELL_PLATFORM == 'bsd' || $SHELL_PLATFORM == 'osx' ]]; }
|
||||
|
||||
export -f shell_is_linux
|
||||
export -f shell_is_osx
|
||||
export -f shell_is_bsd
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate default rc file.
|
||||
|
||||
export TMUX_POWERLINE_DIR_HOME="$(dirname $0)"
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/defaults.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/rcfile.sh"
|
||||
|
||||
generate_default_rc
|
||||
|
||||
exit 0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,9 @@
|
||||
#! Check script arguments.
|
||||
|
||||
check_arg_side() {
|
||||
local side="$1"
|
||||
if ! [ "$side" == "left" -o "$side" == "right" ]; then
|
||||
echo "Argument must be must be the side to handle {left, right} and not \"${side}\"."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
__print_colored_content() {
|
||||
echo -n "#[fg=colour$3, bg=colour$2]"
|
||||
echo -n "$1"
|
||||
echo -n "#[default]"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# Muting Logic
|
||||
# In all cases $1 is the side to be muted (eg left/right).
|
||||
|
||||
powerline_muted() {
|
||||
[ -e "$(__powerline_mute_file $1)" ];
|
||||
}
|
||||
|
||||
toggle_powerline_mute_status() {
|
||||
if powerline_muted $1; then
|
||||
rm "$(__powerline_mute_file $1)"
|
||||
else
|
||||
touch "$(__powerline_mute_file $1)"
|
||||
fi
|
||||
}
|
||||
|
||||
__powerline_mute_file() {
|
||||
local tmux_session=$(tmux display -p "#S")
|
||||
|
||||
echo -n "${TMUX_POWERLINE_DIR_TEMPORARY}/mute_${tmux_session}_$1"
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
# Default configuration file for tmux-powerline.
|
||||
# Modeline {
|
||||
# vi: foldmarker={,} foldmethod=marker foldlevel=0 tabstop=4 filetype=sh
|
||||
# }
|
||||
|
||||
# General {
|
||||
# Show which segment fails and its exit code.
|
||||
export TMUX_POWERLINE_DEBUG_MODE_ENABLED="false"
|
||||
# Use patched font symbols.
|
||||
export TMUX_POWERLINE_PATCHED_FONT_IN_USE="true"
|
||||
# The theme to use.
|
||||
export TMUX_POWERLINE_THEME="tmux"
|
||||
# Overlay dirctory to look for themes. There you can put your own themes outside the repo. Fallback will still be the "themes" directory in the repo.
|
||||
export TMUX_POWERLINE_DIR_USER_THEMES=""
|
||||
# Overlay dirctory to look for segments. There you can put your own segments outside the repo. Fallback will still be the "segments" directory in the repo.
|
||||
export TMUX_POWERLINE_DIR_USER_SEGMENTS=""
|
||||
# }
|
||||
|
||||
# battery.sh {
|
||||
# How to display battery remaining. Can be {percentage, cute}.
|
||||
export TMUX_POWERLINE_SEG_BATTERY_TYPE="percentage"
|
||||
# How may hearts to show if cute indicators are used.
|
||||
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="5"
|
||||
# }
|
||||
|
||||
# date.sh {
|
||||
# date(1) format for the date. If you don't, for some reason, like ISO 8601 format you might want to have "%D" or "%m/%d/%Y".
|
||||
export TMUX_POWERLINE_SEG_DATE_FORMAT="%F"
|
||||
# }
|
||||
|
||||
# earthquake.sh {
|
||||
# The data provider to use. Currently only "goo" is supported.
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER="goo"
|
||||
# How often to update the earthquake data in seconds.
|
||||
# Note: This is not an early warning detector, use this
|
||||
# to be informed about recent earthquake magnitudes in your
|
||||
# area. If this is too often, goo may decide to ban you form
|
||||
# their server
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD="600"
|
||||
# Only display information when earthquakes are within this many minutes
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW="60"
|
||||
# Display time with this format
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT='(%H:%M)'
|
||||
# Display only if magnitude is greater or equal to this number
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE="3"
|
||||
# }
|
||||
|
||||
# hostname.sh {
|
||||
# Use short or long format for the hostname. Can be {"short, long"}.
|
||||
export TMUX_POWERLINE_SEG_HOSTNAME_FORMAT="short"
|
||||
# }
|
||||
|
||||
# mailcount.sh {
|
||||
# Mailbox type to use. Can be any of {apple_mail, gmail, maildir, mbox}
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_MAILBOX_TYPE=""
|
||||
|
||||
## Gmail
|
||||
# Enter your Gmail username here WITH OUT @gmail.com.( OR @domain)
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_GMAIL_USERNAME=""
|
||||
# Google password. Recomenned to use application specific password (https://accounts.google.com/b/0/IssuedAuthSubTokens) Leave this empty to get password from OS X keychain.
|
||||
# For OSX users : MAKE SURE that you add a key to the keychain in the format as follows
|
||||
# Keychain Item name : http://<value-you-fill-in-server-variable-below>
|
||||
# Account name : <username-below>@<server-below>
|
||||
# Password : Your password ( Once again, try to use 2 step-verification and application-specific password)
|
||||
# See http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833 for more info.
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_GMAIL_PASSWORD=""
|
||||
# Domain name that will complete your email. For normal GMail users it probably is "gmail.com but can be "foo.tld" for Google Apps users.
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_GMAIL_SERVER="gmail.com"
|
||||
# How often in minutes to check for new mails.
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_GMAIL_INTERVAL="5"
|
||||
|
||||
## Maildir
|
||||
# Path to the maildir to check.
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_MAILDIR_INBOX="/home/jonnyboy/.mail/inbox/new"
|
||||
|
||||
## mbox
|
||||
# Path to the mbox to check.
|
||||
export TMUX_POWERLINE_SEG_MAILCOUNT_MBOX_INBOX="/var/mail/jonnyboy"
|
||||
# }
|
||||
|
||||
# now_playing.sh {
|
||||
# Music player to use. Can be any of {audacious, banshee, cmus, itunes, lastfm, mocp, mpd, mpd_simple, pithos, rdio, rhythmbox, spotify, spotify_wine}.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_MUSIC_PLAYER=""
|
||||
# Maximum output length.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_MAX_LEN="40"
|
||||
# How to handle too long strings. Can be {trim, roll}.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_TRIM_METHOD="trim"
|
||||
# Charcters per second to roll if rolling trim method is used.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_ROLL_SPEED="2"
|
||||
|
||||
# Hostname for MPD server in the format "[password@]host"
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_HOST="localhost"
|
||||
# Port the MPD server is running on.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_PORT="6600"
|
||||
# Song display format for mpd_simple. See mpc(1) for delimiters.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_SIMPLE_FORMAT="%artist% - %title%"
|
||||
|
||||
# Username for Last.fm if that music player is used.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_LASTFM_USERNAME=""
|
||||
# How often in seconds to update the data from last.fm.
|
||||
export TMUX_POWERLINE_SEG_NOW_PLAYING_LASTFM_UPDATE_PERIOD="30"
|
||||
# }
|
||||
|
||||
# pwd.sh {
|
||||
# Maximum length of output.
|
||||
export TMUX_POWERLINE_SEG_PWD_MAX_LEN="40"
|
||||
# }
|
||||
|
||||
# time.sh {
|
||||
# date(1) format for the time. Americans might want to have "%I:%M %p".
|
||||
export TMUX_POWERLINE_SEG_TIME_FORMAT="%H:%M"
|
||||
# }
|
||||
|
||||
# weather.sh {
|
||||
# The data provider to use. Currently only "yahoo" is supported.
|
||||
export TMUX_POWERLINE_SEG_WEATHER_DATA_PROVIDER="yahoo"
|
||||
# What unit to use. Can be any of {c,f,k}.
|
||||
export TMUX_POWERLINE_SEG_WEATHER_UNIT="c"
|
||||
# How often to update the weather in seconds.
|
||||
export TMUX_POWERLINE_SEG_WEATHER_UPDATE_PERIOD="600"
|
||||
|
||||
# Your location. Find a code that works for you:
|
||||
# 1. Go to Yahoo weather http://weather.yahoo.com/
|
||||
# 2. Find the weather for you location
|
||||
# 3. Copy the last numbers in that URL. e.g. "http://weather.yahoo.com/united-states/california/newport-beach-12796587/" has the numbers "12796587"
|
||||
export TMUX_POWERLINE_SEG_WEATHER_LOCATION=""
|
||||
# }
|
||||
@@ -0,0 +1,142 @@
|
||||
# Library functions
|
||||
|
||||
print_powerline() {
|
||||
local side="$1"
|
||||
local upper_side=$(echo "$1" | tr '[:lower:]' '[:upper:]')
|
||||
eval "local input_segments=(\"\${TMUX_POWERLINE_${upper_side}_STATUS_SEGMENTS[@]}\")"
|
||||
local powerline_segments=()
|
||||
local powerline_segment_contents=()
|
||||
|
||||
__check_platform
|
||||
|
||||
__process_segment_defaults
|
||||
__process_scripts
|
||||
__process_colors
|
||||
|
||||
__process_powerline
|
||||
}
|
||||
|
||||
__process_segment_defaults() {
|
||||
for segment_index in "${!input_segments[@]}"; do
|
||||
local input_segment=(${input_segments[$segment_index]})
|
||||
eval "local default_separator=\$TMUX_POWERLINE_DEFAULT_${upper_side}SIDE_SEPARATOR"
|
||||
|
||||
powerline_segment_with_defaults=(
|
||||
${input_segment[0]:-"no_script"} \
|
||||
${input_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR} \
|
||||
${input_segment[2]:-$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR} \
|
||||
${input_segment[3]:-$default_separator} \
|
||||
)
|
||||
|
||||
powerline_segments[$segment_index]="${powerline_segment_with_defaults[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
__process_scripts() {
|
||||
for segment_index in "${!powerline_segments[@]}"; do
|
||||
local powerline_segment=(${powerline_segments[$segment_index]})
|
||||
|
||||
if [ -n "$TMUX_POWERLINE_DIR_USER_SEGMENTS" ] && [ -f "$TMUX_POWERLINE_DIR_USER_SEGMENTS/${powerline_segment[0]}.sh" ] ; then
|
||||
local script="$TMUX_POWERLINE_DIR_USER_SEGMENTS/${powerline_segment[0]}.sh"
|
||||
else
|
||||
local script="$TMUX_POWERLINE_DIR_SEGMENTS/${powerline_segment[0]}.sh"
|
||||
fi
|
||||
|
||||
export TMUX_POWERLINE_CUR_SEGMENT_BG="${powerline_segment[1]}"
|
||||
export TMUX_POWERLINE_CUR_SEGMENT_FG="${powerline_segment[2]}"
|
||||
source "$script"
|
||||
local output
|
||||
output=$(run_segment)
|
||||
local exit_code="$?"
|
||||
unset -f run_segment
|
||||
|
||||
if [ "$exit_code" -ne 0 ] && debug_mode_enabled ; then
|
||||
local seg_name="${script##*/}"
|
||||
echo "Segment '${seg_name}' exited with code ${exit_code}. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$output" ]; then
|
||||
powerline_segment_contents[$segment_index]=" $output "
|
||||
else
|
||||
unset -v powerline_segments[$segment_index]
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
__process_colors() {
|
||||
for segment_index in "${!powerline_segments[@]}"; do
|
||||
local powerline_segment=(${powerline_segments[$segment_index]})
|
||||
# Find the next segment that produces content (i.e. skip empty segments).
|
||||
for next_segment_index in $(eval echo {$(($segment_index + 1))..${#powerline_segments}}) ; do
|
||||
[[ -n ${powerline_segments[next_segment_index]} ]] && break
|
||||
done
|
||||
local next_segment=(${powerline_segments[$next_segment_index]})
|
||||
|
||||
if [ $side == 'left' ]; then
|
||||
powerline_segment[4]=${next_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
|
||||
elif [ $side == 'right' ]; then
|
||||
powerline_segment[4]=${previous_background_color:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
|
||||
fi
|
||||
|
||||
if __segment_separator_is_thin; then
|
||||
powerline_segment[5]=${powerline_segment[2]}
|
||||
else
|
||||
powerline_segment[5]=${powerline_segment[1]}
|
||||
fi
|
||||
|
||||
local previous_background_color=${powerline_segment[1]}
|
||||
|
||||
powerline_segments[$segment_index]="${powerline_segment[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
__process_powerline() {
|
||||
for segment_index in "${!powerline_segments[@]}"; do
|
||||
local powerline_segment=(${powerline_segments[$segment_index]})
|
||||
|
||||
local background_color=${powerline_segment[1]}
|
||||
local foreground_color=${powerline_segment[2]}
|
||||
local separator=${powerline_segment[3]}
|
||||
local separator_background_color=${powerline_segment[4]}
|
||||
local separator_foreground_color=${powerline_segment[5]}
|
||||
|
||||
eval "__print_${side}_segment ${segment_index} ${background_color} ${foreground_color} ${separator} ${separator_background_color} ${separator_foreground_color}"
|
||||
done
|
||||
}
|
||||
|
||||
__print_left_segment() {
|
||||
local content=${powerline_segment_contents[$1]}
|
||||
local content_background_color=$2
|
||||
local content_foreground_color=$3
|
||||
local separator=$4
|
||||
local separator_background_color=$5
|
||||
local separator_foreground_color=$6
|
||||
|
||||
__print_colored_content "$content" $content_background_color $content_foreground_color
|
||||
__print_colored_content $separator $separator_background_color $separator_foreground_color
|
||||
}
|
||||
|
||||
__print_right_segment() {
|
||||
local content=${powerline_segment_contents[$1]}
|
||||
local content_background_color=$2
|
||||
local content_foreground_color=$3
|
||||
local separator=$4
|
||||
local separator_background_color=$5
|
||||
local separator_foreground_color=$6
|
||||
|
||||
__print_colored_content $separator $separator_background_color $separator_foreground_color
|
||||
__print_colored_content "$content" $content_background_color $content_foreground_color
|
||||
}
|
||||
|
||||
__segment_separator_is_thin() {
|
||||
[[ ${powerline_segment[3]} == $TMUX_POWERLINE_SEPARATOR_LEFT_THIN || \
|
||||
${powerline_segment[3]} == $TMUX_POWERLINE_SEPARATOR_RIGHT_THIN ]];
|
||||
}
|
||||
|
||||
__check_platform() {
|
||||
if [ "$SHELL_PLATFORM" == "unknown" ] && debug_mode_enabled; then
|
||||
echo "Unknown platform; modify config/shell.sh" &1>&2
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Read user rc file.
|
||||
|
||||
process_settings() {
|
||||
__read_rcfile
|
||||
|
||||
if [ -z "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" ]; then
|
||||
export TMUX_POWERLINE_DEBUG_MODE_ENABLED="${TMUX_POWERLINE_DEBUG_MODE_ENABLED_DEFAULT}"
|
||||
fi
|
||||
|
||||
if [ -z "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" ]; then
|
||||
export TMUX_POWERLINE_PATCHED_FONT_IN_USE="${TMUX_POWERLINE_PATCHED_FONT_IN_USE_DEFAULT}"
|
||||
fi
|
||||
|
||||
if [ -z "$TMUX_POWERLINE_THEME" ]; then
|
||||
export TMUX_POWERLINE_THEME="${TMUX_POWERLINE_THEME_DEFAULT}"
|
||||
fi
|
||||
|
||||
eval TMUX_POWERLINE_DIR_USER_SEGMENTS="$TMUX_POWERLINE_DIR_USER_SEGMENTS"
|
||||
eval TMUX_POWERLINE_DIR_USER_THEMES="$TMUX_POWERLINE_DIR_USER_THEMES"
|
||||
if [ -n "$TMUX_POWERLINE_DIR_USER_THEMES" ] && [ -f "${TMUX_POWERLINE_DIR_USER_THEMES}/${TMUX_POWERLINE_THEME}.sh" ]; then
|
||||
source "${TMUX_POWERLINE_DIR_USER_THEMES}/${TMUX_POWERLINE_THEME}.sh"
|
||||
else
|
||||
source "${TMUX_POWERLINE_DIR_THEMES}/${TMUX_POWERLINE_THEME}.sh"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
generate_default_rc() {
|
||||
read -d '' rccontents << EORC
|
||||
# Default configuration file for tmux-powerline.
|
||||
# Modeline {
|
||||
# vi: foldmarker={,} foldmethod=marker foldlevel=0 tabstop=4 filetype=sh
|
||||
# }
|
||||
|
||||
# General {
|
||||
# Show which segment fails and its exit code.
|
||||
export TMUX_POWERLINE_DEBUG_MODE_ENABLED="${TMUX_POWERLINE_DEBUG_MODE_ENABLED_DEFAULT}"
|
||||
# Use patched font symbols.
|
||||
export TMUX_POWERLINE_PATCHED_FONT_IN_USE="${TMUX_POWERLINE_PATCHED_FONT_IN_USE_DEFAULT}"
|
||||
# The theme to use.
|
||||
export TMUX_POWERLINE_THEME="${TMUX_POWERLINE_THEME_DEFAULT}"
|
||||
# Overlay dirctory to look for themes. There you can put your own themes outside the repo. Fallback will still be the "themes" directory in the repo.
|
||||
export TMUX_POWERLINE_DIR_USER_THEMES=""
|
||||
# Overlay dirctory to look for segments. There you can put your own segments outside the repo. Fallback will still be the "segments" directory in the repo.
|
||||
export TMUX_POWERLINE_DIR_USER_SEGMENTS=""
|
||||
# }
|
||||
EORC
|
||||
|
||||
for segment in ${TMUX_POWERLINE_DIR_SEGMENTS}/*.sh; do
|
||||
source "$segment"
|
||||
if declare -f generate_segmentrc >/dev/null; then
|
||||
segmentrc=$(generate_segmentrc | sed -e 's/^/\\t/g')
|
||||
unset -f generate_segmentrc
|
||||
local seg_name="${segment##*/}"
|
||||
rccontents="${rccontents}\n\n# ${seg_name} {\n${segmentrc}\n# }"
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "$rccontents" > "$TMUX_POWERLINE_RCFILE_DEFAULT"
|
||||
echo "Default configuration file generated to: ${TMUX_POWERLINE_RCFILE_DEFAULT}"
|
||||
echo "Copy/move it to \"${TMUX_POWERLINE_RCFILE}\" and make your changes."
|
||||
}
|
||||
|
||||
__read_rcfile() {
|
||||
if [ -f "$TMUX_POWERLINE_RCFILE" ]; then
|
||||
source "$TMUX_POWERLINE_RCFILE"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
# Rolling anything what you want.
|
||||
# arg1: text to roll.
|
||||
# arg2: max length to display.
|
||||
# arg3: roll speed in characters per second.
|
||||
roll_text() {
|
||||
local text="$1" # Text to print
|
||||
|
||||
if [ -z "$text" ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
local max_len="10" # Default max length.
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
max_len="$2"
|
||||
fi
|
||||
|
||||
local speed="1" # Default roll speed in chars per second.
|
||||
|
||||
if [ -n "$3" ]; then
|
||||
speed="$3"
|
||||
fi
|
||||
|
||||
# Skip rolling if the output is less than max_len.
|
||||
if [ "${#text}" -le "$max_len" ]; then
|
||||
echo "$text"
|
||||
return
|
||||
fi
|
||||
|
||||
# Anything starting with 0 is an Octal number in Shell,C or Perl,
|
||||
# so we must explicitly state the base of a number using base#number
|
||||
local offset=$((10#$(date +%s) * ${speed} % ${#text}))
|
||||
|
||||
# Truncate text.
|
||||
text=${text:offset}
|
||||
|
||||
local char # Character.
|
||||
local bytes # The bytes of one character.
|
||||
local index
|
||||
|
||||
for ((index=0; index < max_len; index++)); do
|
||||
char=${text:index:1}
|
||||
bytes=$(echo -n $char | wc -c)
|
||||
# The character will takes twice space
|
||||
# of an alphabet if (bytes > 1).
|
||||
if ((bytes > 1)); then
|
||||
max_len=$((max_len - 1))
|
||||
fi
|
||||
done
|
||||
|
||||
text=${text:0:max_len}
|
||||
|
||||
#echo "index=${index} max=${max_len} len=${#text}"
|
||||
# How many spaces we need to fill to keep
|
||||
# the length of text that will be shown?
|
||||
local fill_count=$((${index} - ${#text}))
|
||||
|
||||
for ((index=0; index < fill_count; index++)); do
|
||||
text="${text} "
|
||||
done
|
||||
|
||||
echo "${text}"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# Get the current path in the segment.
|
||||
get_tmux_cwd() {
|
||||
local env_name=$(tmux display -p "TMUXPWD_#D" | tr -d %)
|
||||
local env_val=$(tmux show-environment | grep --color=never "$env_name")
|
||||
# The version below is still quite new for tmux. Uncomment this in the future :-)
|
||||
#local env_val=$(tmux show-environment "$env_name" 2>&1)
|
||||
|
||||
if [[ ! $env_val =~ "unknown variable" ]]; then
|
||||
local tmux_pwd=$(echo "$env_val" | sed 's/^.*=//')
|
||||
echo "$tmux_pwd"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export TMUX_POWERLINE_DIR_HOME="$(dirname $0)"
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/muting.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/arg_processing.sh"
|
||||
|
||||
side="$1"
|
||||
check_arg_side "$side"
|
||||
toggle_powerline_mute_status "$side"
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export TMUX_POWERLINE_DIR_HOME="$(dirname $0)"
|
||||
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/helpers.sh"
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/shell.sh"
|
||||
source "${TMUX_POWERLINE_DIR_HOME}/config/tmux.sh"
|
||||
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/arg_processing.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/formatting.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/muting.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/powerline.sh"
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/rcfile.sh"
|
||||
|
||||
# Load our rc file
|
||||
source "${TMUX_POWERLINE_DIR_LIB}/ourrcfile.sh"
|
||||
|
||||
if ! powerline_muted "$1"; then
|
||||
process_settings
|
||||
check_arg_side "$1"
|
||||
print_powerline "$1"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,18 @@
|
||||
# Build the small MPD NP program.
|
||||
# Enable debug printing with $ make -e DEBUG=1
|
||||
DEBUG=0
|
||||
CC = $(shell hash clang 2>/dev/null && echo clang || echo gcc)
|
||||
CFLAGS = -O3 -Wall -std=c99 -I /usr/include/ -D DEBUG=${DEBUG}
|
||||
LDLIBS = -lmpdclient
|
||||
XKB_LAYOUT_LDLIBS= -lX11
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: np_mpd xkb_layout
|
||||
|
||||
xkb_layout: xkb_layout.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $< $(XKB_LAYOUT_LDLIBS) -o $@
|
||||
|
||||
clean:
|
||||
$(RM) np_mpd
|
||||
$(RM) xkb_layout
|
||||
@@ -0,0 +1,148 @@
|
||||
# LICENSE This code is not under the same license as the rest of the project as it's "stolen". It's cloned from https://github.com/richoH/dotfiles/blob/master/bin/battery and just some modifications are done so it works for my laptop. Check that URL for more recent versions.
|
||||
|
||||
TMUX_POWERLINE_SEG_BATTERY_TYPE_DEFAULT="percentage"
|
||||
TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS_DEFAULT=5
|
||||
|
||||
HEART_FULL="♥"
|
||||
HEART_EMPTY="♡"
|
||||
|
||||
generate_segmentrc() {
|
||||
read -d '' rccontents << EORC
|
||||
# How to display battery remaining. Can be {percentage, cute}.
|
||||
export TMUX_POWERLINE_SEG_BATTERY_TYPE="${TMUX_POWERLINE_SEG_BATTERY_TYPE_DEFAULT}"
|
||||
# How may hearts to show if cute indicators are used.
|
||||
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS_DEFAULT}"
|
||||
EORC
|
||||
echo "$rccontents"
|
||||
}
|
||||
|
||||
run_segment() {
|
||||
__process_settings
|
||||
if shell_is_osx; then
|
||||
battery_status=$(__battery_osx)
|
||||
else
|
||||
battery_status=$(__battery_linux)
|
||||
fi
|
||||
[ -z "$battery_status" ] && return
|
||||
|
||||
case "$TMUX_POWERLINE_SEG_BATTERY_TYPE" in
|
||||
"percentage")
|
||||
output="${HEART_FULL} ${battery_status}%"
|
||||
;;
|
||||
"cute")
|
||||
output=$(__cutinate $battery_status)
|
||||
esac
|
||||
if [ -n "$output" ]; then
|
||||
echo "$output"
|
||||
fi
|
||||
}
|
||||
|
||||
__process_settings() {
|
||||
if [ -z "$TMUX_POWERLINE_SEG_BATTERY_TYPE" ]; then
|
||||
export TMUX_POWERLINE_SEG_BATTERY_TYPE="${TMUX_POWERLINE_SEG_BATTERY_TYPE_DEFAULT}"
|
||||
fi
|
||||
if [ -z "$TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS" ]; then
|
||||
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS_DEFAULT}"
|
||||
fi
|
||||
}
|
||||
|
||||
__battery_osx() {
|
||||
ioreg -c AppleSmartBattery -w0 | \
|
||||
grep -o '"[^"]*" = [^ ]*' | \
|
||||
sed -e 's/= //g' -e 's/"//g' | \
|
||||
sort | \
|
||||
while read key value; do
|
||||
case $key in
|
||||
"MaxCapacity")
|
||||
export maxcap=$value;;
|
||||
"CurrentCapacity")
|
||||
export curcap=$value;;
|
||||
"ExternalConnected")
|
||||
export extconnect=$value;;
|
||||
esac
|
||||
if [[ -n $maxcap && -n $curcap && -n $extconnect ]]; then
|
||||
if [[ "$curcap" == "$maxcap" ]]; then
|
||||
return
|
||||
fi
|
||||
charge=$(( 100 * $curcap / $maxcap ))
|
||||
if [[ "$extconnect" == "Yes" ]]; then
|
||||
echo "$charge"
|
||||
else
|
||||
if [[ $charge -lt 50 ]]; then
|
||||
echo -n "#[fg=red]"
|
||||
fi
|
||||
echo "$charge"
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
__battery_linux() {
|
||||
case "$SHELL_PLATFORM" in
|
||||
"linux")
|
||||
BATPATH=/sys/class/power_supply/BAT0
|
||||
if [ ! -d $BATPATH ]; then
|
||||
BATPATH=/sys/class/power_supply/BAT1
|
||||
fi
|
||||
STATUS=$BATPATH/status
|
||||
BAT_FULL=$BATPATH/charge_full
|
||||
if [ ! -r $BAT_FULL ]; then
|
||||
BAT_FULL=$BATPATH/energy_full
|
||||
fi
|
||||
BAT_NOW=$BATPATH/charge_now
|
||||
if [ ! -r $BAT_NOW ]; then
|
||||
BAT_NOW=$BATPATH/energy_now
|
||||
fi
|
||||
|
||||
if [ "$1" = `cat $STATUS` -o "$1" = "" ]; then
|
||||
__linux_get_bat
|
||||
fi
|
||||
;;
|
||||
"bsd")
|
||||
STATUS=`sysctl -n hw.acpi.battery.state`
|
||||
case $1 in
|
||||
"Discharging")
|
||||
if [ $STATUS -eq 1 ]; then
|
||||
__freebsd_get_bat
|
||||
fi
|
||||
;;
|
||||
"Charging")
|
||||
if [ $STATUS -eq 2 ]; then
|
||||
__freebsd_get_bat
|
||||
fi
|
||||
;;
|
||||
"")
|
||||
__freebsd_get_bat
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
__cutinate() {
|
||||
perc=$1
|
||||
inc=$(( 100 / $TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS ))
|
||||
|
||||
|
||||
for i in `seq $TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS`; do
|
||||
if [ $perc -lt 100 ]; then
|
||||
echo -n $HEART_EMPTY
|
||||
else
|
||||
echo -n $HEART_FULL
|
||||
fi
|
||||
echo -n " "
|
||||
perc=$(( $perc + $inc ))
|
||||
done
|
||||
}
|
||||
|
||||
__linux_get_bat() {
|
||||
bf=$(cat $BAT_FULL)
|
||||
bn=$(cat $BAT_NOW)
|
||||
echo $(( 100 * $bn / $bf ))
|
||||
}
|
||||
|
||||
__freebsd_get_bat() {
|
||||
echo "$(sysctl -n hw.acpi.battery.life)"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
# Prints the CPU usage: user% sys% idle.
|
||||
|
||||
run_segment() {
|
||||
if shell_is_linux; then
|
||||
cpu_line=$(top -b -n 1 | grep "Cpu(s)" )
|
||||
cpu_user=$(echo "$cpu_line" | grep -Po "(\d+(.\d+)?)(?=%?\s?(us(er)?))")
|
||||
cpu_system=$(echo "$cpu_line" | grep -Po "(\d+(.\d+)?)(?=%?\s?(sys?))")
|
||||
cpu_idle=$(echo "$cpu_line" | grep -Po "(\d+(.\d+)?)(?=%?\s?(id(le)?))")
|
||||
elif shell_is_osx; then
|
||||
cpus_line=$(top -e -l 1 | grep "CPU usage:" | sed 's/CPU usage: //')
|
||||
cpu_user=$(echo "$cpus_line" | awk '{print $1}' | sed 's/%//' )
|
||||
cpu_system=$(echo "$cpus_line" | awk '{print $3}'| sed 's/%//' )
|
||||
cpu_idle=$(echo "$cpus_line" | awk '{print $5}' | sed 's/%//' )
|
||||
fi
|
||||
|
||||
if [ -n "$cpu_user" ] && [ -n "$cpu_system" ] && [ -n "$cpu_idle" ]; then
|
||||
echo "${cpu_user}, ${cpu_system}, ${cpu_idle}" | awk -F', ' '{printf("%5.1f,%5.1f,%5.1f",$1,$2,$3)}'
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# Print the current date.
|
||||
|
||||
TMUX_POWERLINE_SEG_DATE_FORMAT_DEFAULT="%F"
|
||||
|
||||
generate_segmentrc() {
|
||||
read -d '' rccontents << EORC
|
||||
# date(1) format for the date. If you don't, for some reason, like ISO 8601 format you might want to have "%D" or "%m/%d/%Y".
|
||||
export TMUX_POWERLINE_SEG_DATE_FORMAT="${TMUX_POWERLINE_SEG_DATE_FORMAT_DEFAULT}"
|
||||
EORC
|
||||
echo "$rccontents"
|
||||
}
|
||||
|
||||
__process_settings() {
|
||||
if [ -z "$TMUX_POWERLINE_SEG_DATE_FORMAT" ]; then
|
||||
export TMUX_POWERLINE_SEG_DATE_FORMAT="${TMUX_POWERLINE_SEG_DATE_FORMAT_DEFAULT}"
|
||||
fi
|
||||
}
|
||||
|
||||
run_segment() {
|
||||
__process_settings
|
||||
date +"$TMUX_POWERLINE_SEG_DATE_FORMAT"
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Prints the name of the current day.
|
||||
|
||||
run_segment() {
|
||||
date +"%a"
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
# Prints the most recent earthquake (currently only supports japan)
|
||||
# It prints the location, time, and magnitude if the quake happened within
|
||||
# a timelimit and magnitude threshold
|
||||
|
||||
earthquake_symbol='#[fg=colour1]~'
|
||||
|
||||
# The update period in seconds.
|
||||
update_period=600
|
||||
|
||||
TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER_DEFAULT="goo"
|
||||
TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD_DEFAULT="600"
|
||||
TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW_DEFAULT="60"
|
||||
TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT_DEFAULT='(%H:%M)'
|
||||
TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE_DEFAULT='3'
|
||||
|
||||
generate_segmentrc() {
|
||||
read -d '' rccontents << EORC
|
||||
# The data provider to use. Currently only "goo" is supported.
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER="${TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER_DEFAULT}"
|
||||
# How often to update the earthquake data in seconds.
|
||||
# Note: This is not an early warning detector, use this
|
||||
# to be informed about recent earthquake magnitudes in your
|
||||
# area. If this is too often, goo may decide to ban you form
|
||||
# their server
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD="${TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD_DEFAULT}"
|
||||
# Only display information when earthquakes are within this many minutes
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW="${TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW_DEFAULT}"
|
||||
# Display time with this format
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT='${TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT_DEFAULT}'
|
||||
# Display only if magnitude is greater or equal to this number
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE="${TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE_DEFAULT}"
|
||||
EORC
|
||||
echo "$rccontents"
|
||||
}
|
||||
|
||||
run_segment() {
|
||||
__process_settings
|
||||
local tmp_file="${TMUX_POWERLINE_DIR_TEMPORARY}/earthquake.txt"
|
||||
local earthquake
|
||||
case "$TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER" in
|
||||
"goo") earthquake=$(__goo_earthquake) ;;
|
||||
*)
|
||||
echo "Unknown earthquake-information provider [${$TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER}]";
|
||||
return 1
|
||||
esac
|
||||
if [ -n "$earthquake" ]; then
|
||||
echo "$earthquake_symbol #[fg=colour237]${earthquake}"
|
||||
fi
|
||||
}
|
||||
|
||||
__process_settings() {
|
||||
if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER" ]; then
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER="${TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER_DEFAULT}"
|
||||
fi
|
||||
if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD" ]; then
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD="${TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD_DEFAULT}"
|
||||
fi
|
||||
if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW" ]; then
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW="${TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW_DEFAULT}"
|
||||
fi
|
||||
if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT" ]; then
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT="${TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT_DEFAULT}"
|
||||
fi
|
||||
if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE" ]; then
|
||||
export TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE="${TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE_DEFAULT}"
|
||||
fi
|
||||
}
|
||||
|
||||
__goo_earthquake() {
|
||||
location=""
|
||||
magnitude=""
|
||||
magnitude_number=""
|
||||
timestamp=""
|
||||
if [[ -f "$tmp_file" ]]; then
|
||||
if shell_is_osx || shell_is_bsd; then
|
||||
last_update=$(stat -f "%m" ${tmp_file})
|
||||
elif shell_is_linux; then
|
||||
last_update=$(stat -c "%Y" ${tmp_file})
|
||||
fi
|
||||
time_now=$(date +%s)
|
||||
|
||||
up_to_date=$(echo "(${time_now}-${last_update}) < ${update_period}" | bc)
|
||||
if [ "$up_to_date" -eq 1 ]; then
|
||||
__read_tmp_file
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$magnitude" ]; then
|
||||
# get the rss file, convert encoding to UTF-8, then delete windows carriage-returns
|
||||
earthquake_data=$(curl --max-time 4 -s "http://weather.goo.ne.jp/earthquake/index.rdf" | iconv -f EUC-JP -t UTF-8 | tr -d "\r")
|
||||
if [ "$?" -eq "0" ]; then
|
||||
# This rss feed is not very clean or easy to use, but we will use it because
|
||||
# this is all that can be found for now
|
||||
|
||||
# we grab the data from the title of the first item (most recent earthquake)
|
||||
earthquake_data=${earthquake_data#*item\><title>}
|
||||
# end our data at the end of the approx. time
|
||||
earthquake_data=${earthquake_data%%頃*}
|
||||
|
||||
# pluck our data
|
||||
location=$(echo $earthquake_data | awk '{print $2}')
|
||||
magnitude=$(echo $earthquake_data | awk '{print $4}')
|
||||
timestamp=${earthquake_data#*\(}
|
||||
|
||||
__convert_jp_magnitude
|
||||
__convert_jp_timestamp
|
||||
|
||||
echo $location > $tmp_file
|
||||
echo $magnitude >> $tmp_file
|
||||
echo $timestamp >> $tmp_file
|
||||
elif [ -f "$tmp_file" ]; then
|
||||
__read_tmp_file
|
||||
fi
|
||||
fi
|
||||
__convert_timestamp_to_fmt
|
||||
|
||||
# extract the numerical portion of magnitude
|
||||
magnitude_number=$(echo $magnitude | sed -e 's/+//' -e 's/-//')
|
||||
|
||||
if [ -n "$magnitude" ]; then
|
||||
if __check_alert_time_window && __check_min_magnitude ; then
|
||||
echo "${location}${timestamp_fmt}:#[fg=colour0]${magnitude}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
__convert_jp_magnitude() {
|
||||
magnitude=${magnitude#震度}
|
||||
# simplify high-lower designation (only used in extreme cases: above 4)
|
||||
if [[ "$magnitude" == *弱 ]] ; then
|
||||
magnitude="-${magnitude%弱}"
|
||||
elif [[ "$magnitude" == *強 ]] ; then
|
||||
magnitude="+${magnitude%強}"
|
||||
fi
|
||||
}
|
||||
|
||||
__check_alert_time_window() {
|
||||
[[ $(( ( $(date +%s) - $timestamp ) / 60 )) -lt $TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW ]]
|
||||
}
|
||||
|
||||
__check_min_magnitude() {
|
||||
[[ $magnitude_number -ge $TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE ]]
|
||||
}
|
||||
|
||||
__convert_jp_timestamp() {
|
||||
if shell_is_osx ; then
|
||||
timestamp=$(date -j -f "%Y年%m月%d日 %H時%M分" "$timestamp" +"%s")
|
||||
else
|
||||
timestamp=$(echo $timestamp | $sed -e 's/年/-/' -e 's/月/-/' -e 's/日//' -e 's/時/:/' -e 's/分//')
|
||||
timestamp=$(date -d "$timestamp" +"%s")
|
||||
fi
|
||||
}
|
||||
|
||||
__convert_timestamp_to_fmt() {
|
||||
if shell_is_osx ; then
|
||||
timestamp_fmt=$(date -r "$timestamp" +"$TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT")
|
||||
else
|
||||
timestamp_fmt=$(date -d "$timestamp" +"$TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT")
|
||||
fi
|
||||
}
|
||||
|
||||
__read_tmp_file() {
|
||||
if [ ! -f "$tmp_file" ]; then
|
||||
return
|
||||
fi
|
||||
IFS_bak="$IFS"
|
||||
IFS=$'\n'
|
||||
lines=($(cat ${tmp_file}))
|
||||
IFS="$IFS_bak"
|
||||
location="${lines[0]}"
|
||||
magnitude="${lines[1]}"
|
||||
timestamp="${lines[2]}"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user