From a1489aa5085dccdf3a2120b9cd4ecb037a9570ea Mon Sep 17 00:00:00 2001 From: Darko Date: Wed, 15 Jan 2014 14:13:50 +0100 Subject: [PATCH] Update to jb_fix_names.php and change in monitor --- bin/monitor.php | 4 +- test/jb_fix_names.php | 181 ++++++++++++++++++++++++------------------ 2 files changed, 106 insertions(+), 79 deletions(-) diff --git a/bin/monitor.php b/bin/monitor.php index 26312d2b8..321539104 100644 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -5,7 +5,7 @@ require(WWW_DIR.'/lib/postprocess.php'); require_once (WWW_DIR.'/lib/site.php'); require_once("../test/ColorCLI.php"); -$version="0.3r613"; +$version="0.3r614"; $db = new DB(); $s = new Sites(); @@ -1398,7 +1398,7 @@ if ($array ['FIXRELEASES'] = "true") { if (( $array['MAX_LOAD'] >= get_load()) && (( TIME() - $time27 ) >= $array['FIXRELEASES_TIMER'] ) && ( $array['FIXRELEASES'] == "true" )) { $color = get_color(); $log = writelog($panes4[0]); - shell_exec("$_tmux respawnp -t {$array['TMUX_SESSION']}:4.0 'echo \"\033[38;5;\"$color\"m\" && $ds1 $panes4[0] $ds2 && cd $_test && $_php fixReleaseNames.php 1 true other yes show 2>&1 $log && $_php fixReleaseNames.php 3 true other yes show 2>&1 $log && $_php fixReleaseNames.php 5 true other yes show 2>&1 $log && $_php fixReleaseNames.php 7 true other yes show 2>&1 $log && $_php hash_decrypt.php 1000 2>&1 $log && $_php jb_fix_names.php 2 2>&1 $log echo \" \033[1;0;33m\" && $ds1 $panes4[0] $ds3' 2>&1 1> /dev/null"); + shell_exec("$_tmux respawnp -t {$array['TMUX_SESSION']}:4.0 'echo \"\033[38;5;\"$color\"m\" && $ds1 $panes4[0] $ds2 && cd $_test && $_php fixReleaseNames.php 1 true other yes show 2>&1 $log && $_php fixReleaseNames.php 3 true other yes show 2>&1 $log && $_php fixReleaseNames.php 5 true other yes show 2>&1 $log && $_php fixReleaseNames.php 7 true other yes show 2>&1 $log && $_php hash_decrypt.php 1000 2>&1 $log && $_php jb_fix_names.php 6 show 2>&1 $log echo \" \033[1;0;33m\" && $ds1 $panes4[0] $ds3' 2>&1 1> /dev/null"); $time27 = TIME();} elseif ( $array['FIXRELEASES'] != "true" ) { $color = get_color(); diff --git a/test/jb_fix_names.php b/test/jb_fix_names.php index 530bac890..04ba5fff9 100644 --- a/test/jb_fix_names.php +++ b/test/jb_fix_names.php @@ -12,46 +12,72 @@ require_once("ColorCLI.php"); //This is jonnyboys renametopre.php script adapted for newznab. $c = new ColorCLI(); -if (!(isset($argv[1]) && ($argv[1] == "full" || is_numeric($argv[1])))) { - exit($c->error("\nThis script will attempt to rename releases using regexes first from namecleaner.php and then from this file.\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] full 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] full all 155 ...: To process all releases in groupID 155.\n")); +if (!(isset($argv[1]) && ($argv[1] == "all" || $argv[1] == "full" || is_numeric($argv[1])))) { + exit($c->error("\nThis script will attempt to rename releases using regexes first from NameCleaning.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 groupids 155 and 140.\n")); } +preName($argv, $argc); -preName($argv); - -function preName($argv) +function preName($argv, $argc) { $db = new DB(); $groups = new Groups(); $category = new Category(); $functions = new Functions(); $internal = $external = $pre = $none = 0; + $show = 2; + if ($argv[$argc - 1] === 'show') { + $show = 1; + } else if ($argv[$argc - 1] === 'bad') { + $show = 3; + } $counter = 0; $c = new ColorCLI(); - $n = "\n"; - $what = $argv[1] == 'full' ? '' : ' AND adddate > NOW() - INTERVAL ' . $argv[1] . ' HOUR'; - if (isset($argv[3]) && is_numeric($argv[3])) { - $where = ' AND groupID = ' . $argv[3]; - } else if (!isset($argv[3]) && isset($argv[2]) && is_numeric($argv[2])) { - $where = ' AND groupID = ' . $argv[2]; - } else { + $full = $all = false; + $what = $where = $why = ''; + if ($argv[1] === 'full') { + $full = true; + } else if ($argv[1] === 'all') { + $all = true; + } else if (is_numeric($argv[1])) { + $what = ' AND adddate > NOW() - INTERVAL ' . $argv[1] . ' HOUR'; + } + + if (isset($argv[1]) && is_numeric($argv[1])) { $where = ''; + $why = ' WHERE (bitwise & 260) = 256'; + } else if (isset($argv[2]) && is_numeric($argv[2]) && $full === true) { + $where = ' AND groupid = ' . $argv[2]; + $why = ' WHERE (bitwise & 260) = 256'; + } else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $full === true) { + $where = ' AND groupid IN ' . $argv[2]; + $why = ' WHERE (bitwise & 260) = 256'; + } else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $all === true) { + $where = ' AND groupid IN ' . $argv[2]; + $why = ' WHERE (bitwise & 256) = 256'; + } else if (isset($argv[2]) && is_numeric($argv[2]) && $all === true) { + $where = ' AND groupid = ' . $argv[2]; + $why = ' WHERE (bitwise & 256) = 256'; + } else if (isset($argv[2]) && is_numeric($argv[2])) { + $where = ' AND groupid = ' . $argv[2]; + $why = ' WHERE (bitwise & 260) = 256'; + } else if ($full === true) { + $why = ' WHERE ((bitwise & 260) = 256 OR categoryid between 7000 AND 7999)'; + } else if ($all === true) { + $why = ' WHERE (bitwise & 256) = 256'; + } else { + $why = ' WHERE 1=1'; } resetSearchnames(); - if (!isset($argv[2])){ - $res = $db->queryDirect("SELECT ID, name, searchname, groupID, categoryID FROM releases WHERE reqidstatus != 1 AND ((bitwise & 260) = 256 OR categoryID BETWEEN 8000 AND 8999)".$what); - } - elseif (isset($argv[2]) && is_numeric($argv[2])){ - $res = $db->queryDirect("SELECT ID, name, searchname, groupID, categoryID FROM releases WHERE reqidstatus != 1 AND ((bitwise & 260) = 256 OR categoryID BETWEEN 8000 AND 8999)".$what.$where); - } - elseif (isset($argv[1]) && $argv[1]=="full" && isset($argv[2]) && $argv[2] == "all"){ - $res = $db->queryDirect("SELECT ID, name, searchname, groupID, categoryID FROM releases WHERE (bitwise & 256) = 256" .$where); - } - $total = count($res); + $res = $db->queryDirect("SELECT ID, name, searchname, groupID, categoryID FROM releases" . $why . $what . $where); + + $total = $res->rowCount(); if ($total > 0) { $consoletools = new ConsoleTools(); @@ -114,67 +140,81 @@ function preName($argv) $run = $db->query(sprintf("UPDATE releases SET bitwise = ((bitwise & ~1)|1), searchname = %s, categoryID = %d" . $preid . "WHERE ID = %d", $db->escapeString($cleanName), $determinedcat, $row['ID'])); } - /* $groupname = $groups->getByNameByID($row["groupid"]); - $oldcatname = $category->getNameByID($row["categoryid"]); - $newcatname = $category->getNameByID($determinedcat); - echo $c->headerOver("New name: ") . $c->primary($cleanName). - $c->headerOver("Old name: ") . $c->primary($row["searchname"]). - $c->headerOver("New cat: ") . $c->primary($newcatname). - $c->headerOver("Old cat: ") . $c->primary($oldcatname). - $c->headerOver("Group: ") . $c->primary($groupname). - $c->headerOver("Method: ") . $c->primary("renametopre regexes"). - $c->headerOver("ReleaseID: ") . $c->primary($row["id"]); */ - if ($increment === true) { + if ($increment === true) { + $status = "renametopre Match"; $internal++; } else if ($predb === true) { + $status = "PreDB: Match"; $pre++; } else if ($propername === true) { + $status = "ReleaseCleaner Match"; $external++; } + if ($show === 1) { + $oldcatname = $category->getNameByID($row["categoryID"]); + $newcatname = $category->getNameByID($determinedcat); + echo $c->headerOver("\n\nNew name: ") . $c->primary($cleanName) . + $c->headerOver("Old name: ") . $c->primary($row["searchname"]) . + $c->headerOver("New cat: ") . $c->primary($newcatname) . + $c->headerOver("Old cat: ") . $c->primary($oldcatname) . + $c->headerOver("Group: ") . $c->primary($groupname) . + $c->headerOver("Method: ") . $c->primary($status) . + $c->headerOver("ReleaseID: ") . $c->primary($row["ID"]); + } } + } else if ($show === 3 && preg_match('/^\[?\d*\].+?yEnc/i', $row['name'])) { + echo $c->primary($row['name']); } } if ($cleanName == $row['name']) { $db->query(sprintf("UPDATE releases SET bitwise = ((bitwise & ~5)|5) WHERE ID = %d", $row['ID'])); } - if ($counter === 0) { - echo $c->header(" [internal][external] processed/total"); + if ($show === 2) { + $consoletools->overWritePrimary("Renamed Releases: [Internal=" . number_format($internal) . "][External=" . number_format($external) . "][Prehash=" . number_format($pre) . "] " . $consoletools->percentString( ++$counter, $total)); } - - $consoletools->overWritePrimary("Renamed Releases: [Internal=" . number_format($internal) . "][External=" . number_format($external) . "][Predb=" . number_format($pre) . "] " . $consoletools->percentString( ++$counter, $total)); } } - echo $c->header("\n" . number_format($pre) . " renamed using preDB Match\n" . number_format($external) . " renamed using NameCleaning.php\n" . number_format($internal) . " using renametopre.php\nout of " . number_format($total) . " releases.\n"); - echo $c->header("Categorizing all non-categorized releases in other->misc using usenet subject. This can take a while, be patient."); + echo $c->header("\n" . number_format($pre) . " renamed using prehash Match\n" . number_format($external) . " renamed using namecleaner.php\n" . number_format($internal) . " using jb_fix_names.php\nout of " . number_format($total) . " releases.\n"); + + if (isset($argv[1]) && $argv[1] !== "all" && !is_numeric($argv[2]) && !preg_match('/\([\d, ]+\)/', $argv[2])) { + echo $c->header("Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient."); + } else if (isset($argv[1]) && (is_numeric($argv[2]) || preg_match('/\([\d, ]+\)/', $argv[2]))) { + echo $c->header("Categorizing all non-categorized releases in ${argv[2]} 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]) && $argv[1] == "full") { - $relcount = categorizeRelease("name", "WHERE categoryID = 8010", true); - }else { - $relcount = categorizeRelease("name", "WHERE categoryID = 8010 AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true); - } + + if (isset($argv[1]) && is_numeric($argv[1])) { + $relcount = categorizeRelease("searchname","WHERE ((bitwise & 1) = 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 = categorizeRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND (bitwise & 1) = 0 ", true); + } else if (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $all === true) { + $relcount = categorizeRelease("searchname", str_replace(" AND", "WHERE", $where), true); + } else if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "full") { + $relcount = categorizeRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND (bitwise & 1) = 0 ", true); + } else if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "all") { + $relcount = categorizeRelease("searchname", str_replace(" AND", "WHERE", $where), true); + } else if (isset($argv[1]) && $argv[1] == "full") { + $relcount = categorizeRelease("searchname", "WHERE categoryID = 8010 OR (bitwise & 1) = 0", true); + } else if (isset($argv[1]) && $argv[1] == "all") { + $relcount = categorizeRelease("searchname", "", true); + } else { + $relcount = categorizeRelease("searchname", "WHERE ((bitwise & 1) = 0 OR categoryID = 8010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true); + } $consoletools = new ConsoleTools(); $time = $consoletools->convertTime(TIME() - $timestart); - echo $c->header("Finished categorizing " . number_format($relcount) . " releases in " . $time . " seconds, using the usenet subject.\n"); + echo $c->header("Finished categorizing " . number_format($relcount) . " releases in " . $time . " seconds, using the usenet subject.\n"); - echo $c->header("Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient."); - $timestart1 = TIME(); - if (isset($argv[1]) && $argv[1] == "full") { - $relcount = categorizeRelease("searchname", "WHERE categoryID = 8010", true); - }else { - $relcount = categorizeRelease("searchname", "WHERE categoryID = 8010 AND adddate > NOW() - INTERVAL ".$argv[1]." HOUR", true); - $consoletools1 = new ConsoleTools(); - $time1 = $consoletools1->convertTime(TIME() - $timestart1); - echo $c->header("Finished categorizing " . number_format($relcount) . " releases in " . $time1 . " seconds, using the searchname.\n"); resetSearchnames(); } -} function resetSearchnames() { $db = new DB(); $c = new ColorCLI(); echo $c->header("Resetting blank searchnames."); - $bad = $db->query("UPDATE releases SET searchname = name, bitwise = ((bitwise & ~5)|0) WHERE searchname = ''"); - $tot = count($bad); + $bad = $db->queryDirect("UPDATE releases SET searchname = name, bitwise = ((bitwise & ~5)|0) WHERE searchname = ''"); + $tot = $bad->rowCount(); if ($tot > 0) { echo $c->primary(number_format($tot) . " Releases had no searchname."); } @@ -210,8 +250,8 @@ function resetSearchnames() $cat = new Category(); $consoletools = new consoleTools(); $relcount = 0; - $resrel = $db->query("SELECT ID, ".$type.", groupID FROM releases ".$where); - $total = count($resrel); + $resrel = $db->queryDirect("SELECT ID, ".$type.", groupID FROM releases ".$where); + $total = $resrel->rowCount(); if ($total > 0) { foreach ($resrel as $rowrel) @@ -234,21 +274,9 @@ function releaseCleaner($subject, $groupID, $groupname) $groups = new Groups(); $db = new DB(); $match = ''; - // Get pre style name from releases.name - if (preg_match('/(\w+[\._](\w+[\._-])+\w+-\w+)/', $subject, $match)) { - $title = $db->queryOneRow("SELECT title from prehash WHERE title = " . $db->escapeString(trim($match[1]))); - if (isset($title['title'])) { - $cleanerName = $title['title']; - if (!empty($cleanerName)) { - return array("cleansubject" => $cleanerName, "properlynamed" => true, "increment" => false, "predb" => true); - } - } - } $functions = new Functions(); $groupName = $functions->getByNameByID($groupID); $namecleaning = new nameCleaning(); - $propername = true; - $cleanName = ''; $category = new Category(); $cleanerName = $namecleaning->releaseCleaner($subject, $groupname); @@ -258,7 +286,6 @@ function releaseCleaner($subject, $groupID, $groupname) return $cleanerName; } - $match = ''; if ($groupName == "alt.binaries.classic.tv.shows") { if (preg_match('/^(?P.+\d+x\d+.+)[ _-]{0,3}\[\d+\/\d+\][ _-]{0,3}("|#34;).+("|#34;)[ _-]{0,3}(yEnc|rar|par2)$/i', $subject, $match)) { $cleanerName = preg_replace('/^REQ[ _-]{0,3}/i', '', preg_replace('/\.+$/', '', trim($match['title'])));