echooutput = $echo; $this->db = new DB(); $this->c = new ColorCLI(); $this->functions = new Functions(); $this->updatedPre = 0; $this->insertedPre = 0; } /** * Retrieve pre info from PreHash sources and store them in the DB. * * @return int The quantity of new titles retrieved. */ public function updatePre() { $newPre = $updatedPre = 0; $newestRel = $this->db->queryOneRow("SELECT value AS adddate FROM tmux WHERE setting = 'lastpretime'"); // Wait 10 minutes in between pulls. if ((int)$newestRel['adddate'] < (time() - 600)) { if ($this->echooutput) { echo $this->c->header("Retrieving titles from prehash sources."); } if (self::PRE_WOMBLE) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveWomble(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Womble."); echo $this->c->primary($this->updatedPre . " \tUpdated from Womble."); } } if (self::PRE_OMGWTF) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveOmgwtfnzbs(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Omgwtfnzbs."); echo $this->c->primary($this->updatedPre . " \tUpdated from Omgwtfnzbs."); } } if (self::PRE_ZENET) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveZenet(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Zenet."); echo $this->c->primary($this->updatedPre . " \tUpdated from Zenet."); } } if (self::PRE_PRELIST) { $this->updatedPre = $this->insertedPre = 0; $this->retrievePrelist(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Prelist."); echo $this->c->primary($this->updatedPre . " \tUpdated from Prelist."); } } if (self::PRE_ORLYDB) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveOrlydb(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Orlydb."); echo $this->c->primary($this->updatedPre . " \tUpdated from Orlydb."); } } if (self::PRE_SRRDB) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveSrr(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Srrdb."); echo $this->c->primary($this->updatedPre . " \tUpdated from Srrdb."); } } if (self::PRE_PREDBME) { $this->updatedPre = $this->insertedPre = 0; $this->retrievePredbme(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Predbme."); echo $this->c->primary($this->updatedPre . " \tUpdated from Predbme."); } } if (self::PRE_ABGXNET) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveAbgx(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from abgx."); echo $this->c->primary($this->updatedPre . " \tUpdated from abgx."); } } if (self::PRE_UCRAWLER) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveUsenetCrawler(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Usenet-Crawler."); echo $this->c->primary($this->updatedPre . " \tUpdated from Usenet-Crawler."); } } if (self::PRE_MOOVEE) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveAllfilledMoovee(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Allfilled Moovee."); echo $this->c->primary($this->updatedPre . " \tUpdated from Allfilled Moovee."); } } if (self::PRE_TEEVEE) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveAllfilledTeevee(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Allfilled Teevee."); echo $this->c->primary($this->updatedPre . " \tUpdated from Allfilled Teevee."); } } if (self::PRE_EROTICA) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveAllfilledErotica(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Allfilled Erotica."); echo $this->c->primary($this->updatedPre . " \tUpdated from Allfilled Erotica."); } } if (self::PRE_FOREIGN) { $this->updatedPre = $this->insertedPre = 0; $this->retrieveAllfilledForeign(); $newPre += $this->insertedPre; $updatedPre += $this->updatedPre; if ($this->echooutput) { echo $this->c->primary($this->insertedPre . " \tRetrieved from Allfilled Foreign."); echo $this->c->primary($this->updatedPre . " \tUpdated from Allfilled Foreign."); } } if ($this->echooutput) { echo $this->c->primary($newPre . " \tRetrieved from all sources."); echo $this->c->primary($updatedPre . " \tUpdated from all sources."); } // If we found nothing, update the last added to now to reset the timer. $this->db->exec(sprintf("UPDATE tmux SET value = %s WHERE setting = 'lastpretime'", $this->db->escapeString(time()))); } return $newPre; } /** * Attempts to match prehash titles / NFOs to releases. * * @param $nntp */ public function checkPre($nntp) { $matched = $this->matchPredb(); if ($this->echooutput) { echo $this->c->header( 'Matched ' . number_format(($matched > 0) ? $matched : 0) . ' prehash titles to release search names.' ); } $nfos = $this->matchNfo($nntp); if ($this->echooutput) { echo $this->c->header( "\nAdded " . number_format(($nfos > 0) ? $nfos : 0) . ' missing NFOs from prehash sources.' ); } } /** * @param $matches */ protected function verifyPreData(&$matches) { // If the title is too short, don't bother. if (strlen($matches['title']) < 15) { return; } $matches['title'] = str_replace(array("\r", "\n"), '', $matches['title']); $duplicateCheck = $this->db->queryOneRow(sprintf('SELECT ID, nfo, size, category FROM prehash WHERE title = %s', $this->db->escapeString($matches['title']))); if ($duplicateCheck === false) { $this->db->exec( sprintf(' INSERT INTO prehash (title, nfo, size, category, predate, source, md5, sha1, requestID, groupID, files, filename, nuked, nukereason) VALUES (%s, %s, %s, %s, %s, %s, md5(%s), sha1(%s), %d, %d, %s, %s, %d, %s)', $this->db->escapeString($matches['title']), ((isset($matches['nfo']) && !empty($matches['nfo'])) ? $this->db->escapeString($matches['nfo']) : 'NULL'), ((isset($matches['size']) && !empty($matches['size'])) ? $this->db->escapeString($matches['size']) : 'NULL'), ((isset($matches['category']) && !empty($matches['category'])) ? $this->db->escapeString($matches['category']) : 'NULL'), $this->functions->from_unixtime($matches['date']), $this->db->escapeString($matches['source']), $this->db->escapeString($matches['title']), $this->db->escapeString($matches['title']), ((isset($matches['requestID']) && is_numeric($matches['requestID']) ? $matches['requestID'] : 0)), ((isset($matches['groupID']) && is_numeric($matches['groupID'])) ? $matches['groupID'] : 0), ((isset($matches['files']) && !empty($matches['files'])) ? $this->db->escapeString($matches['files']) : 'NULL'), (isset($matches['filename']) ? $this->db->escapeString($matches['filename']) : $this->db->escapeString('')), ((isset($matches['nuked']) && is_numeric($matches['nuked'])) ? $matches['nuked'] : 0), ((isset($matches['reason']) && !empty($matches['nukereason'])) ? $this->db->escapeString($matches['nukereason']) : 'NULL') ) ); $this->insertedPre++; } else { if (empty($matches['title'])) { return; } $query = 'UPDATE prehash SET '; $query .= (!empty($matches['nfo']) ? 'nfo = ' . $this->db->escapeString($matches['nfo']) . ', ' : ''); $query .= (!empty($matches['size']) ? 'size = ' . $this->db->escapeString($matches['size']) . ', ' : ''); $query .= (!empty($matches['source']) ? 'source = ' . $this->db->escapeString($matches['source']) . ', ' : ''); $query .= (!empty($matches['files']) ? 'files = ' . $this->db->escapeString($matches['files']) . ', ' : ''); $query .= (!empty($matches['reason']) ? 'nukereason = ' . $this->db->escapeString($matches['reason']) . ', ' : ''); $query .= (!empty($matches['requestid']) ? 'requestID = ' . $matches['requestid'] . ', ' : ''); $query .= (!empty($matches['groupid']) ? 'groupID = ' . $matches['groupid'] . ', ' : ''); $query .= (!empty($matches['predate']) ? 'predate = ' . $matches['predate'] . ', ' : ''); $query .= (!empty($matches['nuked']) ? 'nuked = ' . $matches['nuked'] . ', ' : ''); $query .= (!empty($matches['filename']) ? 'filename = ' . $this->db->escapeString($matches['filename']) . ', ' : ''); $query .= ( (empty($duplicateCheck['category']) && !empty($matches['category'])) ? 'category = ' . $this->db->escapeString($matches['category']) . ', ' : '' ); if ($query === 'UPDATE prehash SET ') { return; } $query .= 'title = ' . $this->db->escapeString($matches['title']); $query .= ' WHERE title = ' . $this->db->escapeString($matches['title']); $this->db->exec($query); $this->updatedPre++; } } /** * Retrieve new pre info from womble. */ protected function retrieveWomble() { $buffer = $this->getUrl('http://www.newshost.co.za'); if ($buffer !== false) { if (preg_match_all('/
(?P
<\/tt>/s', $buffer, $matches)) {
foreach ($matches as $match) {
foreach ($match as $m) {
if (preg_match(
'/">\[\s*(?P