Beispiel #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;
}
Beispiel #2
0
 /**
  * Insert the NZB details into the database.
  *
  * @param $nzbDetails
  *
  * @return bool
  *
  * @access protected
  */
 protected function insertNZB($nzbDetails)
 {
     // Make up a GUID for the release.
     $this->relGuid = $this->releases->createGUID();
     // Remove part count from subject.
     $partLess = preg_replace('/(\\(\\d+\\/\\d+\\))*$/', 'yEnc', $nzbDetails['subject']);
     // Remove added yEnc from above and anything after.
     $subject = utf8_encode(trim(preg_replace('/yEnc.*$/i', 'yEnc', $partLess)));
     $renamed = 0;
     if ($nzbDetails['useFName']) {
         // If the user wants to use the file name.. use it.
         $cleanName = $nzbDetails['useFName'];
         $renamed = 1;
     } else {
         // Pass the subject through release cleaner to get a nicer name.
         $cleanName = $this->releaseCleaner->releaseCleaner($subject, $nzbDetails['from'], $nzbDetails['totalSize'], $nzbDetails['groupName']);
         if (isset($cleanName['properlynamed'])) {
             $cleanName = $cleanName['cleansubject'];
             $renamed = isset($cleanName['properlynamed']) && $cleanName['properlynamed'] === true ? 1 : 0;
         }
     }
     $escapedSubject = $this->pdo->escapeString($subject);
     $escapedFromName = $this->pdo->escapeString($nzbDetails['from']);
     // Look for a duplicate on name, poster and size.
     $dupeCheck = $this->pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE name = %s AND fromname = %s AND size BETWEEN %s AND %s', $escapedSubject, $escapedFromName, $this->pdo->escapeString($nzbDetails['totalSize'] * 0.99), $this->pdo->escapeString($nzbDetails['totalSize'] * 1.01)));
     if ($dupeCheck === false) {
         $escapedSearchName = $this->pdo->escapeString($cleanName);
         // Insert the release into the DB.
         $relID = $this->releases->insertRelease(['name' => $escapedSubject, 'searchname' => $escapedSearchName, 'totalpart' => $nzbDetails['totalFiles'], 'group_id' => $nzbDetails['group_id'], 'guid' => $this->pdo->escapeString($this->relGuid), 'postdate' => $this->pdo->escapeString($nzbDetails['postDate']), 'fromname' => $escapedFromName, 'size' => $this->pdo->escapeString($nzbDetails['totalSize']), 'categoryid' => $this->category->determineCategory($nzbDetails['group_id'], $cleanName), 'isrenamed' => $renamed, 'reqidstatus' => 0, 'preid' => 0, 'nzbstatus' => NZB::NZB_ADDED]);
     } else {
         //$this->echoOut('This release is already in our DB so skipping: ' . $subject);
         return false;
     }
     if (isset($relID) && $relID === false) {
         $this->echoOut('ERROR: Problem inserting: ' . $subject);
         return false;
     }
     return true;
 }
Beispiel #3
0
    /**
     * Try to get a title from a Linux_2rename.sh file for alt.binaries.u4e group.
     *
     * @param string $fileLocation
     */
    protected function _processU4ETitle($fileLocation)
    {
        // Open the file for reading.
        $handle = @fopen($fileLocation, 'r');
        // Check if it failed.
        if ($handle) {
            // Loop over the file line by line.
            while (($buffer = fgets($handle, 16384)) !== false) {
                // Check if we find the word
                if (stripos($buffer, 'mkdir') !== false) {
                    // Get a new name.
                    $newName = trim(str_replace('mkdir ', '', $buffer));
                    // Check if it's a empty string or not.
                    if (empty($newName)) {
                        continue;
                    }
                    // Get a new category ID.
                    $newCategory = $this->_categorize->determineCategory($this->_release['group_id'], $newName);
                    $newTitle = $this->pdo->escapeString(substr($newName, 0, 255));
                    // Update the release with the data.
                    $this->pdo->queryExec(sprintf('UPDATE releases
							SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL,
							bookinfoid = NULL, anidbid = NULL, preid = 0, searchname = %s, isrenamed = 1, iscategorized = 1,
							proc_files = 1, categoryid = %d
							WHERE id = %d', $newTitle, $newCategory, $this->_release['id']));
                    $this->sphinx->updateRelease($this->_release['id'], $this->pdo);
                    // Echo the changed name to CLI.
                    if ($this->_echoCLI) {
                        NameFixer::echoChangedReleaseName(['new_name' => $newName, 'old_name' => $this->_release['searchname'], 'new_category' => $newCategory, 'old_category' => $this->_release['categoryid'], 'group' => $this->_release['group_id'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_processU4ETitle']);
                    }
                    // Break out of the loop.
                    break;
                }
            }
            // Close the file.
            fclose($handle);
        }
        // Delete the file.
        @unlink($fileLocation);
    }
Beispiel #4
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;
}
Beispiel #5
0
use nzedb\Categorize;
use nzedb\ConsoleTools;
use nzedb\NZB;
use nzedb\ReleaseCleaning;
use nzedb\Releases;
use nzedb\db\Settings;
$pdo = new Settings();
if (!isset($argv[1])) {
    exit($pdo->log->error("\nYou must supply a path as the first argument. Two additional, optional arguments can also be used.\n\n" . "php {$argv['0']} /path/to/import true 1000            ...: To import using the filename as release searchname, limited to 1000\n" . "php {$argv['0']} /path/to/import false                ...: To import using the subject as release searchname\n"));
}
$consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$binaries = new Binaries(['Settings' => $pdo]);
$crosspostt = $pdo->getSetting('crossposttime');
$crosspostt = !empty($crosspostt) ? $crosspostt : 2;
$releasecleaning = new ReleaseCleaning($pdo);
$categorize = new Categorize(['Settings' => $pdo]);
$nzb = new NZB($pdo);
$releases = new Releases(['Settings' => $pdo]);
$nzbsperhour = $nzbSkipped = $maxtoprocess = 0;
if (isset($argv[2]) && is_numeric($argv[2])) {
    exit($pdo->log->error("\nTo use a max number to process, it must be the third argument. \nTo run:\nphp nzb-import.php /path [true, false] 1000\n"));
}
if (!isset($argv[2])) {
    $pieces = explode("   ", $argv[1]);
    $usenzbname = isset($pieces[1]) && $pieces[1] == 'true' ? true : false;
    $path = $pieces[0];
} else {
    $path = $argv[1];
    $usenzbname = isset($argv[2]) && $argv[2] == 'true' ? true : false;
}
if (isset($argv[3]) && is_numeric($argv[3])) {
Beispiel #6
0
    /**
     * Create releases from complete collections.
     *
     * @param int|string $groupID (optional)
     *
     * @return int
     * @access public
     */
    public function createReleases($groupID)
    {
        $startTime = time();
        $group = $this->groups->getCBPTableNames($this->tablePerGroup, $groupID);
        $categorize = new Categorize(['Settings' => $this->pdo]);
        $returnCount = $duplicate = 0;
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create releases from complete collections."));
        }
        $this->pdo->ping(true);
        $collections = $this->pdo->queryDirect(sprintf('
				SELECT SQL_NO_CACHE %s.*, groups.name AS gname
				FROM %s
				INNER JOIN groups ON %s.group_id = groups.id
				WHERE %s %s.filecheck = %d
				AND filesize > 0 LIMIT %d', $group['cname'], $group['cname'], $group['cname'], !empty($groupID) ? ' group_id = ' . $groupID . ' AND ' : ' ', $group['cname'], self::COLLFC_SIZED, $this->releaseCreationLimit));
        if ($this->echoCLI && $collections !== false) {
            echo $this->pdo->log->primary($collections->rowCount() . " Collections ready to be converted to releases.");
        }
        if ($collections instanceof \Traversable) {
            $preDB = new PreDb(['Echo' => $this->echoCLI, 'Settings' => $this->pdo]);
            foreach ($collections as $collection) {
                $cleanRelName = $this->pdo->escapeString(utf8_encode(str_replace(['#', '@', '$', '%', '^', '§', '¨', '©', 'Ö'], '', $collection['subject'])));
                $fromName = $this->pdo->escapeString(utf8_encode(trim($collection['fromname'], "'")));
                // Look for duplicates, duplicates match on releases.name, releases.fromname and releases.size
                // A 1% variance in size is considered the same size when the subject and poster are the same
                $dupeCheck = $this->pdo->queryOneRow(sprintf("\n\t\t\t\t\t\tSELECT SQL_NO_CACHE id\n\t\t\t\t\t\tFROM releases\n\t\t\t\t\t\tWHERE name = %s\n\t\t\t\t\t\tAND fromname = %s\n\t\t\t\t\t\tAND size BETWEEN '%s'\n\t\t\t\t\t\tAND '%s'", $cleanRelName, $fromName, $collection['filesize'] * 0.99, $collection['filesize'] * 1.01));
                if ($dupeCheck === false) {
                    $cleanedName = $this->releaseCleaning->releaseCleaner($collection['subject'], $collection['fromname'], $collection['filesize'], $collection['gname']);
                    if (is_array($cleanedName)) {
                        $properName = $cleanedName['properlynamed'];
                        $preID = isset($cleanerName['predb']) ? $cleanerName['predb'] : false;
                        $isReqID = isset($cleanerName['requestid']) ? $cleanerName['requestid'] : false;
                        $cleanedName = $cleanedName['cleansubject'];
                    } else {
                        $properName = true;
                        $isReqID = $preID = false;
                    }
                    if ($preID === false && $cleanedName !== '') {
                        // try to match the cleaned searchname to predb title or filename here
                        $preMatch = $preDB->matchPre($cleanedName);
                        if ($preMatch !== false) {
                            $cleanedName = $preMatch['title'];
                            $preID = $preMatch['preid'];
                            $properName = true;
                        }
                    }
                    $releaseID = $this->releases->insertRelease(['name' => $cleanRelName, 'searchname' => $this->pdo->escapeString(utf8_encode($cleanedName)), 'totalpart' => $collection['totalfiles'], 'group_id' => $collection['group_id'], 'guid' => $this->pdo->escapeString($this->releases->createGUID($cleanRelName)), 'postdate' => $this->pdo->escapeString($collection['date']), 'fromname' => $fromName, 'size' => $collection['filesize'], 'categoryid' => $categorize->determineCategory($collection['group_id'], $cleanedName), 'isrenamed' => $properName === true ? 1 : 0, 'reqidstatus' => $isReqID === true ? 1 : 0, 'preid' => $preID === false ? 0 : $preID, 'nzbstatus' => NZB::NZB_NONE]);
                    if ($releaseID !== false) {
                        // Update collections table to say we inserted the release.
                        $this->pdo->queryExec(sprintf('
								UPDATE %s
								SET filecheck = %d, releaseid = %d
								WHERE id = %d', $group['cname'], self::COLLFC_INSERTED, $releaseID, $collection['id']));
                        $returnCount++;
                        if ($this->echoCLI) {
                            echo "Added {$returnCount} releases.\r";
                        }
                    }
                } else {
                    // The release was already in the DB, so delete the collection.
                    $this->pdo->queryExec(sprintf('
							DELETE c, b, p FROM %s c
							INNER JOIN %s b ON(c.id=b.collection_id)
							STRAIGHT_JOIN %s p ON(b.id=p.binaryid)
							WHERE c.collectionhash = %s', $group['cname'], $group['bname'], $group['pname'], $this->pdo->escapeString($collection['collectionhash'])));
                    $duplicate++;
                }
            }
        }
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . number_format($returnCount) . ' Releases added and ' . number_format($duplicate) . ' duplicate collections deleted in ' . $this->consoleTools->convertTime(time() - $startTime)), true);
        }
        return ['added' => $returnCount, 'dupes' => $duplicate];
    }