/** * 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; }
/** * Fetch a comment and insert it. * * @param string $messageID Message-ID for the article. * @param string $siteID ID of the site. * * @return bool * * @access protected */ 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; } // Insert the comment. if ($this->pdo->queryExec(sprintf(' INSERT INTO release_comments (text, createddate, shareid, nzb_guid, siteid, username, user_id, releaseid, shared, host) VALUES (%s, %s, %s, UNHEX(%s), %s, %s, 0, 0, 2, "")', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $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; }
/** * Download and process binaries for JPG pictures. * * @void * @access protected */ protected function _processJPGMessageIDs() { // Download JPG file. if ($this->_foundJPGSample === false && !empty($this->_JPGMessageIDs)) { // Try to download it. $jpgBinary = $this->_nntp->getMessages($this->_releaseGroupName, $this->_JPGMessageIDs, $this->_alternateNNTP); if ($this->_nntp->isError($jpgBinary)) { $jpgBinary = false; } if ($jpgBinary !== false) { if ($this->_echoCLI) { $this->_echo('(jB)', 'primaryOver', false); } // Try to create a file with it. @file_put_contents($this->tmpPath . 'samplepicture.jpg', $jpgBinary); // Try to resize and move it. $this->_foundJPGSample = $this->_releaseImage->saveImage($this->_release['guid'] . '_thumb', $this->tmpPath . 'samplepicture.jpg', $this->_releaseImage->jpgSavePath, 650, 650) === 1 ? true : false; if ($this->_foundJPGSample !== false) { // Update the DB to say we got it. $this->pdo->queryExec(sprintf(' UPDATE releases SET jpgstatus = %d WHERE id = %d', 1, $this->_release['id'])); if ($this->_echoCLI) { $this->_echo('j', 'primaryOver', false); } } @unlink($this->tmpPath . 'samplepicture.jpg'); } else { if ($this->_echoCLI) { $this->_echo('f', 'warningOver', false); } } } }
/** * 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 \nzedb\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, group_id, 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'], [Category::CAT_BOOKS_OTHER, Category::CAT_GAME_OTHER, Category::CAT_MOVIE_OTHER, Category::CAT_MUSIC_OTHER, Category::CAT_PC_PHONE_OTHER, Category::CAT_TV_OTHER, Category::CAT_OTHER_HASHED, Category::CAT_XXX_OTHER, Category::CAT_MISC])) { $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 release_files 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('PostProcess', 'parsePAR2', 'Added ' . $filesAdded . ' release_files 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; }