Exemple #1
0
function categorizeRelease($where, $update = true, $echooutput = false)
{
    global $pdo;
    $cat = new Categorize(['Settings' => $pdo]);
    $pdo->log = new ColorCLI();
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $relcount = $chgcount = 0;
    echo $pdo->log->primary("SELECT id, searchname, group_id, categoryid FROM releases " . $where);
    $resrel = $pdo->queryDirect("SELECT id, searchname, group_id, categoryid FROM releases " . $where);
    $total = $resrel->rowCount();
    if ($total > 0) {
        foreach ($resrel as $rowrel) {
            $catId = $cat->determineCategory($rowrel['group_id'], $rowrel['searchname']);
            if ($rowrel['categoryid'] != $catId) {
                if ($update === true) {
                    $pdo->queryExec(sprintf("\n\t\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\t\tSET iscategorized = 1,\n\t\t\t\t\t\t\t\tvideos_id = 0,\n\t\t\t\t\t\t\t\ttv_episodes_id = 0,\n\t\t\t\t\t\t\t\timdbid = NULL,\n\t\t\t\t\t\t\t\tmusicinfoid = NULL,\n\t\t\t\t\t\t\t\tconsoleinfoid = NULL,\n\t\t\t\t\t\t\t\tgamesinfo_id = 0,\n\t\t\t\t\t\t\t\tbookinfoid = NULL,\n\t\t\t\t\t\t\t\tanidbid = NULL,\n\t\t\t\t\t\t\t\txxxinfo_id = 0,\n\t\t\t\t\t\t\t\tcategoryid = %d\n\t\t\t\t\t\t\tWHERE 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;
}
Exemple #2
0
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, group_id, categoryid, dehashstatus FROM releases WHERE preid = 0 AND ishashed = 1');
    } else {
        if (isset($argv[1]) && $argv[1] === "full") {
            $res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, group_id, categoryid, dehashstatus FROM releases WHERE categoryid = 7020 AND ishashed = 1 AND dehashstatus BETWEEN -6 AND 0');
        } else {
            if (isset($argv[1]) && is_numeric($argv[1])) {
                $res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, group_id, categoryid, dehashstatus FROM releases WHERE categoryid = 7020 AND ishashed = 1 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.");
    }
}
Exemple #3
0
 /**
  * Categorizes releases.
  *
  * @param string $type  name or searchname | Categorize using the search name or subject.
  * @param string $where Optional "where" query parameter.
  *
  * @return int Quantity of categorized releases.
  * @access public
  */
 public function categorizeRelease($type, $where = '')
 {
     $cat = new Categorize(['Settings' => $this->pdo]);
     $categorized = $total = 0;
     $releases = $this->pdo->queryDirect(sprintf('SELECT id, %s, group_id FROM releases %s', $type, $where));
     if ($releases && $releases->rowCount()) {
         $total = $releases->rowCount();
         foreach ($releases as $release) {
             $catId = $cat->determineCategory($release['group_id'], $release[$type]);
             $this->pdo->queryExec(sprintf('UPDATE releases SET categoryid = %d, iscategorized = 1 WHERE id = %d', $catId, $release['id']));
             $categorized++;
             if ($this->echoCLI) {
                 $this->consoleTools->overWritePrimary('Categorizing: ' . $this->consoleTools->percentString($categorized, $total));
             }
         }
     }
     if ($this->echoCLI !== false && $categorized > 0) {
         echo PHP_EOL;
     }
     return $categorized;
 }
Exemple #4
0
    if ($titles instanceof \Traversable) {
        foreach ($titles as $row) {
            $matched = 0;
            $searched = 0;
            $matched = $namefixer->matchPredbFT($row, 1, 1, true, $show);
            //echo "Pre Title " . $row['title'] . " is translated to search string: ";
            //echo $pdo->log->header($matched);
            if ($matched > 0) {
                $searched = 1;
                $counted++;
            } elseif ($matched < 0) {
                $searched = -6;
                echo "*";
            } else {
                $searched = $row['searched'] - 1;
                echo ".";
            }
            $pdo->queryExec(sprintf("UPDATE predb SET searched = %d WHERE id = %d", $searched, $row['preid']));
            if (!isset($argv[2]) || $argv[2] !== 'show') {
                $consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $consoletools->percentString(++$counter, $total));
            }
        }
    }
    if ($total > 0) {
        echo $pdo->log->header("\nRenamed " . number_format($counted) . " releases in " . $consoletools->convertTime(TIME() - $timestart) . ".");
    } else {
        echo $pdo->log->info("\nNothing to do.");
    }
} else {
    echo $pdo->log->info("No work to process.\n");
}
            $pdo->queryExec("TRUNCATE TABLE movieinfo");
            $pdo->queryExec("TRUNCATE TABLE video_data");
            $pdo->queryExec("TRUNCATE TABLE musicinfo");
            $pdo->queryExec("TRUNCATE TABLE bookinfo");
            $pdo->queryExec("TRUNCATE TABLE release_nfos");
            $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("\n\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\tSET consoleinfoid = NULL, gamesinfo_id = 0, imdbid = NULL, musicinfoid = NULL,\n\t\t\t\t\t\t\tbookinfoid = NULL, rageid = -1, xxxinfo_id = 0, passwordstatus = -1, haspreview = -1,\n\t\t\t\t\t\t\tjpgstatus = 0, videostatus = 0, audiostatus = 0, nfostatus = -1\n\t\t\t\t\t\tWHERE 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";
Exemple #6
0
    public function getPreFileNames($args = [])
    {
        $timestart = time();
        $counter = $counted = 0;
        $limit = $orderby = '';
        $show = isset($args[2]) && $args[2] === 'show' ? 1 : 0;
        if (isset($args[1]) && is_numeric($args[1])) {
            $orderby = "ORDER BY r.id DESC";
            $limit = "LIMIT " . $args[1];
        }
        echo $this->pdo->log->header("\nMatch PreFiles ({$args[1]}) Started at " . date('g:i:s'));
        echo $this->pdo->log->primary("Matching predb filename to cleaned release_files.name.\n");
        $query = $this->pdo->queryDirect(sprintf('
							SELECT r.id AS releaseid, r.name, r.searchname,
								r.group_id, r.categoryid,
								rf.name AS filename
							FROM releases r
							INNER JOIN release_files rf ON r.id = rf.releaseid
							AND rf.name IS NOT NULL
							WHERE r.preid = 0
							GROUP BY r.id
							%s %s', $orderby, $limit));
        if ($query !== false) {
            $total = $query->rowCount();
            if ($total > 0 && $query instanceof \Traversable) {
                echo $this->pdo->log->header("\n" . number_format($total) . ' releases to process.');
                foreach ($query as $row) {
                    $success = $this->matchPredbFiles($row, 1, 1, true, $show);
                    if ($success === 1) {
                        $counted++;
                    }
                    if ($show === 0) {
                        $this->consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $this->consoletools->percentString(++$counter, $total));
                    }
                }
                echo $this->pdo->log->header("\nRenamed " . number_format($counted) . " releases in " . $this->consoletools->convertTime(TIME() - $timestart) . ".");
            } else {
                echo $this->pdo->log->info("\nNothing to do.");
            }
        }
    }
Exemple #7
0
    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']);
Exemple #8
0
            exit($pdo->log->info("You have no releases in the DB."));
        }
    } else {
        if (isset($argv[1]) && $argv[1] == "reset") {
            $pdo = new Settings();
            $res = $pdo->query("SELECT releases.id, releases.name, releases.fromname, releases.size, groups.name AS gname FROM releases INNER JOIN groups ON releases.group_id = groups.id");
            if (count($res) > 0) {
                echo $pdo->log->header("Going to reset search names, this can take a while.");
                $done = 0;
                $timestart = time();
                $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
                foreach ($res as $row) {
                    $rc = new ReleaseCleaning($pdo);
                    $newname = $rc->releaseCleaner($row['name'], $row['fromname'], $row['size'], $row['gname']);
                    if (is_array($newname)) {
                        $newname = $newname['cleansubject'];
                    }
                    $newname = $pdo->escapeString($newname);
                    $pdo->queryExec(sprintf("UPDATE releases SET searchname = %s where id = %d", $newname, $row['id']));
                    $sphinx->updateRelease($row['id']);
                    $done++;
                    $consoletools->overWritePrimary("Renaming:" . $consoletools->percentString($done, count($res)));
                }
                $timenc = $consoletools->convertTime(TIME() - $timestart);
                echo $pdo->log->header($done . " releases renamed in " . $timenc);
            }
        } else {
            exit($pdo->log->error("\nThis script runs the subject names through namecleaner to create a clean search name, it also recategorizes and runs the releases through namefixer.\n" . "php resetSearchname.php full              ...: To run this, recategorize and refix release names on all releases.\n" . "php resetSearchname.php limited           ...: To run this on releases that have not had their names fixed, then categorizing them.\n" . "php resetSearchname.php reset             ...: To just reset searchnames.\n"));
        }
    }
}
Exemple #9
0
 /**
  * Matches the hashes within the predb table to release files and subjects (names) which are hashed.
  *
  * @param $time
  * @param $echo
  * @param $cats
  * @param $namestatus
  * @param $show
  *
  * @return int
  */
 public function parseTitles($time, $echo, $cats, $namestatus, $show)
 {
     $namefixer = new NameFixer(['Echo' => $this->echooutput, 'ConsoleTools' => $this->pdo->log, 'Settings' => $this->pdo]);
     $consoletools = new ConsoleTools(['ColorCLI' => $this->pdo->log]);
     $othercats = Category::getCategoryOthersGroup();
     $updated = $checked = 0;
     $tq = '';
     if ($time == 1) {
         $tq = 'AND r.adddate > (NOW() - INTERVAL 3 HOUR) ORDER BY rf.releaseid, rf.size DESC';
     }
     $ct = '';
     if ($cats == 1) {
         $ct = sprintf('AND r.categoryid IN (%s)', $othercats);
     }
     if ($this->echooutput) {
         $te = '';
         if ($time == 1) {
             $te = ' in the past 3 hours';
         }
         echo $this->pdo->log->header('Fixing search names' . $te . " using the predb hash.");
     }
     $regex = "AND (r.ishashed = 1 OR rf.ishashed = 1)";
     if ($cats === 3) {
         $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.group_id, ' . 'dehashstatus, rf.name AS filename FROM releases r ' . 'LEFT OUTER JOIN release_files rf ON r.id = rf.releaseid ' . 'WHERE nzbstatus = 1 AND dehashstatus BETWEEN -6 AND 0 AND preid = 0 %s', $regex);
     } else {
         $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.group_id, ' . 'dehashstatus, rf.name AS filename FROM releases r ' . 'LEFT OUTER JOIN release_files rf ON r.id = rf.releaseid ' . 'WHERE nzbstatus = 1 AND isrenamed = 0 AND dehashstatus BETWEEN -6 AND 0 %s %s %s', $regex, $ct, $tq);
     }
     $res = $this->pdo->queryDirect($query);
     $total = $res->rowCount();
     echo $this->pdo->log->primary(number_format($total) . " releases to process.");
     if ($res instanceof \Traversable) {
         foreach ($res as $row) {
             if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['name'], $matches)) {
                 $updated = $updated + $namefixer->matchPredbHash($matches[0], $row, $echo, $namestatus, $this->echooutput, $show);
             } else {
                 if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['filename'], $matches)) {
                     $updated = $updated + $namefixer->matchPredbHash($matches[0], $row, $echo, $namestatus, $this->echooutput, $show);
                 }
             }
             if ($show === 2) {
                 $consoletools->overWritePrimary("Renamed Releases: [" . number_format($updated) . "] " . $consoletools->percentString(++$checked, $total));
             }
         }
     }
     if ($echo == 1) {
         echo $this->pdo->log->header("\n" . $updated . " releases have had their names changed out of: " . number_format($checked) . " files.");
     } else {
         echo $this->pdo->log->header("\n" . $updated . " releases could have their names changed. " . number_format($checked) . " files were checked.");
     }
     return $updated;
 }
Exemple #10
0
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 . ", group_id FROM releases " . $where);
    $resrel = $pdo->queryDirect("SELECT id, " . $type . ", group_id FROM releases " . $where);
    $total = $resrel->rowCount();
    if ($total > 0) {
        foreach ($resrel as $rowrel) {
            $catId = $cat->determineCategory($rowrel['group_id'], $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;
}
Exemple #11
0
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."));
    }
}