Updated scripts, some removed and added scripzs to pupulate nzb_guid

This commit is contained in:
Darko
2014-04-28 14:01:35 +02:00
parent 330c62c5f3
commit 2e304e91c8
4 changed files with 104 additions and 72 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ require_once(dirname(__FILE__) . "/../lib/showsleep.php");
require_once(dirname(__FILE__) . "/../lib/functions.php");
$version = "0.3r1120";
$version = "0.3r1121";
$db = new DB();
$functions = new Functions();
+4 -4
View File
@@ -5,10 +5,10 @@ require_once(WWW_DIR . '/lib/nntp.php');
require_once(WWW_DIR . '/lib/binaries.php');
require_once(WWW_DIR . '/lib/category.php');
require_once(WWW_DIR . '/lib/groups.php');
require_once(WWW_DIR . '/lib/nzb.php');
require_once(dirname(__FILE__) . '/../lib/ColorCLI.php');
require_once(dirname(__FILE__) . '/../lib/namecleaner.php');
require_once(dirname(__FILE__) . '/../lib/consoletools.php');
require_once(dirname(__FILE__) . '/../lib/Enzebe.php');
$c = new ColorCLI();
@@ -90,16 +90,16 @@ function copyNZBforImport($relguid, $nzb)
{
$s = new Sites();
$site = $s->get();
$nzb = new NZB();
$nzb = new Enzebe();
$sitenzbpath = $site->nzbpath;
$path =
$nzb->getNZBPath($relguid, $sitenzbpath, true);
$nzb->getNZBPath($relguid, true);
$fp = gzopen($path, 'w5');
if ($fp && $nzb) {
$date1 = htmlspecialchars(date('F j, Y, g:i a O'), ENT_QUOTES, 'utf-8');
$article =
preg_replace(
'/dtd">\s*<nzb xmlns=/', "dtd\">\n<!-- NZB Generated by: nZEDb "
'/dtd">\s*<nzb xmlns=/', "dtd\">\n<!-- NZB Generated by: newznab "
. $site->version() . ' ' . $date1 . " -->\n<nzb xmlns=", $nzb
);
+99
View File
@@ -0,0 +1,99 @@
<?php
require_once(dirname(__FILE__) . "/../bin/config.php");
require_once(WWW_DIR . "/lib/framework/db.php");
require_once("ColorCLI.php");
require_once("consoletools.php");
require_once("Enzebe.php");
require_once("functions.php");
// This script updates all releases with the guid from the nzb file. Adapted from nZEDb for newznab
$c = new ColorCLI();
if (isset($argv[1])) {
$del = false;
if (isset($argv[2])) {
$del = $argv[2];
}
create_guids($argv[1], $del);
} else {
exit($c->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)
{
$db = new DB();
$consoletools = new ConsoleTools();
$timestart = TIME();
$relcount = $deleted = 0;
$c = new ColorCLI();
if ($live == "true") {
$relrecs = $db->queryDirect(sprintf("SELECT ID, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY ID DESC"));
} else if ($live == "limited") {
$relrecs = $db->queryDirect(sprintf("SELECT ID, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY ID DESC LIMIT 10000"));
}
$total = $relrecs->rowCount();
if ($total > 0) {
echo $c->header("Creating nzb_guids for " . number_format($total) . " releases.");
$functions = new Functions();
$nzb = new Enzebe();
$reccnt = 0;
foreach ($relrecs as $relrec) {
$reccnt++;
$nzbpath = $nzb->NZBPath($relrec['guid']);
if ($nzbpath !== false) {
$nzbpath = 'compress.zlib://' . $nzbpath;
$nzbfile = @simplexml_load_file($nzbpath);
if (!$nzbfile) {
if (isset($delete) && $delete == 'delete') {
//echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n";
$functions->fastDelete($relrec['ID'], $relrec['guid']);
$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";
$functions->fastDelete($relrec['ID'], $relrec['guid']);
$deleted++;
}
continue;
}
asort($binary_names);
$segment = "";
foreach ($nzbfile->file as $file) {
if ($file["subject"] == $binary_names[0]) {
$segment = $file->segments->segment;
$nzb_guid = md5($segment);
$db->exec("UPDATE releases set nzb_guid = " . $db->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 $c->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting.");
$functions->fastDelete($relrec['ID'], $relrec['guid']);
}
}
}
if ($relcount > 0) {
echo "\n";
}
echo $c->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart));
} else {
echo $c->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart));
exit($c->info("No releases are missing the guid."));
}
}
-67
View File
@@ -1,67 +0,0 @@
<?php
require_once(dirname(__FILE__)."/../bin/config.php");
require_once(WWW_DIR."/lib/framework/db.php");
require_once(WWW_DIR."/lib/releases.php");
require_once(WWW_DIR."/lib/releaseimage.php");
require_once(WWW_DIR."/lib/nzb.php");
require_once(WWW_DIR."/lib/site.php");;
require_once("consoletools.php");
require_once("ColorCLI.php");
require_once("functions.php");
//This script is ported from nZEDb and adapted for newznab.
$c = new ColorCLI();
if (!isset($agrv[1]) && !is_numeric($argv[1])) {
exit($c->error("\nIncorrect argument suppplied. This script will delete all duplicate releases matching on name, fromname, groupid and size.\n\n"
. "php $argv[0] 10 ...: To delete all duplicates added within the last 10 hours.\n"
. "php $argv[0] 0 ...: To delete all duplicates.\n"
. "php $argv[0] 10 dupes/ ...: To delete all duplicates added within the last 10 hours and save a copy of the nzb to dupes folder.\n"));
}
$crosspostt = $argv[1];
$db = new DB();
$c = new ColorCLI();
$functions = new Functions();
$releases = new Releases();
$count = $total = 0;
$nzb = new NZB();
$ri = new ReleaseImage();
$s = new Sites();
$site = $s->get();
$consoleTools = new ConsoleTools();
if ($crosspostt != 0) {
$query = sprintf('SELECT ID, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name, fromname, groupID, size HAVING COUNT(*) > 1 ORDER BY ID DESC', $crosspostt);
}
else {
$query = sprintf('SELECT ID, guid FROM releases GROUP BY name, fromname, groupID, size HAVING COUNT(*) > 1 ORDER BY ID DESC');
}
do {
$resrel = $db->queryDirect($query);
$total = $resrel->rowCount();
echo $c->header(number_format($total) . " Releases have Duplicates");
if (count($resrel) > 0) {
foreach ($resrel as $rowrel) {
$nzbpath = $nzb->getNZBPath($rowrel['guid'], $site->nzbpath, false);
if (isset($argv[2]) && is_dir($argv[2])) {
$path = $argv[2];
if (substr($path, strlen($path) - 1) != '/') {
$path = $path . "/";
}
if (!file_exists($path . $rowrel['guid'] . ".nzb.gz") && file_exists($nzbpath)) {
if (@copy($nzbpath, $path . $rowrel['guid'] . ".nzb.gz") !== true) {
exit("\n" . $c->error("\nUnable to write " . $path . $rowrel['guid'] . ".nzb.gz"));
}
}
}
if ($functions->fastDelete($rowrel['ID'], $rowrel['guid'], $site) !== false) {
$consoleTools->overWritePrimary('Deleted: ' . number_format(++$count) . " Duplicate Releases");
}
}
}
echo "\n\n";
$consoleTools = new ConsoleTools();
} while ($total > 0);
echo $c->header("\nDeleted ". number_format($count) . " Duplicate Releases");