/** * 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 array('hidden' => false, 'ID' => $messageID); } elseif ($hiddenNFO === true && strlen($hiddenID) > 1) { return array('hidden' => true, 'ID' => $hiddenID); } } return 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 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'], array(\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 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('PostProcess', 'parsePAR2', '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; }
/** * If a collection did not have the file count (ie: [00/12]) or the collection is incomplete after * $this->collectionDelayTime hours, set the collection to complete to create it into a release/nzb. * * @param array $group * @param string $where * * @void * @access private */ private function collectionFileCheckStage6(array &$group, &$where) { $this->pdo->queryExec(sprintf("\n\t\t\t\tUPDATE %s c SET filecheck = %d, totalfiles = (SELECT COUNT(b.id) FROM %s b WHERE b.collectionid = c.id)\n\t\t\t\tWHERE c.dateadded < NOW() - INTERVAL '%d' HOUR\n\t\t\t\tAND c.filecheck IN (%d, %d, 10) %s", $group['cname'], self::COLLFC_COMPPART, $group['bname'], $this->collectionDelayTime, self::COLLFC_DEFAULT, self::COLLFC_COMPCOLL, $where)); }
continue; } $newName = ''; $handle = @fopen($tmpPath . $fileName, 'r'); if ($handle) { while (($buffer = fgets($handle, 16384)) !== false) { if (stripos($buffer, 'mkdir') !== false) { $newName = trim(str_replace('mkdir', '', $buffer)); break; } } fclose($handle); } @unlink($tmpPath . $fileName); if ($newName === '') { echo 'ERROR: New name is empty!' . PHP_EOL; continue; } $determinedCat = $categorize->determineCategory($newName, $release['group_id']); NameFixer::echoChangedReleaseName(array('new_name' => $newName, 'old_name' => $release['oldname'], 'new_category' => $categorize->getNameByid($determinedCat), 'old_category' => $categorize->getNameByid($release['categoryid']), 'group' => $release['groupname'], 'release_id' => $release['id'], 'method' => 'misc/testing/Dev/rename_u4e.php')); $newName = $pdo->escapeString(substr($newName, 0, 255)); $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, preid = 0, searchname = %s, isrenamed = 1, iscategorized = 1, proc_files = 1, categoryid = %d WHERE id = %d', $newName, $determinedCat, $release['id'])); $sphinx->updateReleaseSearchName($release['id'], $newName); } }
/** * Delete all Collections/Binaries/Parts for a group ID. * * @param int $groupID The ID of the group. * * @note A trigger automatically deletes the parts/binaries. * * @return void */ public function purgeGroup($groupID) { $this->_pdo->queryExec(sprintf('DELETE c FROM collections c WHERE c.group_id = %d', $groupID)); }