Ejemplo n.º 1
0
    /**
     * Add new files for a release ID.
     *
     * @param int    $id          The ID of the release.
     * @param string $name        Name of the file.
     * @param int    $size        Size of the file.
     * @param int    $createdTime Unix time the file was created.
     * @param int    $hasPassword Does it have a password (see Releases class constants)?
     *
     * @return mixed
     */
    public function add($id, $name, $size, $createdTime, $hasPassword)
    {
        $insert = 0;
        $duplicateCheck = $this->pdo->queryOneRow(sprintf('
				SELECT id
				FROM releasefiles
				WHERE releaseid = %d AND name = %s', $id, $this->pdo->escapeString(utf8_encode($name))));
        if ($duplicateCheck === false) {
            $insert = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\tINSERT INTO releasefiles\n\t\t\t\t\t\t(releaseid, name, size, createddate, passworded)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(%d, %s, %s, %s, %d)", $id, $this->pdo->escapeString(utf8_encode($name)), $this->pdo->escapeString($size), $this->pdo->from_unixtime($createdTime), $hasPassword));
        }
        return $insert;
    }
Ejemplo n.º 2
0
 /**
  * Add a forum post.
  */
 public function add($parentid, $userid, $subject, $message, $locked = 0, $sticky = 0, $replies = 0)
 {
     if ($message == "") {
         return -1;
     }
     if ($parentid != 0) {
         $par = $this->getParent($parentid);
         if ($par == false) {
             return -1;
         }
         $this->pdo->queryExec(sprintf("update forumpost set replies = replies + 1, updateddate = now() where id = %d", $parentid));
     }
     $this->pdo->queryInsert(sprintf("INSERT INTO forumpost (forumid, parentid, userid, subject, message, locked, sticky, replies, createddate, updateddate) VALUES ( 1,  %d, %d,  %s,  %s, %d, %d, %d,NOW(),  NOW())", $parentid, $userid, $this->pdo->escapeString($subject), $this->pdo->escapeString($message), $locked, $sticky, $replies));
 }
Ejemplo n.º 3
0
 /**
  * Get an episodeinfo row by name.
  */
 public function getEpisodeInfoByName($showtitle, $fullep, $epabsolute = '0')
 {
     $db = new Settings();
     if ($epabsolute == '0') {
         //as string - not int.
         if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $fullep)) {
             $additionalSql = sprintf('AND fullep = %s', $db->escapeString($fullep));
         } else {
             $additionalSql = sprintf('AND airdate LIKE %s', $db->escapeString($fullep . ' %'));
         }
     } else {
         $additionalSql = sprintf('AND epabsolute = %s', $db->escapeString($epabsolute));
     }
     return $db->queryOneRow(sprintf('SELECT * FROM episodeinfo WHERE showtitle = %s %s', $db->escapeString($showtitle), $additionalSql));
 }
Ejemplo n.º 4
0
 public function updateMovie($uid, $imdbid, $catid = array())
 {
     $db = new Settings();
     $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null";
     $sql = sprintf("update usermovies set categoryid = %s where userid = %d and imdbid = %d", $catid, $uid, $imdbid);
     $db->queryExec($sql);
 }
Ejemplo n.º 5
0
    /**
     * Fetch a comment and insert it.
     *
     * @param string $messageID Message-ID for the article.
     * @param string $siteID    id of the site.
     *
     * @return bool
     */
    protected function insertNewComment(&$messageID, &$siteID)
    {
        // Get the article body.
        $body = $this->nntp->getMessages(self::group, $messageID);
        // Check if there's an error.
        if ($this->nntp->isError($body)) {
            return false;
        }
        // Decompress the body.
        $body = @gzinflate($body);
        if ($body === false) {
            return false;
        }
        // JSON Decode the body.
        $body = json_decode($body, true);
        if ($body === false) {
            return false;
        }
        // Just in case.
        if (!isset($body['USER']) || !isset($body['SID']) || !isset($body['RID']) || !isset($body['TIME']) | !isset($body['BODY'])) {
            return false;
        }
        $cid = md5($body['SID'] . $body['USER'] . $body['TIME'] . $siteID);
        // Insert the comment.
        if ($this->pdo->queryExec(sprintf('
				INSERT IGNORE INTO releasecomment
				(text, createddate, issynced, shareid, cid, gid, nzb_guid, siteid, username, userid, releaseid, shared, host, sourceID)
				VALUES (%s, %s, 1, %s, %s, %s, %s, %s, %s, 0, 0, 2, "", 999)', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $this->pdo->escapeString($cid), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($siteID), $this->pdo->escapeString(substr($body['USER'], 0, 3) === 'sn-' ? 'SH_ANON' : 'SH_' . $body['USER'])))) {
            return true;
        }
        return false;
    }
Ejemplo n.º 6
0
 /**
  * Inserts Genre and returns last affected row (Genre id)
  *
  * @param $genre
  *
  * @return bool
  */
 private function insertGenre($genre)
 {
     $res = '';
     if (isset($genre)) {
         $res = $this->pdo->queryInsert(sprintf("INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)", $this->pdo->escapeString($genre), 6000, 0));
     }
     return $res;
 }
Ejemplo n.º 7
0
 public function addFull($id, $xml)
 {
     $row = $this->getFull($id);
     if ($row) {
         return -1;
     }
     return $this->pdo->queryInsert(sprintf("INSERT INTO releaseextrafull (releaseid, mediainfo) VALUES (%d, %s)", $id, $this->pdo->escapeString($xml)));
 }
Ejemplo n.º 8
0
 /**
  * Get a group id for a group name.
  *
  * @param string $groupName
  *
  * @return mixed
  *
  * @access protected
  */
 protected function _getGroupID($groupName)
 {
     if (!isset($this->_groupList[$groupName])) {
         $group = $this->_pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->_pdo->escapeString($groupName)));
         $this->_groupList[$groupName] = $group['id'];
     }
     return $this->_groupList[$groupName];
 }
Ejemplo n.º 9
0
    /** This function updates a single variable column in releases
     *  The first parameter is the column to update, the second is the value
     *  The final parameter is the id of the release to update
     *
     * @param string $column
     * @param string|int $status
     * @param int $id
     **/
    private function _updateSingleColumn($column = '', $status = 0, $id = 0)
    {
        if ($column !== '' && $id !== 0) {
            $this->pdo->queryExec(sprintf('
							UPDATE releases
							SET %s = %s
							WHERE id = %d', $column, is_numeric($status) ? $status : $this->pdo->escapeString($status), $id));
        }
    }
Ejemplo n.º 10
0
 /**
  * update a release name
  *
  * @param Settings $pdo
  * @param    $id
  * @param    $oldname
  * @param    $newname
  */
 private function updateName(Settings $pdo, $id, $oldname, $newname)
 {
     if ($this->verbose) {
         echo sprintf("OLD : %s\nNEW : %s\n\n", $oldname, $newname);
     }
     if (!$this->echoonly) {
         $this->pdo->queryExec(sprintf("update releases set name=%s, searchname = %s WHERE id = %d", $this->pdo->escapeString($newname), $this->pdo->escapeString($newname), $id));
     }
 }
Ejemplo n.º 11
0
    /**
     * Retrieves a list of Anime titles, optionally filtered by starting character and title
     *
     * @param string $letter
     * @param string $animetitle
     * @return array|bool
     */
    public function getAnimeList($letter = '', $animetitle = '')
    {
        $regex = 'REGEXP';
        $rsql = '';
        if ($letter != '') {
            if ($letter == '0-9') {
                $letter = '[0-9]';
            }
            $rsql .= sprintf('AND at.title %s %s', $regex, $this->pdo->escapeString('^' . $letter));
        }
        $tsql = '';
        if ($animetitle != '') {
            $tsql .= sprintf('AND at.title %s', $this->pdo->likeString($animetitle, true, true));
        }
        return $this->pdo->queryDirect(sprintf('SELECT at.anidbid, at.title, ai.type, ai.categories, ai.rating, ai.startdate, ai.enddate
					FROM anidb_titles AS at LEFT JOIN anidb_info AS ai USING (anidbid)
					WHERE at.anidbid > 0 %s %s
					GROUP BY at.anidbid
					ORDER BY at.title ASC', $rsql, $tsql));
    }
Ejemplo n.º 12
0
    /**
     * Retrieve alternate release with same or similar searchname
     *
     * @param string $guid
     * @param string $searchname
     * @param string $userid
     * @return string
     */
    public function getAlternate($guid, $searchname, $userid)
    {
        //status values
        // 0/false 	= successfully downloaded
        // 1/true 	= failed download
        $this->pdo->queryInsert(sprintf("INSERT IGNORE INTO dnzb_failures (userid, guid) VALUES (%d, %s)", $userid, $this->pdo->escapeString($guid)));
        $alternate = $this->pdo->queryOneRow(sprintf('SELECT * FROM releases r
			WHERE r.searchname %s
			AND r.guid NOT IN (SELECT guid FROM failed_downloads WHERE userid = %d)', $this->pdo->likeString($searchname), $userid));
        return $alternate;
    }
Ejemplo n.º 13
0
    /**
     * Updates existing anime info in anidb info/episodes tables
     *
     * @param array $AniDBInfoArray
     *
     * @return string
     */
    private function updateAniDBInfoEps($AniDBInfoArray = array())
    {
        $this->pdo->queryExec(sprintf('
						UPDATE anidb_info
						SET type = %s, startdate = %s, enddate = %s, related = %s,
							similar = %s, creators = %s, description = %s,
							rating = %s, picture = %s, categories = %s, characters = %s,
							updated = NOW()
						WHERE anidbid = %d', $this->pdo->escapeString($AniDBInfoArray['type']), $this->pdo->escapeString($AniDBInfoArray['startdate']), $this->pdo->escapeString($AniDBInfoArray['enddate']), $this->pdo->escapeString($AniDBInfoArray['related']), $this->pdo->escapeString($AniDBInfoArray['similar']), $this->pdo->escapeString($AniDBInfoArray['creators']), $this->pdo->escapeString($AniDBInfoArray['description']), $this->pdo->escapeString($AniDBInfoArray['rating']), $this->pdo->escapeString($AniDBInfoArray['picture']), $this->pdo->escapeString($AniDBInfoArray['categories']), $this->pdo->escapeString($AniDBInfoArray['characters']), $this->anidbId));
        $this->insertAniDBEpisodes($AniDBInfoArray['epsarr']);
        return $AniDBInfoArray['picture'];
    }
Ejemplo n.º 14
0
 /**
  * Delete release from Sphinx RT tables.
  * @param array $identifiers ['g' => Release GUID(mandatory), 'id' => ReleaseID(optional, pass false)]
  * @param \newznab\db\Settings $pdo
  */
 public function deleteRelease($identifiers, Settings $pdo)
 {
     if (!is_null($this->sphinxQL)) {
         if ($identifiers['i'] === false) {
             $identifiers['i'] = $pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE guid = %s', $pdo->escapeString($identifiers['g'])));
             if ($identifiers['i'] !== false) {
                 $identifiers['i'] = $identifiers['i']['id'];
             }
         }
         if ($identifiers['i'] !== false) {
             $this->sphinxQL->queryExec(sprintf('DELETE FROM releases_rt WHERE id = %d', $identifiers['i']));
         }
     }
 }
Ejemplo n.º 15
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.º 16
0
 /**
  * Insert or update a musicinfo row.
  */
 public function addUpdateMusicInfo($title, $asin, $url, $salesrank, $artist, $publisher, $releasedate, $review, $year, $genreID, $tracks, $cover)
 {
     if (strlen($year) > 4) {
         if (preg_match("/\\d{4}/", $year, $matches)) {
             $year = $this->pdo->escapeString($matches[0]);
         } else {
             $year = "null";
         }
     } else {
         $year = $this->pdo->escapeString($year);
     }
     $sql = sprintf("\n\t\tINSERT INTO musicinfo  (title, asin, url, salesrank,  artist, publisher, releasedate, review, year, genreID, tracks, cover, createddate, updateddate)\n\t\tVALUES (%s, %s, %s,  %s,  %s, %s, %s, %s, %s,   %s, %s, %d, now(), now())\n\t\t\tON DUPLICATE KEY UPDATE  title = %s,  asin = %s,  url = %s,  salesrank = %s,  artist = %s,  publisher = %s,  releasedate = %s,  review = %s,  year = %s,  genreID = %s,  tracks = %s,  cover = %d,  createddate = now(),  updateddate = now()", $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $salesrank, $this->pdo->escapeString($artist), $this->pdo->escapeString($publisher), $releasedate, $this->pdo->escapeString($review), $year, $genreID == -1 ? "null" : $genreID, $this->pdo->escapeString($tracks), $cover, $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $salesrank, $this->pdo->escapeString($artist), $this->pdo->escapeString($publisher), $releasedate, $this->pdo->escapeString($review), $this->pdo->escapeString($year), $genreID == -1 ? "null" : $genreID, $this->pdo->escapeString($tracks), $cover);
     $musicId = $this->pdo->queryInsert($sql);
     return $musicId;
 }
Ejemplo n.º 17
0
 /**
  * Try to match a single release to a PreDB title when the release is created.
  *
  * @param string $cleanerName
  *
  * @return array|bool Array with title/id from PreDB if found, bool False if not found.
  */
 public function matchPre($cleanerName)
 {
     if ($cleanerName == '') {
         return false;
     }
     $titleCheck = $this->pdo->queryOneRow(sprintf('SELECT id FROM prehash WHERE title = %s LIMIT 1', $this->pdo->escapeString($cleanerName)));
     if ($titleCheck !== false) {
         return array('title' => $cleanerName, 'prehashid' => $titleCheck['id']);
     }
     // Check if clean name matches a PreDB filename.
     $fileCheck = $this->pdo->queryOneRow(sprintf('SELECT id, title FROM prehash WHERE filename = %s LIMIT 1', $this->pdo->escapeString($cleanerName)));
     if ($fileCheck !== false) {
         return array('title' => $fileCheck['title'], 'prehashid' => $fileCheck['id']);
     }
     return false;
 }
Ejemplo n.º 18
0
    /**
     * Safe backfill using posts. Going back to a date specified by the user on the site settings.
     * This does 1 group for x amount of parts until it reaches the date.
     *
     * @param string $articles
     *
     * @return void
     */
    public function safeBackfill($articles = '')
    {
        $groupname = $this->pdo->queryOneRow(sprintf('
				SELECT name FROM groups
				WHERE first_record_postdate BETWEEN %s AND NOW()
				AND backfill = 1
				ORDER BY name ASC', $this->pdo->escapeString($this->_safeBackFillDate)));
        if (!$groupname) {
            $dMessage = 'No groups to backfill, they are all at the target date ' . $this->_safeBackFillDate . ", or you have not enabled them to be backfilled in the groups page.\n";
            if ($this->_debug) {
                $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL);
            }
            exit($dMessage);
        } else {
            $this->backfillAllGroups($groupname['name'], $articles);
        }
    }
Ejemplo n.º 19
0
    /**
     * 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);
    }
Ejemplo n.º 20
0
 /**
  * Insert or update a bookinfo row.
  */
 public function addUpdateBookInfo($title, $asin, $url, $author, $publisher, $publishdate, $review, $cover, $dewey, $ean, $isbn, $pages)
 {
     if ($pages == 0) {
         $pages = "null";
     } else {
         $pages = $pages + 0;
     }
     if ($publishdate == "") {
         $publishdate = "null";
     } elseif (strlen($publishdate) == 4) {
         $publishdate = $this->pdo->escapeString($publishdate . "-01-01");
     } elseif (strlen($publishdate) == 7) {
         $publishdate = $this->pdo->escapeString($publishdate . "-01");
     } else {
         $publishdate = $this->pdo->escapeString($publishdate);
     }
     $sql = sprintf("INSERT INTO bookinfo  (title, asin, url, author, publisher, publishdate, review, cover, createddate, updateddate, dewey, ean, isbn, pages)\n\t\tVALUES (%s,  %s, %s, %s, %s, %s,  %s, %d, now(), now(), %s, %s, %s, %s)\n\t\t\tON DUPLICATE KEY UPDATE  title = %s,  asin = %s,  url = %s,   author = %s,  publisher = %s,  publishdate = %s,  review = %s, cover = %d,  createddate = now(),  updateddate = now(), dewey = %s, ean = %s, isbn = %s, pages = %s", $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $publishdate, $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages, $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $this->pdo->escapeString($publishdate), $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages);
     $bookId = $this->pdo->queryInsert($sql);
     return $bookId;
 }
Ejemplo n.º 21
0
    /**
     * Add/Update predb row.
     *
     * @param newznab\db\Settings $pdo
     * @param    $preArray
     * @return bool
     */
    public function updatePreDB(Settings $pdo, $preArray)
    {
        if (!preg_match('/^(UN)?((MOD)?NUKED?|DELPRE)$/', $preArray['category'])) {
            $pdo->queryExec(sprintf('INSERT INTO predb
				(ctime, dirname, category, filesize, filecount, filename)
				VALUES (%d, %s, %s, %F, %d, %s)
				ON DUPLICATE KEY UPDATE
				category=%3$s, filesize=%4$F, filecount=%5$d, filename=%6$s', $preArray['ctime'], $this->pdo->escapeString($preArray['dirname']), $this->pdo->escapeString($preArray['category']), !empty($preArray['filesize']) ? (double) $preArray['filesize'] : 0, !empty($preArray['filecount']) ? (int) $preArray['filecount'] : 0, !empty($preArray['nuke_filename']) ? $this->pdo->escapeString($preArray['nuke_filename']) : '""'));
            //$newCheck = mysql_affected_rows();
            //if($this->echooutput && $newCheck > 0)
            //	echo "!PRE: [".date('Y-m-d H:i:s', $preArray['ctime']).'] - [ '.$preArray['dirname'].' ] - ['.$preArray['category']."]\n";
            return true;
        } else {
            $pdo->queryExec(sprintf("update predb\n\t\t\t\tSET nuketype=%s, nukereason=%s, nuketime=%d\n\t\t\t\tWHERE dirname = %s", $this->pdo->escapeString($preArray['category']), !empty($preArray['nuke_filename']) ? $this->pdo->escapeString($preArray['nuke_filename']) : '""', $preArray['ctime'], $this->pdo->escapeString($preArray['dirname'])));
            //$newCheck = mysql_affected_rows();
            //if($this->echooutput && $newCheck > 0)
            //	echo $preArray['category'].': ['.date('Y-m-d H:i:s', $preArray['ctime']).'] - [ '.$preArray['dirname'].' ] - ['.$preArray['nuke_filename']."]\n";
            return true;
        }
        return false;
    }
Ejemplo n.º 22
0
    protected function _updateConsoleTable($con = [])
    {
        $ri = new \ReleaseImage($this->pdo);
        $check = $this->pdo->queryOneRow(sprintf('
							SELECT id
							FROM consoleinfo
							WHERE asin = %s', $this->pdo->escapeString($con['asin'])));
        if ($check === false) {
            $consoleId = $this->pdo->queryInsert(sprintf("INSERT INTO consoleinfo (title, asin, url, salesrank, platform, publisher, genreid, esrb, releasedate, review, cover, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, NOW(), NOW())", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $con['salesrank'], $this->pdo->escapeString($con['platform']), $this->pdo->escapeString($con['publisher']), $con['consolegenreid'] == -1 ? "null" : $con['consolegenreid'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover']));
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
        } else {
            $consoleId = $check['id'];
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
            $this->update($consoleId, $con['title'], $con['asin'], $con['url'], $con['salesrank'], $con['platform'], $con['publisher'], isset($con['releasedate']) ? $con['releasedate'] : null, $con['esrb'], $con['cover'], $con['consolegenreid'], isset($con['review']) ? $con['review'] : null);
        }
        return $consoleId;
    }
Ejemplo n.º 23
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'], '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;
 }
Ejemplo n.º 24
0
    /**
     * Return all blacklists.
     *
     * @param bool   $activeOnly Only display active blacklists ?
     * @param int    $opType     Optional, get white or black lists (use Binaries constants).
     * @param string $groupName  Optional, group.
     * @param bool   $groupRegex Optional Join groups / binaryblacklist using regexp for equals.
     *
     * @return array
     */
    public function getBlacklist($activeOnly = true, $opType = -1, $groupName = '', $groupRegex = false)
    {
        switch ($opType) {
            case self::OPTYPE_BLACKLIST:
                $opType = 'AND binaryblacklist.optype = ' . self::OPTYPE_BLACKLIST;
                break;
            case self::OPTYPE_WHITELIST:
                $opType = 'AND binaryblacklist.optype = ' . self::OPTYPE_WHITELIST;
                break;
            default:
                $opType = '';
                break;
        }
        return $this->_pdo->query(sprintf('
				SELECT
					binaryblacklist.id, binaryblacklist.optype, binaryblacklist.status, binaryblacklist.description,
					binaryblacklist.groupname AS groupname, binaryblacklist.regex, groups.id AS group_id, binaryblacklist.msgcol,
					binaryblacklist.last_activity as last_activity
				FROM binaryblacklist
				LEFT OUTER JOIN groups ON groups.name %s binaryblacklist.groupname
				WHERE 1=1 %s %s %s
				ORDER BY coalesce(groupname,\'zzz\')', $groupRegex ? 'REGEXP' : '=', $activeOnly ? 'AND binaryblacklist.status = 1' : '', $opType, $groupName ? 'AND groups.name REGEXP ' . $this->_pdo->escapeString($groupName) : ''));
    }
Ejemplo n.º 25
0
    /**
     * Attempt to get a better name from a par2 file and categorize the release.
     *
     * @note Called from NZBContents.php
     *
     * @param string $messageID MessageID from NZB file.
     * @param int    $relID     id of the release.
     * @param int    $groupID   Group id of the release.
     * @param \NNTP   $nntp      Class NNTP
     * @param int    $show      Only show result or apply iy.
     *
     * @return bool
     */
    public function parsePAR2($messageID, $relID, $groupID, &$nntp, $show)
    {
        if ($messageID === '') {
            return false;
        }
        $query = $this->pdo->queryOneRow(sprintf('
				SELECT id, groupid, categoryid, name, searchname, UNIX_TIMESTAMP(postdate) AS post_date, id AS releaseid
				FROM releases
				WHERE isrenamed = 0
				AND id = %d', $relID));
        if ($query === false) {
            return false;
        }
        // Only get a new name if the category is OTHER.
        $foundName = true;
        if (!in_array((int) $query['categoryid'], array(\Category::CAT_BOOK_OTHER, \Category::CAT_GAME_OTHER, \Category::CAT_MOVIE_OTHER, \Category::CAT_MUSIC_OTHER, \Category::CAT_PC_MOBILEOTHER, \Category::CAT_TV_OTHER, \Category::CAT_MISC_HASHED, \Category::CAT_XXX_OTHER, \Category::CAT_MISC_OTHER))) {
            $foundName = false;
        }
        // Get the PAR2 file.
        $par2 = $nntp->getMessages($this->groups->getByNameByID($groupID), $messageID, $this->alternateNNTP);
        if ($nntp->isError($par2)) {
            return false;
        }
        // Put the PAR2 into Par2Info, check if there's an error.
        $this->_par2Info->setData($par2);
        if ($this->_par2Info->error) {
            return false;
        }
        // Get the file list from Par2Info.
        $files = $this->_par2Info->getFileList();
        if ($files !== false && count($files) > 0) {
            $filesAdded = 0;
            // Loop through the files.
            foreach ($files as $file) {
                if (!isset($file['name'])) {
                    continue;
                }
                // If we found a name and added 10 files, stop.
                if ($foundName === true && $filesAdded > 10) {
                    break;
                }
                if ($this->addpar2) {
                    // Add to release files.
                    if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf('
								SELECT id
								FROM releasefiles
								WHERE releaseid = %d
								AND name = %s', $relID, $this->pdo->escapeString($file['name']))) === false) {
                        // Try to add the files to the DB.
                        if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) {
                            $filesAdded++;
                        }
                    }
                } else {
                    $filesAdded++;
                }
                // Try to get a new name.
                if ($foundName === false) {
                    $query['textstring'] = $file['name'];
                    if ($this->nameFixer->checkName($query, 1, 'PAR2, ', 1, $show) === true) {
                        $foundName = true;
                    }
                }
            }
            // If we found some files.
            if ($filesAdded > 0) {
                $this->debugging->log(get_class(), __FUNCTION__, 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO);
                // Update the file count with the new file count + old file count.
                $this->pdo->queryExec(sprintf('
						UPDATE releases
						SET rarinnerfilecount = rarinnerfilecount + %d
						WHERE id = %d', $filesAdded, $relID));
            }
            if ($foundName === true) {
                return true;
            }
        }
        return false;
    }
Ejemplo n.º 26
0
 private function store_blob($nfometa, $blobhash, $removed)
 {
     // This takes a array of blobs with their index id being
     // the release id;  In the event we fetch the data and deem
     // it no good, we need to add it to the skipped array which
     // must be passed into the function.
     $db = new Settings();
     foreach ($blobhash as $uid => $blob) {
         $query = sprintf("REPLACE INTO releasenfo (id, releaseid, binaryID, nfo) " . "VALUES (NULL, %d, 0, compress(%s));", $uid, $db->escapeString($blob));
         $id = $db->queryInsert($query);
         if (!$id) {
             if ($this->verbose) {
                 echo "!";
             }
         } else {
             $query = sprintf("UPDATE releases SET releasenfoid = %d WHERE id = %d LIMIT 1", $id, $uid);
             $res = $db->queryExec($query);
             if ($this->verbose) {
                 echo "s";
             }
         }
     }
     // Now we update the database with entries that have no nfo files
     // associated with the release
     foreach ($removed as $uid) {
         $res = $this->setNfoMissing($uid);
         if ($res <= 0) {
             if ($this->verbose) {
                 echo "!";
             }
         } else {
             if ($this->verbose) {
                 echo "s";
             }
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * Add a new blacklist row.
  */
 public function addBlacklist($regex)
 {
     $db = new Settings();
     $groupname = $regex["groupname"];
     if ($groupname == "") {
         $groupname = "null";
     } else {
         $groupname = preg_replace("/a\\.b\\./i", "alt.binaries.", $groupname);
         $groupname = sprintf("%s", $db->escapeString($groupname));
     }
     return $db->queryInsert(sprintf("insert into binaryblacklist (groupname, regex, status, description, optype, msgcol) values (%s, %s, %d, %s, %d, %d) ", $groupname, $db->escapeString($regex["regex"]), $regex["status"], $db->escapeString($regex["description"]), $regex["optype"], $regex["msgcol"]));
 }
Ejemplo n.º 28
0
             system($command);
         }
     }
     $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
 } else {
     if (isset($argv[1]) && $argv[1] == "all" && (isset($argv[2]) && $argv[2] == "outfile") && (isset($argv[3]) && file_exists($argv[3]))) {
         $sql = "SHOW tables";
         $tables = $pdo->query($sql);
         foreach ($tables as $row) {
             $tbl = $row['tables_in_' . DB_NAME];
             $filename = $argv[3] . $tbl . ".csv";
             echo $pdo->log->header("Dumping {$tbl}.");
             if (file_exists($filename)) {
                 newname($filename);
             }
             $pdo->queryDirect(sprintf("SELECT * INTO OUTFILE %s FROM %s", $pdo->escapeString($filename), $tbl));
         }
     } else {
         if (isset($argv[1]) && $argv[1] == "all" && (isset($argv[2]) && $argv[2] == "infile") && (isset($argv[3]) && is_dir($argv[3]))) {
             $sql = "SHOW tables";
             $tables = $pdo->query($sql);
             $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
             foreach ($tables as $row) {
                 $tbl = $row['tables_in_' . DB_NAME];
                 $filename = $argv[3] . $tbl . ".csv";
                 if (file_exists($filename)) {
                     echo $pdo->log->header("Restoring {$tbl}.");
                     $pdo->queryExec(sprintf("LOAD DATA INFILE %s INTO TABLE %s", $pdo->escapeString($filename), $tbl));
                 }
             }
             $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
Ejemplo n.º 29
0
 /**
  *
  */
 public function processReleases()
 {
     $results = $this->pdo->queryDirect(sprintf("SELECT id, searchname, rageid, anidbid, seriesfull, season, episode, tvtitle FROM releases WHERE episodeinfoid IS NULL AND categoryid IN ( SELECT id FROM category WHERE parentid = %d ) LIMIT 150", Category::CAT_PARENT_TV));
     if ($this->pdo->getNumRows($results) > 0) {
         if ($this->echooutput) {
             echo "TheTVDB : Looking up last " . $this->pdo->getNumRows($results) . " releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($results)) {
             unset($TheTVDBAPIArray, $episodeArray, $fullep, $epabsolute, $additionalSql);
             $seriesName = '';
             if ($arr['rageid'] > 0) {
                 $seriesName = $this->pdo->queryOneRow(sprintf('SELECT releasetitle AS seriesName FROM tvrage WHERE rageid = %d', $arr['rageid']));
             } elseif ($arr['anidbid'] > 0) {
                 $seriesName = $this->pdo->queryOneRow(sprintf('SELECT title AS seriesName FROM anidb WHERE anidbid = %d', $arr['anidbid']));
             }
             if (empty($seriesName) || !$seriesName) {
                 $this->notFound($seriesName, "", $arr['id'], false);
                 continue;
             }
             $seriesName = str_replace('`', '\'', $seriesName['seriesName']);
             if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $arr['seriesfull'])) {
                 $fullep = str_pad(str_replace('S', '', $arr['season']), 2, '0', STR_PAD_LEFT) . 'x' . str_pad(str_replace('E', '', $arr['episode']), 2, '0', STR_PAD_LEFT);
             } else {
                 $fullep = str_replace('/', '-', $arr['seriesfull']);
             }
             $TheTVDBAPIArray = $this->getSeriesInfoByName($seriesName);
             if (!$TheTVDBAPIArray) {
                 $seriesid = $this->lookupSeriesID($seriesName);
                 if ($seriesid > 0) {
                     $TheTVDBAPIArray = $this->TheTVDBAPI($seriesid, $seriesName);
                     if ($TheTVDBAPIArray) {
                         $this->addSeries($TheTVDBAPIArray);
                         $this->addEpisodes($TheTVDBAPIArray);
                     } else {
                         $this->addEmptySeries($seriesName);
                         $this->notFound($seriesName, $fullep, $arr['id']);
                         continue;
                     }
                 } else {
                     $this->addEmptySeries($seriesName);
                     $this->notFound($seriesName, $fullep, $arr['id']);
                     continue;
                 }
             } else {
                 if ($TheTVDBAPIArray['tvdbid'] > 0 && time() - strtotime($TheTVDBAPIArray['createddate']) > 604800) {
                     $TheTVDBAPIArray = $this->TheTVDBAPI($TheTVDBAPIArray['tvdbid'], $seriesName);
                     $this->updateSeries($TheTVDBAPIArray['tvdbid'], $TheTVDBAPIArray['actors'], $TheTVDBAPIArray['airsday'], $TheTVDBAPIArray['airstime'], $TheTVDBAPIArray['contentrating'], $TheTVDBAPIArray['firstaired'], $TheTVDBAPIArray['genre'], $TheTVDBAPIArray['imdbid'], $TheTVDBAPIArray['network'], $TheTVDBAPIArray['overview'], $TheTVDBAPIArray['rating'], $TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $TheTVDBAPIArray['seriesname'], $TheTVDBAPIArray['status']);
                     $this->addEpisodes($TheTVDBAPIArray);
                 }
             }
             if ($TheTVDBAPIArray['tvdbid'] > 0) {
                 $epabsolute = '0';
                 if ($arr['anidbid'] > 0) {
                     if (preg_match('/S(?P<season>\\d+)[ED](?P<episode>\\d+)/', $arr['episode'], $seasonEpisode)) {
                         $arr['season'] = $seasonEpisode['season'];
                         $arr['episode'] = $seasonEpisode['episode'];
                     } else {
                         $epabsolute = $arr['episode'];
                     }
                 }
                 $Episode = new Episode();
                 $episodeArray = $Episode->getEpisodeInfoByName($seriesName, $fullep, (string) $epabsolute);
                 if (!$episodeArray) {
                     $this->notFound($seriesName, $fullep, $arr['id']);
                     continue;
                 }
             } else {
                 $this->notFound($seriesName, $fullep, $arr['id']);
                 continue;
             }
             $additionalSql = '';
             if ($arr['anidbid'] > 0 && $episodeArray['epabsolute'] > 0) {
                 $additionalSql = sprintf(', season = NULL, episode = %d, tvtitle = %s, tvairdate = %s', $episodeArray['epabsolute'], $this->pdo->escapeString($episodeArray['epabsolute'] . ' - ' . str_replace('\'', '`', $episodeArray['eptitle'])), $this->pdo->escapeString($episodeArray['airdate']));
             }
             $this->pdo->queryExec(sprintf('UPDATE releases SET tvdbid = %d, episodeinfoid = %d %s WHERE id = %d', $TheTVDBAPIArray['tvdbid'], $episodeArray['id'], $additionalSql, $arr['id']));
             if ($this->echooutput) {
                 echo 'TheTVDB : ' . $seriesName . ' ' . $fullep . " returned " . $episodeArray['tvdbid'] . "\n";
             }
         }
     }
 }
Ejemplo n.º 30
0
    /**
     * Attempt to find NFO files inside the NZB's of releases.
     *
     * @param object $nntp           Instance of class NNTP.
     * @param string $groupID        (optional) Group id.
     * @param string $guidChar       (optional) First character of the release GUID (used for multi-processing).
     * @param int    $processImdb    (optional) Attempt to find IMDB id's in the NZB?
     * @param int    $processTvrage  (optional) Attempt to find TvRage id's in the NZB?
     *
     * @return int                   How many NFO's were processed?
     *
     * @access public
     */
    public function processNfoFiles($nntp, $groupID = '', $guidChar = '', $processImdb = 1, $processTvrage = 1)
    {
        $ret = 0;
        $guidCharQuery = $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true);
        $groupIDQuery = $groupID === '' ? '' : 'AND r.groupid = ' . $groupID;
        $optionsQuery = self::NfoQueryString($this->pdo);
        $res = $this->pdo->query(sprintf('
				SELECT r.id, r.guid, r.groupid, r.name
				FROM releases r
				WHERE 1=1 %s %s %s
				ORDER BY r.nfostatus ASC, r.postdate DESC
				LIMIT %d', $optionsQuery, $guidCharQuery, $groupIDQuery, $this->nzbs));
        $nfoCount = count($res);
        if ($nfoCount > 0) {
            $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . ($guidChar === '' ? '' : '[' . $guidChar . '] ') . ($groupID === '' ? '' : '[' . $groupID . '] ') . 'Processing ' . $nfoCount . ' NFO(s), starting at ' . $this->nzbs . ' * = hidden NFO, + = NFO, - = no NFO, f = download failed.'));
            if ($this->echo) {
                // Get count of releases per nfo status
                $nfoStats = $this->pdo->queryDirect(sprintf('
						SELECT r.nfostatus AS status, COUNT(*) AS count
						FROM releases r
						WHERE 1=1 %s %s %s
						GROUP BY r.nfostatus
						ORDER BY r.nfostatus ASC', $optionsQuery, $guidCharQuery, $groupIDQuery));
                if ($nfoStats instanceof Traversable) {
                    $outString = PHP_EOL . 'Available to process';
                    foreach ($nfoStats as $row) {
                        $outString .= ', ' . $row['status'] . ' = ' . number_format($row['count']);
                    }
                    $this->pdo->log->doEcho($this->pdo->log->header($outString . '.'));
                }
            }
            $groups = new Groups(['Settings' => $this->pdo]);
            $nzbContents = new NZBContents(['Echo' => $this->echo, 'NNTP' => $nntp, 'Nfo' => $this, 'Settings' => $this->pdo, 'PostProcess' => new PostProcess(['Echo' => $this->echo, 'Nfo' => $this, 'Settings' => $this->pdo])]);
            $movie = new Movie(['Echo' => $this->echo, 'Settings' => $this->pdo]);
            $tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]);
            foreach ($res as $arr) {
                $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['groupid'], $groups->getByNameByID($arr['groupid']));
                if ($fetchedBinary !== false) {
                    // Insert nfo into database.
                    $cp = 'COMPRESS(%s)';
                    $nc = $this->pdo->escapeString($fetchedBinary);
                    $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT id FROM releasenfo WHERE releaseid = %d', $arr['id']));
                    if (!isset($ckreleaseid['id'])) {
                        $this->pdo->queryInsert(sprintf('INSERT INTO releasenfo (nfo, releaseid) VALUES (' . $cp . ', %d)', $nc, $arr['id']));
                    }
                    $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $arr['id']));
                    $ret++;
                    $movie->doMovieUpdate($fetchedBinary, 'nfo', $arr['id'], $processImdb);
                    // If set scan for tvrage info.
                    if ($processTvrage == 1) {
                        $rageId = $this->parseRageId($fetchedBinary);
                        if ($rageId !== false) {
                            $show = $tvRage->parseNameEpSeason($arr['name']);
                            if (is_array($show) && $show['name'] != '') {
                                // Update release with season, ep, and air date info (if available) from release title.
                                $tvRage->updateEpInfo($show, $arr['id']);
                                $rid = $tvRage->getByRageID($rageId);
                                if (!$rid) {
                                    $tvrShow = $tvRage->getRageInfoFromService($rageId);
                                    $tvRage->updateRageInfo($rageId, $show, $tvrShow, $arr['id']);
                                }
                            }
                        }
                    }
                }
            }
        }
        // Remove nfo that we cant fetch after 5 attempts.
        $releases = $this->pdo->queryDirect(sprintf('SELECT r.id
				FROM releases r
				WHERE r.nzbstatus = %d
				AND r.nfostatus < %d %s %s', NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery));
        if ($releases instanceof Traversable) {
            foreach ($releases as $release) {
                $this->pdo->queryExec(sprintf('DELETE FROM releasenfo WHERE nfo IS NULL AND releaseid = %d', $release['id']));
            }
        }
        // Set releases with no NFO.
        $this->pdo->queryExec(sprintf('
				UPDATE releases r
				SET r.nfostatus = %d
				WHERE r.nzbstatus = %d
				AND r.nfostatus < %d %s %s', self::NFO_FAILED, NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery));
        if ($this->echo) {
            if ($nfoCount > 0) {
                echo PHP_EOL;
            }
            if ($ret > 0) {
                $this->pdo->log->doEcho($ret . ' NFO file(s) found/processed.', true);
            }
        }
        return $ret;
    }