echooutput = $echo;
$this->db = new DB();
$this->c = new ColorCLI();
$this->functions = new Functions();
}
/**
* Retrieve pre info from PreDB sources and store them in the DB.
*
* @return int The quantity of new titles retrieved.
*/
public function updatePre()
{
$newNames = 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 preDB sources.");
}
if (self::PRE_WOMBLE) {
$newNames += $newWomble = $this->retrieveWomble();
if ($this->echooutput) {
echo $this->c->primary($newWomble . " \tRetrieved from Womble.");
}
}
if (self::PRE_OMGWTF) {
$newNames += $newOmgWtf = $this->retrieveOmgwtfnzbs();
if ($this->echooutput) {
echo $this->c->primary($newOmgWtf . " \tRetrieved from Omgwtfnzbs.");
}
}
if (self::PRE_ZENET) {
$newNames += $newZenet = $this->retrieveZenet();
if ($this->echooutput) {
echo $this->c->primary($newZenet . " \tRetrieved from Zenet.");
}
}
if (self::PRE_PRELIST) {
$newNames += $newPreList = $this->retrievePrelist();
if ($this->echooutput) {
echo $this->c->primary($newPreList . " \tRetrieved from Prelist.");
}
}
if (self::PRE_ORLYDB) {
$newNames += $newOrly = $this->retrieveOrlydb();
if ($this->echooutput) {
echo $this->c->primary($newOrly . " \tRetrieved from Orlydb.");
}
}
if (self::PRE_SRRDB) {
$newNames += $newSrr = $this->retrieveSrr();
if ($this->echooutput) {
echo $this->c->primary($newSrr . " \tRetrieved from Srrdb.");
}
}
if (self::PRE_PREDBME) {
$newNames += $newPdme = $this->retrievePredbme();
if ($this->echooutput) {
echo $this->c->primary($newPdme . " \tRetrieved from Predbme.");
}
}
if (self::PRE_ABGXNET) {
$newNames += $abgx = $this->retrieveAbgx();
if ($this->echooutput) {
echo $this->c->primary($abgx . " \tRetrieved from abgx.");
}
}
if (self::PRE_UCRAWLER) {
$newNames += $newUsenetCrawler = $this->retrieveUsenetCrawler();
if ($this->echooutput) {
echo $this->c->primary($newUsenetCrawler . " \tRetrieved from Usenet-Crawler.");
}
}
if (self::PRE_MOOVEE) {
$newNames += $newMoovee = $this->retrieveAllfilledMoovee();
if ($this->echooutput) {
echo $this->c->primary($newMoovee . " \tRetrieved from Allfilled Moovee.");
}
}
if (self::PRE_TEEVEE) {
$newNames += $newTeevee = $this->retrieveAllfilledTeevee();
if ($this->echooutput) {
echo $this->c->primary($newTeevee . " \tRetrieved from Allfilled Teevee.");
}
}
if (self::PRE_EROTICA) {
$newNames += $newErotica = $this->retrieveAllfilledErotica();
if ($this->echooutput) {
echo $this->c->primary($newErotica . " \tRetrieved from Allfilled Erotica.");
}
}
if (self::PRE_FOREIGN) {
$newNames += $newForeign = $this->retrieveAllfilledForeign();
if ($this->echooutput) {
echo $this->c->primary($newForeign . " \tRetrieved from Allfilled Foreign.\n");
}
}
if ($this->echooutput) {
echo $this->c->primary($newNames . " \tRetrieved from all the above 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 $newNames;
}
/**
* Attempts to match PreDB 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) . ' predDB 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 preDB sources.'
);
}
}
/**
* Retrieve new pre info from womble.
*
* @return int
*/
protected function retrieveWomble()
{
$newNames = $updated = 0;
$buffer = $this->getUrl('http://www.newshost.co.za');
if ($buffer !== false) {
$matches = $match = $matches2 = array();
if (preg_match_all('/
.+?<\/tr>/s', $buffer, $matches)) {
foreach ($matches as $match) {
foreach ($match as $m) {
if (preg_match('/
.+?(?P.+?)<\/td>(.+?right>(?P.+?) (?P.+?)<\/td.+?)?(?P.+?)<\/td.+?nfo<\/a>.+)?(?P.+?)<\/td.+tr>/s', $m, $matches2)) {
// If the title is too short, don't bother.
if (strlen($matches2['title']) < 15) {
continue;
}
$md5 = $this->db->escapeString(md5($matches2['title']));
$sha1 = $this->db->escapeString(sha1($matches2['title']));
$oldName = $this->db->queryOneRow(sprintf('SELECT md5, sha1, source, ID, nfo FROM prehash WHERE md5 = %s AND sha1 = %s', $md5, $sha1));
// If we have it already and have the NFO, continue.
if ($oldName !== false && $oldName['nfo'] != NULL) {
continue;
}
// Start forming data for the query.
$nfo =
($matches2['nfo'] == ''
? 'NULL'
: $this->db->escapeString('http://www.newshost.co.za/' . $matches2['nfo'])
);
$size =
((!isset($matches['size1']) && empty($matches2['size1']))
? 'NULL'
: $this->db->escapeString($matches2['size1'] . $matches2['size2'])
);
$category = $this->db->escapeString($matches2['category']);
$time = $this->functions->from_unixtime(strtotime($matches2['date']));
$source = $this->db->escapeString('womble');
// If we already have it, update.
if ($oldName !== false) {
$this->db->exec(
sprintf('
UPDATE prehash SET
nfo = %s, size = %s, category = %s, predate = %s,
source = %s
WHERE ID = %d',
$nfo, $size, $category, $time, $source, $oldName['ID']
)
);
$updated++;
} elseif ($this->db->exec(
sprintf('
INSERT INTO prehash (title, nfo, size, category, predate, source, md5, sha1)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
$this->db->escapeString($matches2['title']),
$nfo, $size, $category, $time, $source, $md5, $sha1
)
)
) {
$newNames++;
}
}
}
}
}
if ($this->echooutput) {
echo $this->c->primary($updated . " \tUpdated from Womble.");
}
} elseif ($this->echooutput) {
echo $this->c->error("Update from Womble failed.");
}
return $newNames;
}
/**
* Retrieve pre info from omg.
*
* @return int
*/
protected function retrieveOmgwtfnzbs()
{
$newNames = $updated = 0;
$buffer = $this->getUrl('http://rss.omgwtfnzbs.org/rss-info.php');
if ($buffer !== false) {
$matches = $matches2 = $match = array();
if (preg_match_all('/- .+?<\/item>/s', $buffer, $matches)) {
foreach ($matches as $match) {
foreach ($match as $m) {
if (preg_match('/(?P.+?)\s+-\s+omgwtfnzbs\.org.*?<\/title.+?pubDate>(?P.+?)<\/pubDate.+?gory:<\/b> (?P.+?)
(?P.+?) (?P[a-zA-Z]+)db->escapeString(md5($title));
$sha1 = $this->db->escapeString(sha1($title));
$oldName = $this->db->queryOneRow(sprintf('SELECT md5, sha1, source, ID FROM prehash WHERE md5 = %s AND sha1 = %s', $md5, $sha1));
// If we have it already and the source is womble or omg, continue.
if ($oldName !== false && ($oldName['source'] === 'womble' || $oldName['source'] === 'omgwtfnzbs')) {
continue;
}
$size = $this->db->escapeString(round($matches2['size1']) . $matches2['size2']);
$category = $this->db->escapeString($matches2['category']);
$time = $this->functions->from_unixtime(strtotime($matches2['date']));
$source = $this->db->escapeString('omgwtfnzbs');
// If we have it already, update it.
if ($oldName !== false) {
$this->db->exec(
sprintf('
UPDATE prehash
SET size = %s, category = %s, predate = %s, source = %s
WHERE ID = %d',
$size, $category, $time, $source, $oldName['ID']
)
);
$updated++;
} elseif ($this->db->exec(
sprintf('
INSERT INTO prehash (title, size, category, predate, source, md5, sha1)
VALUES (%s, %s, %s, %s, %s, %s, %s)',
$this->db->escapeString($title), $size, $category, $time, $source, $md5, $sha1
)
)
) {
$newNames++;
}
}
}
}
}
if ($this ->echooutput) {
echo $this->c->primary($updated . " \tUpdated from Omgwtfnzbs.");
}
} elseif ($this ->echooutput) {
echo $this->c->error("Update from Omgwtfnzbs failed.");
}
return $newNames;
}
/**
* Get new pre data from zenet.
*
* @return int
*/
protected function retrieveZenet()
{
$newNames = 0;
$buffer = $this->getUrl('http://pre.zenet.org/live.php');
if ($buffer !== false) {
$matches = $matches2 = $match = array();
if (preg_match_all('/ | | |