/** * Gets the completion from the NZB, optionally looks if there is an NFO/PAR2 file. * * @param string $guid * @param int $relID * @param int $groupID * @param bool $nfoCheck * * @return array|bool * * @access public */ public function parseNZB($guid, $relID, $groupID, $nfoCheck = false) { $nzbFile = $this->LoadNZB($guid); if ($nzbFile !== false) { $messageID = $hiddenID = ''; $actualParts = $artificialParts = 0; $foundPAR2 = $this->lookuppar2 === false ? true : false; $foundNFO = $hiddenNFO = $nfoCheck === false ? true : false; foreach ($nzbFile->file as $nzbcontents) { foreach ($nzbcontents->segments->segment as $segment) { $actualParts++; } $subject = (string) $nzbcontents->attributes()->subject; if (preg_match('/(\\d+)\\)$/', $subject, $parts)) { $artificialParts += $parts[1]; } if ($foundNFO === false) { if (preg_match('/\\.\\b(nfo|inf|ofn)\\b(?![ .-])/i', $subject)) { $messageID = (string) $nzbcontents->segments->segment; $foundNFO = true; } } if ($foundNFO === false && $hiddenNFO === false) { if (preg_match('/\\(1\\/1\\)$/i', $subject) && !preg_match('/\\.(apk|bat|bmp|cbr|cbz|cfg|css|csv|cue|db|dll|doc|epub|exe|gif|htm|ico|idx|ini' . '|jpg|lit|log|m3u|mid|mobi|mp3|nib|nzb|odt|opf|otf|par|par2|pdf|psd|pps|png|ppt|r\\d{2,4}' . '|rar|sfv|srr|sub|srt|sql|rom|rtf|tif|torrent|ttf|txt|vb|vol\\d+\\+\\d+|wps|xml|zip)/i', $subject)) { $hiddenID = (string) $nzbcontents->segments->segment; $hiddenNFO = true; } } if ($foundPAR2 === false) { if (preg_match('/\\.(par[2" ]|\\d{2,3}").+\\(1\\/1\\)$/i', $subject)) { if ($this->pp->parsePAR2((string) $nzbcontents->segments->segment, $relID, $groupID, $this->nntp, 1) === true) { $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID)); $foundPAR2 = true; } } } } if ($artificialParts <= 0 || $actualParts <= 0) { $completion = 0; } else { $completion = $actualParts / $artificialParts * 100; } if ($completion > 100) { $completion = 100; } $this->pdo->queryExec(sprintf('UPDATE releases SET completion = %d WHERE id = %d', $completion, $relID)); if ($foundNFO === true && strlen($messageID) > 1) { return ['hidden' => false, 'ID' => $messageID]; } elseif ($hiddenNFO === true && strlen($hiddenID) > 1) { return ['hidden' => true, 'ID' => $hiddenID]; } } return false; }