Ejemplo n.º 1
0
 public function processNfos()
 {
     if ($this->site->lookupnfo == 1) {
         $nfo = new Nfo($this->echooutput);
         $nfo->processNfoFiles($this->site->lookupimdb, $this->site->lookuptvrage);
     }
 }
Ejemplo n.º 2
0
 /**
  * Look for an .nfo file in the NZB, return the NFO message id.
  * Gets the NZB completion.
  * Looks for PAR2 files in the NZB.
  *
  * @param string $guid
  * @param string $relID
  * @param int    $groupID
  * @param string $groupName
  *
  * @return bool
  *
  * @access public
  */
 public function getNfoFromNZB($guid, $relID, $groupID, $groupName)
 {
     $fetchedBinary = false;
     $messageID = $this->parseNZB($guid, $relID, $groupID, true);
     if ($messageID !== false) {
         $fetchedBinary = $this->nntp->getMessages($groupName, $messageID['id'], $this->alternateNNTP);
         if ($this->nntp->isError($fetchedBinary)) {
             // NFO download failed, increment attempts.
             $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = nfostatus - 1 WHERE id = %d', $relID));
             if ($this->echooutput) {
                 echo 'f';
             }
             return false;
         }
         if ($this->nfo->isNFO($fetchedBinary, $guid) === true) {
             if ($this->echooutput) {
                 echo $messageID['hidden'] === false ? '+' : '*';
             }
         } else {
             if ($this->echooutput) {
                 echo '-';
             }
             $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', Nfo::NFO_NONFO, $relID));
             $fetchedBinary = false;
         }
     } else {
         if ($this->echooutput) {
             echo '-';
         }
         $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', Nfo::NFO_NONFO, $relID));
     }
     return $fetchedBinary;
 }
Ejemplo n.º 3
0
 /**
  * Process nfo files.
  *
  * @param \NNTP   $nntp
  * @param string $groupID  (Optional) id of a group to work on.
  * @param string $guidChar (Optional) First letter of a release GUID to use to get work.
  *
  * @return void
  */
 public function processNfos(&$nntp, $groupID = '', $guidChar = '')
 {
     if ($this->pdo->getSetting('lookupnfo') == 1) {
         $this->Nfo->processNfoFiles($nntp, $groupID, $guidChar, (int) $this->pdo->getSetting('lookupimdb'), (int) $this->pdo->getSetting('lookuptvrage'));
     }
 }
Ejemplo n.º 4
0
 /**
  * @param      $id
  * @param bool $isGuid
  */
 public function delete($id, $isGuid = false)
 {
     $users = new Users();
     $s = new Settings();
     $nfo = new Nfo();
     $rf = new ReleaseFiles();
     $re = new ReleaseExtra();
     $rc = new ReleaseComments();
     $ri = new ReleaseImage();
     if (!is_array($id)) {
         $id = array($id);
     }
     foreach ($id as $identifier) {
         //
         // delete from disk.
         //
         $rel = $isGuid ? $this->getByGuid($identifier) : $this->getById($identifier);
         $nzbpath = "";
         if ($isGuid) {
             $nzbpath = $s->getSetting('nzbpath') . substr($identifier, 0, 1) . "/" . $identifier . ".nzb.gz";
         } elseif ($rel) {
             $nzbpath = $s->getSetting('nzbpath') . substr($rel["guid"], 0, 1) . "/" . $rel["guid"] . ".nzb.gz";
         }
         if ($nzbpath != "" && file_exists($nzbpath)) {
             unlink($nzbpath);
         }
         $audiopreviewpath = "";
         if ($isGuid) {
             $audiopreviewpath = WWW_DIR . 'covers/audio/' . $identifier . ".mp3";
         } elseif ($rel) {
             $audiopreviewpath = WWW_DIR . 'covers/audio/' . $rel["guid"] . ".mp3";
         }
         if ($audiopreviewpath && file_exists($audiopreviewpath)) {
             unlink($audiopreviewpath);
         }
         if ($rel) {
             $nfo->deleteReleaseNfo($rel['id']);
             $rc->deleteCommentsForRelease($rel['id']);
             $users->delCartForRelease($rel['id']);
             $users->delDownloadRequestsForRelease($rel['id']);
             $rf->delete($rel['id']);
             $re->delete($rel['id']);
             $re->deleteFull($rel['id']);
             $ri->delete($rel['guid']);
             $this->pdo->queryExec(sprintf("DELETE FROM releases WHERE id = %d", $rel['id']));
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Verify a file is a NFO and add it to the database.
  *
  * @param string $fileLocation
  */
 protected function _processNfoFile($fileLocation)
 {
     $data = @file_get_contents($fileLocation);
     if ($data !== false) {
         if ($this->_nfo->isNFO($data, $this->_release['guid']) === true) {
             if ($this->_nfo->addAlternateNfo($data, $this->_release, $this->_nntp) === true) {
                 $this->_releaseHasNoNFO = false;
             }
         }
     }
 }
Ejemplo n.º 6
0
 public function proc_query($qry, $bookreqids, $request_hours, $db_name)
 {
     switch ((int) $qry) {
         case 1:
             return sprintf("SELECT\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 5000 AND 5999 AND rageid = -1,1,0)) AS processtvrage,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid = 5070 AND anidbid IS NULL,1,0)) AS processanime,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 2000 AND 2999 AND imdbid IS NULL,1,0)) AS processmovies,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid IN (3010, 3040, 3050) AND musicinfoid IS NULL,1,0)) AS processmusic,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 1000 AND 1999 AND consoleinfoid IS NULL,1,0)) AS processconsole,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid IN (%s) AND bookinfoid IS NULL,1,0)) AS processbooks,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid = 4050 AND gamesinfo_id = 0,1,0)) AS processgames,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 6000 AND 6040 AND xxxinfo_id = 0,1,0)) AS processxxx,\n\t\t\t\t\tSUM(IF(1=1 %s,1,0)) AS processnfo,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND nfostatus = 1,1,0)) AS nfo,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND isrequestid = 1 AND prehashid = 0 AND\n\t\t\t\t\t\t((reqidstatus = 0) OR (reqidstatus = -1) OR (reqidstatus = -3 AND adddate > NOW() - INTERVAL %s HOUR)),1,0)) AS requestid_inprogress,\n\t\t\t\t\tSUM(IF(prehashid > 0 AND nzbstatus = 1 AND isrequestid = 1 AND reqidstatus = 1,1,0)) AS requestid_matched,\n\t\t\t\t\tSUM(IF(prehashid > 0 AND searchname IS NOT NULL,1,0)) AS prehash_matched,\n\t\t\t\t\tSUM(IF(preid > 0 AND searchname IS NOT NULL,1,0)) AS predb_matched,\n\t\t\t\t\tCOUNT(DISTINCT(preid)) AS distinct_predb_matched,\n\t\t\t\t\tCOUNT(DISTINCT(prehashid)) AS distinct_prehash_matched\n\t\t\t\t\tFROM releases r", $bookreqids, Nfo::NfoQueryString($this->pdo), $request_hours);
         case 2:
             return "SELECT\n\t\t\t\t\t(SELECT COUNT(*) FROM releases WHERE nzbstatus = 1 AND nfostatus = 1) AS nfo,\n\t\t\t\t\t(SELECT COUNT(*) FROM releases r\n\t\t\t\t\t\tINNER JOIN category c ON c.id = r.categoryid\n\t\t\t\t\t\tWHERE r.nzbstatus = 1\n\t\t\t\t\t\tAND r.passwordstatus BETWEEN -6 AND -1 AND r.haspreview = -1 AND c.disablepreview = 0\n\t\t\t\t\t) AS work,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE active = 1) AS active_groups,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE name IS NOT NULL) AS all_groups";
         case 4:
             return sprintf("\n\t\t\t\t\tSELECT\n\t\t\t\t\t(SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'predb' AND TABLE_SCHEMA = %1\$s) AS predb,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'prehash' AND TABLE_SCHEMA = %1\$s) AS prehash,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'partrepair' AND TABLE_SCHEMA = %1\$s) AS partrepair_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'parts' AND TABLE_SCHEMA = %1\$s) AS parts_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'binaries' AND TABLE_SCHEMA = %1\$s) AS binaries_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'releases' AND TABLE_SCHEMA = %1\$s) AS releases,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE first_record IS NOT NULL AND backfill = 1\n\t\t\t\t\t\tAND (now() - INTERVAL backfill_target DAY) < first_record_postdate\n\t\t\t\t\t) AS backfill_groups_days,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE first_record IS NOT NULL AND backfill = 1 AND (now() - INTERVAL datediff(curdate(),\n\t\t\t\t\t(SELECT VALUE FROM settings WHERE setting = 'safebackfilldate')) DAY) < first_record_postdate) AS backfill_groups_date", $this->pdo->escapeString($db_name));
         case 6:
             return "SELECT\n\t\t\t\t\t(SELECT searchname FROM releases ORDER BY id DESC LIMIT 1) AS newestrelname,\n\t\t\t\t\t(SELECT UNIX_TIMESTAMP(MAX(predate)) FROM prehash) AS newestprehash,\n\t\t\t\t\t(SELECT UNIX_TIMESTAMP(MAX(ctime)) FROM predb) AS newestpredb,\n\t\t\t\t\t(SELECT UNIX_TIMESTAMP(adddate) FROM releases ORDER BY id DESC LIMIT 1) AS newestrelease";
         default:
             return false;
     }
 }
Ejemplo n.º 7
0
 public function processMovieReleases()
 {
     $ret = 0;
     $db = new DB();
     $nfo = new Nfo();
     $res = $db->queryDirect(sprintf("SELECT searchname, ID from releases where imdbID IS NULL and categoryID in ( select ID from category where parentID = %d )", Category::CAT_PARENT_MOVIE));
     if (mysql_num_rows($res) > 0) {
         if ($this->echooutput) {
             echo "Processing " . mysql_num_rows($res) . " movie releases\n";
         }
         while ($arr = mysql_fetch_assoc($res)) {
             $moviename = $this->parseMovieName($arr['searchname']);
             if ($moviename !== false) {
                 if ($this->echooutput) {
                     echo 'Looking up: ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n";
                 }
                 $buffer = getUrl("http://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=" . urlencode($moviename . ' imdb'));
                 // make sure we got some data
                 if ($buffer !== false && strlen($buffer)) {
                     $imdbId = $nfo->parseImdb($buffer);
                     if ($imdbId !== false) {
                         if ($this->echooutput) {
                             echo '- found ' . $imdbId . "\n";
                         }
                         //update release with imdb id
                         $db->query(sprintf("UPDATE releases SET imdbID = %s WHERE ID = %d", $db->escapeString($imdbId), $arr["ID"]));
                         //check for existing movie entry
                         $movCheck = $this->getMovieInfo($imdbId);
                         if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) {
                             $movieId = $this->updateMovieInfo($imdbId);
                         }
                     } else {
                         //no imdb id found, set to all zeros so we dont process again
                         $db->query(sprintf("UPDATE releases SET imdbID = %d WHERE ID = %d", 0, $arr["ID"]));
                     }
                 } else {
                     //url fetch failed, will try next run
                 }
             } else {
                 //no valid movie name found, set to all zeros so we dont process again
                 $db->query(sprintf("UPDATE releases SET imdbID = %d WHERE ID = %d", 0, $arr["ID"]));
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Check if we should process NFO's.
  * @return bool
  */
 private function checkProcessNfo()
 {
     if ($this->pdo->getSetting('lookupnfo') == 1) {
         $this->nfoQueryString = \Nfo::NfoQueryString($this->pdo);
         return $this->pdo->queryOneRow(sprintf('SELECT r.id FROM releases r WHERE 1=1 %s LIMIT 1', $this->nfoQueryString)) === false ? false : true;
     }
     return false;
 }
Ejemplo n.º 9
0
 /**
  * Process nfo files
  */
 public function processNfos()
 {
     if ($this->pdo->getSetting('lookupnfo') == 1) {
         $nfo = new Nfo($this->echooutput);
         $nfo->processNfoFiles(500);
     }
 }
Ejemplo n.º 10
0
 /**
  * Process all untagged movies to link them to a movieinfo row.
  */
 public function processMovieReleases()
 {
     $ret = 0;
     $nfo = new Nfo();
     $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where imdbid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_MOVIE));
     if ($this->pdo->getNumRows($res) > 0) {
         if ($this->echooutput) {
             echo "MovProc : Processing " . $this->pdo->getNumRows($res) . " movie releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($res)) {
             $imdbID = false;
             /* Preliminary IMDB id Detection from NFO file */
             $rawnfo = '';
             if ($nfo->getNfo($arr['id'], $rawnfo)) {
                 $imdbID = $this->parseImdbFromNfo($rawnfo);
             }
             if ($imdbID !== false) {
                 // Set IMDB (if found in nfo) and move along
                 $this->pdo->queryExec(sprintf("update releases set imdbid = %s where id = %d", $this->pdo->escapeString($imdbID), $arr["id"]));
                 //check for existing movie entry
                 $movCheck = $this->getMovieInfo($imdbID);
                 if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) {
                     $movieId = $this->updateMovieInfo($imdbID);
                 }
                 continue;
             }
             $moviename = $this->parseMovieName($arr['searchname']);
             if ($moviename !== false) {
                 if ($this->echooutput) {
                     echo 'MovProc : ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n";
                 }
                 //$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com'));
                 $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]);
                 // make sure we got some data
                 if ($buffer !== false && strlen($buffer)) {
                     $imdbId = $this->parseImdbFromNfo($buffer);
                     if ($imdbId !== false) {
                         //update release with imdb id
                         $this->pdo->queryExec(sprintf("update releases SET imdbid = %s WHERE id = %d", $this->pdo->escapeString($imdbId), $arr["id"]));
                         //check for existing movie entry
                         $movCheck = $this->getMovieInfo($imdbId);
                         if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) {
                             $movieId = $this->updateMovieInfo($imdbId);
                         }
                     } else {
                         //no imdb id found, set to all zeros so we dont process again
                         $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"]));
                     }
                 } else {
                     //url fetch failed, will try next run
                 }
             } else {
                 //no valid movie name found, set to all zeros so we dont process again
                 $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"]));
             }
         }
     }
 }
Ejemplo n.º 11
0
 function processReleases()
 {
     $db = new DB();
     $cat = new Category();
     $bin = new Binaries();
     $nzb = new Nzb();
     $s = new Sites();
     $relreg = new ReleaseRegex();
     $page = new Page();
     $nfo = new Nfo(true);
     $retcount = 0;
     echo $s->getLicense();
     echo "\n\nStarting release update process (" . date("Y-m-d H:i:s") . ")\n";
     if (!file_exists($page->site->nzbpath)) {
         echo "Bad or missing nzb directory - " . $page->site->nzbpath;
         return;
     }
     $this->checkRegexesUptoDate($page->site->latestregexurl, $page->site->latestregexrevision, true);
     //
     // Get all regexes for all groups which are to be applied to new binaries
     // in order of how they should be applied
     //
     $regexrows = $relreg->get();
     foreach ($regexrows as $regexrow) {
         echo "Applying regex " . $regexrow["ID"] . " for group " . ($regexrow["groupname"] == "" ? "all" : $regexrow["groupname"]) . "\n";
         $groupmatch = "";
         //
         // Groups ending in * need to be like matched when getting out binaries for groups and children
         //
         if (preg_match("/\\*\$/i", $regexrow["groupname"])) {
             $groupname = substr($regexrow["groupname"], 0, -1);
             $resgrps = $db->query(sprintf("select ID from groups where name like %s ", $db->escapeString($groupname . "%")));
             foreach ($resgrps as $resgrp) {
                 $groupmatch .= " groupID = " . $resgrp["ID"] . " or ";
             }
             $groupmatch .= " 1=2 ";
         } elseif ($regexrow["groupname"] != "") {
             $resgrp = $db->queryOneRow(sprintf("select ID from groups where name = %s ", $db->escapeString($regexrow["groupname"])));
             //
             // if group not found, its a regex for a group we arent indexing.
             //
             if ($resgrp) {
                 $groupmatch = " groupID = " . $resgrp["ID"];
             } else {
                 $groupmatch = " 1=2 ";
             }
         } else {
             $groupmatch = " 1=1 ";
         }
         // Get current mysql time for date comparison checks in case php is in a different time zone
         $currTime = $db->queryOneRow("SELECT NOW() as now");
         // Get out all binaries of STAGE0 for current group
         $arrNoPartBinaries = array();
         $resbin = $db->queryDirect(sprintf("SELECT binaries.ID, binaries.name, binaries.date, binaries.totalParts from binaries where (%s) and procstat = %d order by binaries.date asc", $groupmatch, Releases::PROCSTAT_NEW));
         while ($rowbin = mysql_fetch_assoc($resbin)) {
             if (preg_match($regexrow["regex"], $rowbin["name"], $matches)) {
                 $matches = array_map("trim", $matches);
                 if (isset($matches['reqid']) && ctype_digit($matches['reqid']) && (!isset($matches['name']) || empty($matches['name']))) {
                     $matches['name'] = $matches['reqid'];
                 }
                 // Check that the regex provided the correct parameters
                 if (!isset($matches['name']) || empty($matches['name'])) {
                     echo "regex applied which didnt return right number of capture groups - " . $regexrow["regex"] . "\n";
                     print_r($matches);
                     continue;
                 }
                 // If theres no number of files data in the subject, put it into a release if it was posted to usenet longer than five hours ago.
                 if (!isset($matches['parts']) && strtotime($currTime['now']) - strtotime($rowbin['date']) > 18000 || isset($arrNoPartBinaries[$matches['name']])) {
                     //
                     // Take a copy of the name of this no-part release found. This can be used
                     // next time round the loop to find parts of this set, but which have not yet reached 3 hours.
                     //
                     $arrNoPartBinaries[$matches['name']] = "1";
                     $matches['parts'] = "01/01";
                 }
                 if (isset($matches['name']) && isset($matches['parts'])) {
                     if (strpos($matches['parts'], '/') === false) {
                         $matches['parts'] = str_replace(array('-', '~', ' of '), '/', $matches['parts']);
                     }
                     $regcatid = "null ";
                     if ($regexrow["categoryID"] != "") {
                         $regcatid = $regexrow["categoryID"];
                     }
                     $reqid = " null ";
                     if (isset($matches['reqid'])) {
                         $reqid = $matches['reqid'];
                     }
                     //check if post is repost
                     if (preg_match('/(repost\\d?|re\\-?up)/i', $rowbin['name'], $repost) && !preg_match('/repost|re\\-?up/i', $matches['name'])) {
                         $matches['name'] .= ' ' . $repost[1];
                     }
                     $relparts = explode("/", $matches['parts']);
                     $db->query(sprintf("update binaries set relname = replace(%s, '_', ' '), relpart = %d, reltotalpart = %d, procstat=%d, categoryID=%s, regexID=%d, reqID=%s where ID = %d", $db->escapeString($matches['name']), $relparts[0], $relparts[1], Releases::PROCSTAT_TITLEMATCHED, $regcatid, $regexrow["ID"], $reqid, $rowbin["ID"]));
                 }
             }
         }
     }
     //
     // Move all binaries from releases which have the correct number of files on to the next stage.
     //
     echo "Stage 2\n";
     $result = $db->queryDirect(sprintf("SELECT relname, SUM(reltotalpart) AS reltotalpart, groupID, reqID, fromname, SUM(num) AS num, coalesce(g.minfilestoformrelease, s.minfilestoformrelease) as minfilestoformrelease FROM   ( SELECT relname, reltotalpart, groupID, reqID, fromname, COUNT(ID) AS num FROM binaries     WHERE procstat = %s     GROUP BY relname, reltotalpart, groupID, reqID, fromname    ) x left outer join groups g on g.ID = x.groupID inner join ( select value as minfilestoformrelease from site where setting = 'minfilestoformrelease' ) s GROUP BY relname, groupID, reqID, fromname", Releases::PROCSTAT_TITLEMATCHED));
     while ($row = mysql_fetch_assoc($result)) {
         $retcount++;
         //
         // Less than the site permitted number of files in a release. Dont discard it, as it may
         // be part of a set being uploaded.
         //
         if ($row["num"] < $row["minfilestoformrelease"]) {
             echo "Number of files in release " . $row["relname"] . " less than site/group setting (" . $row['num'] . "/" . $row["minfilestoformrelease"] . ")\n";
             $db->query(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname = %s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
         } elseif ($row["num"] >= $row["reltotalpart"]) {
             // Check that the binary is complete
             $binlist = $db->query(sprintf("SELECT ID, totalParts, date from binaries where relname = %s and procstat = %d and groupID = %d and fromname = %s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
             $incomplete = false;
             foreach ($binlist as $rowbin) {
                 $binParts = $db->queryOneRow(sprintf("SELECT COUNT(ID) AS num FROM parts WHERE binaryID = %d", $rowbin['ID']));
                 if ($binParts['num'] < $rowbin['totalParts']) {
                     echo "binary " . $rowbin['ID'] . " from " . $row['relname'] . " has missing parts - " . $binParts['num'] . "/" . $rowbin['totalParts'] . " (" . number_format($binParts['num'] / $rowbin['totalParts'] * 100, 1) . "% complete)\n";
                     // Allow to binary to release if posted to usenet longer than four hours ago and we still don't have all the parts
                     if (strtotime($currTime['now']) - strtotime($rowbin['date']) > 14400) {
                         echo "allowing incomplete binary " . $rowbin['ID'] . "\n";
                     } else {
                         $incomplete = true;
                     }
                 }
             }
             if ($incomplete) {
                 echo "Incorrect number of parts " . $row["relname"] . "-" . $row["num"] . "-" . $row["reltotalpart"] . "\n";
                 $db->query(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname = %s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
             } elseif ($row['reqID'] != '' && $page->site->reqidurl != "") {
                 //
                 // Try and get the name using the group
                 //
                 $binGroup = $db->queryOneRow(sprintf("SELECT name FROM groups WHERE ID = %d", $row["groupID"]));
                 echo "Looking up " . $row['reqID'] . " in " . $binGroup['name'] . "... ";
                 $newtitle = $this->getReleaseNameForReqId($page->site->reqidurl, $binGroup["name"], $row["reqID"], true);
                 //
                 // if the feed/group wasnt supported by the scraper, then just use the release name as the title.
                 //
                 if ($newtitle == "no feed") {
                     $newtitle = $row["relname"];
                     echo "Group not supported\n";
                 }
                 //
                 // Valid release with right number of files and title now, so move it on
                 //
                 if ($newtitle != "") {
                     $db->query(sprintf("update binaries set relname = %s, procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($newtitle), Releases::PROCSTAT_READYTORELEASE, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
                 } else {
                     //
                     // Item not found, if the binary was added to the index yages ago, then give up.
                     //
                     $maxaddeddate = $db->queryOneRow(sprintf("SELECT NOW() as now, MAX(dateadded) as dateadded FROM binaries WHERE relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
                     //
                     // If added to the index over 48 hours ago, give up trying to determine the title
                     //
                     if (strtotime($maxaddeddate['now']) - strtotime($maxaddeddate['dateadded']) > 60 * 60 * 48) {
                         $db->query(sprintf("update binaries set procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", Releases::PROCSTAT_NOREQIDNAMELOOKUPFOUND, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
                         echo "Not found in 48 hours\n";
                     }
                 }
             } else {
                 $db->query(sprintf("update binaries set procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", Releases::PROCSTAT_READYTORELEASE, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
             }
         } else {
             echo "Incorrect number of files for " . $row["relname"] . " (" . $row["num"] . "/" . $row["reltotalpart"] . ")\n";
             $db->query(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"])));
         }
         if ($retcount % 10 == 0) {
             echo "-processed " . $retcount . " binaries stage two\n";
         }
     }
     $retcount = $nfocount = 0;
     echo "Stage 3\n";
     //
     // Get out all distinct relname, group from binaries of STAGE2
     //
     $result = $db->queryDirect(sprintf("SELECT relname, groupID, g.name as group_name, fromname, count(binaries.ID) as parts from binaries inner join groups g on g.ID = binaries.groupID where procstat = %d and relname is not null group by relname, g.name, groupID, fromname ORDER BY COUNT(binaries.ID) desc", Releases::PROCSTAT_READYTORELEASE));
     while ($row = mysql_fetch_assoc($result)) {
         $retcount++;
         //
         // Get the last post date and the poster name from the binary
         //
         $bindata = $db->queryOneRow(sprintf("select fromname, MAX(date) as date from binaries where relname = %s and procstat = %d and groupID = %d and fromname = %s group by fromname", $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
         //
         // Get all releases with the same name with a usenet posted date in a +1-1 date range.
         //
         $relDupes = $db->query(sprintf("select ID from releases where searchname = %s and (%s - INTERVAL 1 DAY < postdate AND %s + INTERVAL 1 DAY > postdate)", $db->escapeString($row["relname"]), $db->escapeString($bindata["date"]), $db->escapeString($bindata["date"])));
         if (count($relDupes) > 0) {
             $db->query(sprintf("update binaries set procstat = %d where relname = %s and procstat = %d and groupID = %d and fromname=%s ", Releases::PROCSTAT_DUPLICATE, $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
             continue;
         }
         //
         // Get total size of this release
         // Done in a big OR statement, not an IN as the mysql binaryID index on parts table
         // was not being used.
         //
         $totalSize = "0";
         $regexAppliedCategoryID = "";
         $regexIDused = "";
         $reqIDused = "";
         $relTotalParts = 0;
         $relCompletion = 0;
         $binariesForSize = $db->query(sprintf("select ID, categoryID, regexID, reqID, totalParts from binaries use index (ix_binary_relname) where relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
         if (count($binariesForSize) > 0) {
             $sizeSql = "select sum(size) as totalSize, count(ID) as relParts from parts where (";
             foreach ($binariesForSize as $binSizeId) {
                 $sizeSql .= " binaryID = " . $binSizeId["ID"] . " or ";
                 //
                 // Get categoryID if one has been allocated to this
                 //
                 if ($binSizeId["categoryID"] != "" && $regexAppliedCategoryID == "") {
                     $regexAppliedCategoryID = $binSizeId["categoryID"];
                 }
                 //
                 // Get RegexID if one has been allocated to this
                 //
                 if ($binSizeId["regexID"] != "" && $regexIDused == "") {
                     $regexIDused = $binSizeId["regexID"];
                 }
                 //
                 // Get requestID if one has been allocated to this
                 //
                 if ($binSizeId["reqID"] != "" && $reqIDused == "") {
                     $reqIDused = $binSizeId["reqID"];
                 }
                 //
                 // Get number of expected parts
                 //
                 $relTotalParts += $binSizeId["totalParts"];
             }
             $sizeSql .= " 1=2) ";
             $temp = $db->queryOneRow($sizeSql);
             $totalSize = $temp["totalSize"] + 0 . "";
             $relCompletion = number_format($temp["relParts"] / $relTotalParts * 100, 1, '.', '');
         }
         //
         // Insert the release
         //
         $relguid = md5(uniqid());
         if ($regexAppliedCategoryID == "") {
             $catId = $cat->determineCategory($row["group_name"], $row["relname"]);
         } else {
             $catId = $regexAppliedCategoryID;
         }
         if ($regexIDused == "") {
             $regexID = " null ";
         } else {
             $regexID = $regexIDused;
         }
         if ($reqIDused == "") {
             $reqID = " null ";
         } else {
             $reqID = $reqIDused;
         }
         //Clean release name
         $cleanArr = array('#', '@', '$', '%', '^', '§', '¨', '©', 'Ö');
         $cleanRelName = str_replace($cleanArr, '', $row['relname']);
         $relid = $db->queryInsert(sprintf("insert into releases (name, searchname, totalpart, groupID, adddate, guid, categoryID, regexID, rageID, postdate, fromname, size, reqID, passwordstatus, completion) values (%s, %s, %d, %d, now(), %s, %d, %d, -1, %s, %s, %s, %s, %d, %f)", $db->escapeString($cleanRelName), $db->escapeString($cleanRelName), $row["parts"], $row["groupID"], $db->escapeString($relguid), $catId, $regexID, $db->escapeString($bindata["date"]), $db->escapeString($bindata["fromname"]), $totalSize, $reqID, $page->site->checkpasswordedrar == "1" ? -1 : 0, $relCompletion > 100 ? 100 : $relCompletion));
         echo "Added release " . $cleanRelName . "\n";
         //
         // Tag every binary for this release with its parent release id
         // remove the release name from the binary as its no longer required
         //
         $db->query(sprintf("update binaries set procstat = %d, releaseID = %d where relname = %s and procstat = %d and groupID = %d and fromname=%s", Releases::PROCSTAT_RELEASED, $relid, $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
         //
         // Find an .nfo in the release
         //
         $relnfo = $nfo->determineReleaseNfo($relid);
         if ($relnfo !== false) {
             $nfo->addReleaseNfo($relid, $relnfo['ID']);
             $nfocount++;
         }
         //
         // Write the nzb to disk
         //
         $nzb->writeNZBforReleaseId($relid, $relguid, $cleanRelName, $catId, $nzb->getNZBPath($relguid, $page->site->nzbpath, true));
         if ($retcount % 5 == 0) {
             echo "-processed " . $retcount . " releases stage three\n";
         }
     }
     echo "Found " . $nfocount . " nfos in " . $retcount . " releases\n";
     //
     // Process nfo files
     //
     if ($page->site->lookupnfo != "1") {
         echo "Site config (site.lookupnfo) prevented retrieving nfos\n";
     } else {
         $nfo->processNfoFiles($page->site->lookupimdb, $page->site->lookuptvrage == "1");
     }
     //
     // Lookup imdb if enabled
     //
     if ($page->site->lookupimdb == 1) {
         $movie = new Movie(true);
         $movie->processMovieReleases();
     }
     //
     // Lookup music if enabled
     //
     if ($page->site->lookupmusic == 1) {
         $music = new Music(true);
         $music->processMusicReleases();
     }
     //
     // Lookup games if enabled
     //
     if ($page->site->lookupgames == 1) {
         $console = new Console(true);
         $console->processConsoleReleases();
     }
     //
     // Check for passworded releases
     //
     if ($page->site->checkpasswordedrar != "1") {
         echo "Site config (site.checkpasswordedrar) prevented checking releases are passworded\n";
     } else {
         $this->processPasswordedReleases(true);
     }
     //
     // Process all TV related releases which will assign their series/episode/rage data
     //
     $tvrage = new TVRage(true);
     $tvrage->processTvReleases($page->site->lookuptvrage == "1");
     //
     // Get the current datetime again, as using now() in the housekeeping queries prevents the index being used.
     //
     $currTime = $db->queryOneRow("SELECT NOW() as now");
     //
     // Tidy away any binaries which have been attempted to be grouped into
     // a release more than x times
     //
     echo "Tidying away binaries which cant be grouped after " . $page->site->attemptgroupbindays . " days\n";
     $db->query(sprintf("update binaries set procstat = %d where procstat = %d and dateadded < %s - interval %d day ", Releases::PROCSTAT_WRONGPARTS, Releases::PROCSTAT_NEW, $db->escapeString($currTime["now"]), $page->site->attemptgroupbindays));
     //
     // Delete any parts and binaries which are older than the site's retention days
     //
     echo "Deleting parts which are older than " . $page->site->rawretentiondays . " days\n";
     $db->query(sprintf("delete from parts where dateadded < %s - interval %d day", $db->escapeString($currTime["now"]), $page->site->rawretentiondays));
     echo "Deleting binaries which are older than " . $page->site->rawretentiondays . " days\n";
     $db->query(sprintf("delete from binaries where dateadded < %s - interval %d day", $db->escapeString($currTime["now"]), $page->site->rawretentiondays));
     //
     // Delete any releases which are older than site's release retention days
     //
     if ($page->site->releaseretentiondays != 0) {
         echo "Determining any releases past retention to be deleted.\n\n";
         $result = $db->query(sprintf("select ID from releases where postdate < %s - interval %d day", $db->escapeString($currTime["now"]), $page->site->releaseretentiondays));
         foreach ($result as $row) {
             $this->delete($row["ID"]);
         }
     }
     echo "Processed " . $retcount . " releases\n\n";
     return $retcount;
 }
Ejemplo n.º 12
0
 public function processTvReleases($lookupTvRage = true, $numtoProcess = 100)
 {
     $ret = 0;
     $nfo = new Nfo();
     // get all releases without a rageid which are in a tv category.
     $result = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where rageid = -1 and categoryid in ( select id from category where parentid = %d ) order by postdate desc limit %d ", Category::CAT_PARENT_TV, $numtoProcess));
     if ($this->pdo->getNumRows($result) > 0) {
         if ($this->echooutput) {
             echo "TVRage  : Looking up " . $this->pdo->getNumRows($result) . " releases" . ($lookupTvRage ? " using local and web\n" : " local only\n");
         }
         while ($arr = $this->pdo->getAssocArray($result)) {
             $rageID = false;
             /* Preliminary Rage id Detection from NFO file */
             $rawnfo = '';
             if ($nfo->getNfo($arr['id'], $rawnfo)) {
                 $rageID = $this->parseRageIdFromNfo($rawnfo);
             }
             if ($rageID) {
                 // Set RageID (if matched db) and move along
                 $res = $this->pdo->query(sprintf("SELECT count(id) as cnt from tvrage where rageid = %d", $rageID));
                 if (count($res) >= 1 && intval($res[0]['cnt']) > 1) {
                     $this->pdo->queryExec(sprintf("update releases set rageid = %d where id = %d", $rageID, $arr["id"]));
                     continue;
                 }
             }
             $show = $this->parseNameEpSeason($arr['searchname']);
             if (is_array($show) && $show['name'] != '') {
                 // update release with season, ep, and airdate info (if available) from releasetitle
                 $this->updateEpInfo($show, $arr['id']);
                 // find the rageid
                 $id = $this->getByTitle($show['cleanname']);
                 if ($id === false && $lookupTvRage) {
                     // if it doesnt exist locally and lookups are allowed lets try to get it
                     if ($this->echooutput) {
                         echo "TVRage  : Didnt find " . $show['cleanname'] . " locally, checking web\n";
                     }
                     $tvrShow = $this->getRageMatch($show);
                     if ($tvrShow !== false && is_array($tvrShow)) {
                         // get all tv info and add show
                         $this->updateRageInfo($tvrShow['showid'], $show, $tvrShow, $arr['id']);
                     } elseif ($tvrShow === false) {
                         // no match
                         //add to tvrage with rageid = -2 and $show['cleanname'] title only
                         $this->add(-2, $show['cleanname'], '', '', '', '');
                     } else {
                         // $tvrShow probably equals -1 but we'll do this as a catchall instead of a specific elseif
                         //skip because we couldnt connect to tvrage.com
                     }
                 } elseif ($id > 0) {
                     $tvairdate = isset($show['airdate']) && !empty($show['airdate']) ? $this->pdo->escapeString($show['airdate']) : "null";
                     $tvtitle = "null";
                     if ($lookupTvRage) {
                         if ($tvairdate == "null") {
                             //check local releases to see if we already have the data
                             $epinfo = $this->pdo->queryOneRow(sprintf("select tvtitle as title, tvairdate as airdate from releases where tvairdate is not null and season = %s and episode = %s and rageid = %d", $this->pdo->escapeString($show['season']), $this->pdo->escapeString($show['episode']), $id));
                             //check tvdb episodeinfo data
                             if ($epinfo == false) {
                                 $sql = sprintf("select eptitle as title, airdate as airdate from episodeinfo where airdate is not null and fullep = %s and rageid = %d", $this->pdo->escapeString(str_replace('S', '', $show['season']) . 'x' . str_replace('E', '', $show['episode'])), $id);
                                 $epinfo = $this->pdo->queryOneRow($sql);
                             }
                             if ($epinfo == false) {
                                 $epinfo = $this->getEpisodeInfo($id, $show['season'], $show['episode']);
                             }
                             if ($epinfo !== false) {
                                 if (!empty($epinfo['airdate'])) {
                                     $tvairdate = $this->pdo->escapeString($epinfo['airdate']);
                                 }
                                 if (!empty($epinfo['title'])) {
                                     $tvtitle = $this->pdo->escapeString($epinfo['title']);
                                 }
                             }
                         }
                     }
                     $this->pdo->queryExec(sprintf("update releases set tvtitle=trim(%s), tvairdate=%s, rageid = %d where id = %d", $tvtitle, $tvairdate, $id, $arr["id"]));
                 } else {
                     // cant find rageid, so set rageid to n/a
                     $this->pdo->queryExec(sprintf("update releases set rageid = -2 where id = %d", $arr["id"]));
                 }
             } else {
                 // not a tv episode, so set rageid to n/a
                 $this->pdo->queryExec(sprintf("update releases set rageid = -2 where id = %d", $arr["id"]));
             }
             $ret++;
         }
     }
     return $ret;
 }