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("\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\trageid = -1,\n\t\t\t\t\t\t\t\tseriesfull = NULL,\n\t\t\t\t\t\t\t\tseason = NULL,\n\t\t\t\t\t\t\t\tepisode = NULL,\n\t\t\t\t\t\t\t\ttvtitle = NULL,\n\t\t\t\t\t\t\t\ttvairdate = NULL,\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\txxxinfo_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\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; }
/** * 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'], 'groupid' => $nzbDetails['groupid'], '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['groupid'], $cleanName), 'isrenamed' => $renamed, 'reqidstatus' => 0, 'prehashid' => 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; }
/** * Work out the category based on the name, resets to null if no category matched. */ private function determineCategory($rel, &$foundName, &$methodused) { $categoryID = null; $category = new Categorize(); $categoryID = $category->determineCategory($rel['groupname'], $foundName); if ($methodused == 'a.b.hdtv.x264' && $rel['groupname'] == 'alt.binaries.hdtv.x264') { $categoryID = Category::CAT_MOVIE_HD; } if ($categoryID == $rel['categoryid'] || $categoryID == '7900' || ($foundName == $rel['name'] || $foundName == $rel['searchname'])) { $foundName = null; $methodused = null; } else { $foundName = str_replace(''', '', trim(html_entity_decode($foundName))); $name = str_replace(' ', '_', $foundName); $searchname = str_replace('_', ' ', $foundName); echo PHP_EOL . ColorCLI::headerOver('ReleaseID: ') . ColorCLI::primaryOver($rel['rid']) . PHP_EOL . ColorCLI::headerOver(' Group: ') . ColorCLI::primaryOver($rel['groupname']) . PHP_EOL . ColorCLI::headerOver(' Old Name: ') . ColorCLI::primaryOver($rel['name']) . PHP_EOL . ColorCLI::headerOver(' Old SearchName: ') . ColorCLI::primaryOver($rel['searchname']) . PHP_EOL . ColorCLI::headerOver(' New Name: ') . ColorCLI::primaryOver($name) . PHP_EOL . ColorCLI::headerOver(' New SearchName: ') . ColorCLI::primaryOver($searchname) . PHP_EOL . ColorCLI::headerOver(' Old Cat: ') . ColorCLI::primaryOver($rel['categoryid']) . PHP_EOL . ColorCLI::headerOver(' New Cat: ') . ColorCLI::primaryOver($categoryID) . PHP_EOL . ColorCLI::headerOver(' Method: ') . ColorCLI::primaryOver($methodused) . PHP_EOL; if (!$this->echoonly) { $this->pdo->queryExec(sprintf("update releases SET name = %s, searchname = %s, categoryid = %d, imdbid = NULL, rageid = -1, bookinfoid = NULL, musicinfoid = NULL, consoleinfoid = NULL WHERE releases.id = %d", $this->pdo->escapeString($name), $this->pdo->escapeString($searchname), $categoryID, $rel['rid'])); } $this->numupdated++; } }
/** * 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, groupid FROM releases %s', $type, $where)); if ($releases && $releases->rowCount()) { $total = $releases->rowCount(); foreach ($releases as $release) { $catId = $cat->determineCategory($release['groupid'], $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; }
<?php //This script will rerun all releases against Category.php require_once dirname(__FILE__) . '/../../www/config.php'; use newznab\db\Settings; $db = new Settings(); $category = new Categorize(); $changedcount = 0; $rescount = 0; // // [1] change for all where the regex isnt aimed at a specific category (affects most releases) // //$res = $db->queryDirect("select r.id as id, r.searchname as searchname, g.name as groupname, r.categoryID as rcat from releases r, releaseregex rr, groups g where r.regexid=rr.id and g.ID = r.groupID and rr.categoryid is null"); // // [2] update for all in a category // //$res = $db->queryDirect("select r.id as id, r.searchname as searchname, g.name as groupname, r.categoryID as rcat from releases r inner join groups g on g.ID = r.groupID where r.categoryID in (6010, 6020, 6030, 6040)"); // // [3] reset all flac with hashed names // //$res = $db->queryDirect("select releases.ID as id, searchname as searchname, groups.name as groupname, releases.categoryID as rcat from releases join groups on groups.ID = releases.groupID where length(searchname) = 40 and groups.name like 'alt.binaries.sounds.flac'"); while ($rel = $db->getAssocArray($res)) { $rescount++; $categoryID = $category->determineCategory($rel['groupname'], $rel['searchname']); if ($categoryID != $rel['rcat'] && $categoryID != '7900') { $changedcount++; echo "Changing category for " . $rel['searchname'] . " New (" . $categoryID . ") Old (" . $rel['rcat'] . ")\n"; $db->exec(sprintf("update releases SET categoryID = %d WHERE ID = %d", $categoryID, $rel['id'])); } } echo $rescount . " releases \n";
/** * To output the Humans times */ function category_options($category) { return \Categorize::getCategoryProvider()->whereType($category)->orderBy('sort')->lists('title', 'id'); }
/** * Try to get a title from a Linux_2rename.sh file for alt.binaries.u4e group. * * @param $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['groupid'], $newName); $newTitle = $this->pdo->escapeString(substr($newName, 0, 255)); // Update the release with the data. $this->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, prehashid = 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['groupid'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_processU4ETitle']); } // Break out of the loop. break; } } // Close the file. fclose($handle); } // Delete the file. @unlink($fileLocation); }
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; }
public function category_menu() { check_admin_referer('wp_ajax_shopp_category_menu'); $Categorize = new Categorize(); echo '<option value="">' . Shopp::esc_attr__('Select a category…') . '</option>'; echo '<option value="catalog-products">' . Shopp::esc_attr__('All Products') . '</option>'; echo $Categorize->menu(); exit; }
<?php require_once dirname(__FILE__) . '/../../www/config.php'; use newznab\db\Settings; use newznab\utility\Utility; $releases = new Releases(); $db = new Settings(); $cat = new Categorize(); $releaseRegex = new ReleaseRegex(); $nzb = new NZB(); $page = new Page(); $num = 0; $usefilename = true; $dupecheck = true; $movefiles = true; $categoryoverride = -1; if (empty($argc) || $argc <= 1) { $path = "./"; } else { $util = new Utility(); $path = !$util->endsWith($argv[1], "/") ? $argv[1] . "/" : $argv[1]; if (isset($argv[2])) { $usefilename = strtolower($argv[2]) == 'true'; } if (isset($argv[3])) { $dupecheck = strtolower($argv[3]) == 'true'; } if (isset($argv[4])) { $movefiles = strtolower($argv[4]) == 'true'; } if (isset($argv[5]) && is_numeric($argv[5])) {
<?php require_once dirname(__FILE__) . '/../../../../www/config.php'; 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])) { $maxtoprocess = $argv[3]; }
public function testRegex($regex, $groupname, $poster, $ignorematched, $matchagainstbins) { $cat = new Categorize(); $groups = new Groups(); $groupID = $groups->getByNameByID($groupname); $group = $groups->getCBPTableNames($this->tablePerGroup, $groupID); $catList = $cat->getForSelect(); $matches = []; if ($groupname === 0) { $groupname = '.*'; } if ($matchagainstbins !== '') { $sql = sprintf("select b.*, '0' as size, '0' as blacklistID, g.name as groupname from %s b left join groups g on g.id = b.groupid where b.groupid IN (select g.id from groups g where g.name REGEXP %s) order by b.date desc", $group['bname'], $this->pdo->escapeString('^' . $groupname . '$')); } else { $sql = sprintf("select rrt.* from releaseregextesting rrt where rrt.groupname REGEXP %s order by rrt.date desc", $this->pdo->escapeString('^' . $groupname . '$')); } $resbin = $this->pdo->queryDirect($sql); while ($rowbin = $this->pdo->getAssocArray($resbin)) { if ($ignorematched !== '' && ($rowbin['regexid'] != '' || $rowbin['blacklistid'] == 1)) { continue; } $regexarr = array("id" => "", 'regex' => $regex, 'poster' => $poster, "categoryid" => ""); $regexCheck = $this->performMatch($regexarr, $rowbin['name'], $rowbin['fromname']); if ($regexCheck !== false) { $relname = $regexCheck['name']; $relparts = explode("/", $regexCheck['parts']); $matches[$relname]['name'] = $relname; $matches[$relname]['parts'] = $regexCheck['parts']; $matches[$relname]['bincount'] = isset($matches[$relname]['bincount']) ? $matches[$relname]['bincount'] + 1 : 1; $matches[$relname]['bininfo'][] = $rowbin; $matches[$relname]['binsize'][] = $rowbin['size']; $matches[$relname]['totalsize'] = array_sum($matches[$relname]['binsize']); $matches[$relname]['relparts'][$relparts[1]] = $relparts[1]; $matches[$relname]['reltotalparts'] = array_sum($matches[$relname]['relparts']); $matches[$relname]['regexid'] = $regexCheck['regexid']; if (ctype_digit($regexCheck['regcatid'])) { $matches[$relname]['catname'] = $catList[$regexCheck['regcatid']]; } else { $matches[$relname]['catname'] = $catList[$cat->determineCategory($groupname, $relname)]; } } } //echo '<pre>'; //print_r(array_pop($matches)); //echo '</pre>'; return $matches; }
/** * 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 %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 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($cleanedName, $collection['group_id']), '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 FROM %s WHERE collectionhash = %s', $group['cname'], $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 $returnCount; }
function category_menu () { check_admin_referer('wp_ajax_ecart_category_menu'); require_once(ECART_FLOW_PATH."/Categorize.php"); $Categorize = new Categorize(); echo '<option value="">Select a category…</option>'; echo '<option value="catalog-products">All Products</option>'; echo $Categorize->menu(); exit(); }
$old = umask(0777); @mkdir($tmpPath, 0777, true); @chmod($tmpPath, 0777); @umask($old); if (!is_dir($tmpPath)) { exit('Unable to create temp directory:' . $tmpPath . PHP_EOL); } } $unrarPath = $pdo->getSetting('unrarpath'); if (empty($unrarPath)) { exit('The site setting for the unrar path must not be empty!' . PHP_EOL); } $nntp = new NNTP(['Settings' => $pdo]); $nfo = new Nfo(['Echo' => true, 'Settings' => $pdo]); $nzbContents = new NZBContents(array('Settings' => $pdo, 'Echo' => true, 'Nfo' => $nfo, 'PostProcess' => new PostProcess(['Settings' => $pdo, 'Nfo' => $nfo]), 'NNTP' => $nntp)); $categorize = new Categorize(['Settings' => $pdo]); $releases = $pdo->queryDirect(sprintf(' SELECT rf.name AS filename, r.categoryid, r.name, r.guid, r.id, r.group_id, r.postdate, r.searchname AS oldname, g.name AS groupname FROM releasefiles rf INNER JOIN releases r ON rf.releaseid = r.id INNER JOIN groups g ON r.group_id = g.id WHERE (r.isrenamed = 0 OR r.categoryid = 7020) AND r.passwordstatus = 0 AND rf.name %s ORDER BY r.postdate DESC', $pdo->likeString('Linux_2rename.sh'))); if ($releases instanceof Traversable) { $nntp->doConnect(); $sphinx = new SphinxSearch(); foreach ($releases as $release) { // Clear old files. foreach (glob($tmpPath . '*') as $file) {