From d9be9825712e68165c19bdedf7dd7bd706bce01e Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 27 Feb 2017 14:35:15 +0100 Subject: [PATCH] Add files now --- nntmux/NZBContents.php | 8 +++---- nntmux/ReleaseFiles.php | 21 +++++++++++++++---- nntmux/processing/PostProcess.php | 14 ++----------- nntmux/processing/post/ProcessAdditional.php | 18 ++++------------ resources/db/patches/mysql/+1~par2_hashes.sql | 11 ++++++++++ 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/nntmux/NZBContents.php b/nntmux/NZBContents.php index 94d2d2b5b..f5414294f 100755 --- a/nntmux/NZBContents.php +++ b/nntmux/NZBContents.php @@ -298,12 +298,10 @@ Class NZBContents $nzbFile = $this->LoadNZB($guid); if ($nzbFile !== false) { foreach ($nzbFile->file as $nzbContents) { - if (preg_match('/\.(par[2" ]|\d{2,3}").+\(1\/1\)/i', (string)$nzbContents->attributes()->subject)) { - if ($this->pp->parsePAR2((string)$nzbContents->segments->segment, $relID, $groupID, $this->nntp, $show) === true && $nameStatus === 1) { - $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID)); + if ($nameStatus === 1 && $this->pp->parsePAR2((string)$nzbContents->segments->segment, $relID, $groupID, $this->nntp, $show) === true && preg_match('/\.(par[2" ]|\d{2,3}").+\(1\/1\)/i', (string)$nzbContents->attributes()->subject)) { + $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID)); - return true; - } + return true; } } } diff --git a/nntmux/ReleaseFiles.php b/nntmux/ReleaseFiles.php index 9bdf72cca..e3377537f 100755 --- a/nntmux/ReleaseFiles.php +++ b/nntmux/ReleaseFiles.php @@ -71,13 +71,14 @@ class ReleaseFiles * * @param int $id The ID of the release. * @param string $name Name of the file. - * @param int $size Size of the file. + * @param string $hash hash_16k of par2 + * @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) + public function add($id, $name, $hash = '', $size, $createdTime, $hasPassword) { $insert = 0; @@ -93,18 +94,30 @@ class ReleaseFiles if ($duplicateCheck === false) { $insert = $this->pdo->queryInsert( - sprintf(" + sprintf(' INSERT INTO release_files (releases_id, name, size, createddate, passworded) VALUES - (%d, %s, %s, %s, %d)", + (%d, %s, %s, %s, %s, %d)', $id, $this->pdo->escapeString(utf8_encode($name)), + !empty($this->pdo->escapeString($hash)) ?? '', $this->pdo->escapeString($size), $this->pdo->from_unixtime($createdTime), $hasPassword ) ); + + $this->pdo->queryExec( + sprintf(' + INSERT INTO par_hashes + (releases_id, name, hash) + VALUES (%d, %s, %s)', + $id, + $this->pdo->escapeString(utf8_encode($name)), + !empty($this->pdo->escapeString($hash)) ?? '' + ) + ); $this->sphinxSearch->updateRelease($id, $this->pdo); } return $insert; diff --git a/nntmux/processing/PostProcess.php b/nntmux/processing/PostProcess.php index 686612fb4..a9200ca4b 100755 --- a/nntmux/processing/PostProcess.php +++ b/nntmux/processing/PostProcess.php @@ -355,17 +355,7 @@ class PostProcess $foundName = true; if (in_array( (int)$query['categories_id'], - [ - Category::BOOKS_UNKNOWN, - Category::GAME_OTHER, - Category::MOVIE_OTHER, - Category::MUSIC_OTHER, - Category::PC_PHONE_OTHER, - Category::TV_OTHER, - Category::OTHER_HASHED, - Category::XXX_OTHER, - Category::OTHER_MISC - ] + Category::OTHERS_GROUP ) ) { $foundName = false; @@ -417,7 +407,7 @@ class PostProcess ) { // Try to add the files to the DB. - if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) { + if ($this->releaseFiles->add($relID, $file['name'], $file['hash_16K'], $file['size'], $query['post_date'], 0)) { $filesAdded++; } } diff --git a/nntmux/processing/post/ProcessAdditional.php b/nntmux/processing/post/ProcessAdditional.php index 3a5f3dfca..cfea96206 100755 --- a/nntmux/processing/post/ProcessAdditional.php +++ b/nntmux/processing/post/ProcessAdditional.php @@ -2252,20 +2252,10 @@ class ProcessAdditional // Only get a new name if the category is OTHER. $foundName = true; if (NN_RENAME_PAR2 && - $releaseInfo['proc_pp'] == 0 && + $releaseInfo['proc_pp'] === 0 && in_array( - ((int)$this->_release['categories_id']), - [ - Category::BOOKS_UNKNOWN, - Category::GAME_OTHER, - Category::MOVIE_OTHER, - Category::MUSIC_OTHER, - Category::PC_PHONE_OTHER, - Category::TV_OTHER, - Category::OTHER_HASHED, - Category::XXX_OTHER, - Category::OTHER_MISC - ] + (int)$this->_release['categories_id'], + Category::OTHERS_GROUP ) ) { $foundName = false; @@ -2297,7 +2287,7 @@ class ProcessAdditional ) { // Try to add the files to the DB. - if ($this->_releaseFiles->add($this->_release['id'], $file['name'], $file['size'], $releaseInfo['postdate'], 0)) { + if ($this->_releaseFiles->add($this->_release['id'], $file['name'], $file['hash_16K'], $file['size'], $releaseInfo['postdate'], 0)) { $filesAdded++; } } diff --git a/resources/db/patches/mysql/+1~par2_hashes.sql b/resources/db/patches/mysql/+1~par2_hashes.sql index e69de29bb..912bdf810 100644 --- a/resources/db/patches/mysql/+1~par2_hashes.sql +++ b/resources/db/patches/mysql/+1~par2_hashes.sql @@ -0,0 +1,11 @@ +# Create par_hashes table + +DROP TABLE IF EXISTS par_hashes; +CREATE TABLE par_hashes ( + releases_id INT(11) NOT NULL COMMENT 'FK to releases.id', + hash VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'hash of first 16k of rar files in par2 file', + PRIMARY KEY (releases_id, hash) + ) + ENGINE = MYISAM + DEFAULT CHARSET = utf8 + COLLATE = utf8_unicode_ci;