Esempio n. 1
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;
    }
Esempio n. 2
0
 /**
  * Work out all files contained inside a rar
  */
 public function processReleaseFiles($fetchedBinary, $relid)
 {
     $retval = array();
     $rar = new \ArchiveInfo();
     $rf = new ReleaseFiles();
     $rar->setData($fetchedBinary, true);
     if ($rar->error) {
         return false;
     }
     $files = $rar->getArchiveFileList();
     if ($files !== false) {
         foreach ($files as $file) {
             if (isset($file['name'])) {
                 $rf->add($relid, utf8_encode($file['name']), isset($file['size']) ? $file['size'] : "", isset($file['date']) ? $file['date'] : "", isset($file['pass']) ? $file['pass'] : "");
                 $retval[] = $file['name'];
             }
         }
     }
     unset($fetchedBinary);
     return $retval;
 }
Esempio n. 3
0
    /**
     * Get file info from inside PAR2, store it in DB, attempt to get a release name.
     *
     * @param string $fileLocation
     */
    protected function _siftPAR2Info($fileLocation)
    {
        $this->_par2Info->open($fileLocation);
        if ($this->_par2Info->error) {
            return;
        }
        $releaseInfo = $this->pdo->queryOneRow(sprintf('
				SELECT UNIX_TIMESTAMP(postdate) AS postdate, proc_pp
				FROM releases
				WHERE id = %d', $this->_release['id']));
        if ($releaseInfo === false) {
            return;
        }
        // Only get a new name if the category is OTHER.
        $foundName = true;
        if (NN_RENAME_PAR2 && $releaseInfo['proc_pp'] == 0 && in_array((int) $this->_release['categoryid'], [\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;
        }
        $filesAdded = 0;
        $files = $this->_par2Info->getFileList();
        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;
            }
            // Add to release files.
            if ($this->_addPAR2Files) {
                if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf('SELECT id FROM releasefiles WHERE releaseid = %d AND name = %s', $this->_release['id'], $this->pdo->escapeString($file['name']))) === false) {
                    // Try to add the files to the DB.
                    if ($this->_releaseFiles->add($this->_release['id'], $file['name'], $file['size'], $releaseInfo['postdate'], 0)) {
                        $filesAdded++;
                    }
                }
            } else {
                $filesAdded++;
            }
            // Try to get a new name.
            if ($foundName === false) {
                $this->_release['textstring'] = $file['name'];
                $this->_release['releaseid'] = $this->_release['id'];
                if ($this->_nameFixer->checkName($this->_release, $this->_echoCLI ? 1 : 0, 'PAR2, ', 1, 1) === true) {
                    $foundName = true;
                }
            }
        }
        // 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, $this->_release['id']));
        $this->_foundPAR2Info = true;
    }
Esempio n. 4
0
 public function processReleaseFiles($fetchedBinary, $relid)
 {
     $retval = array();
     $rar = new RarInfo();
     $rf = new ReleaseFiles();
     echo "Checking Release Contents (" . $relid . ")\n";
     if ($rar->setData($fetchedBinary)) {
         $files = $rar->getFileList();
         foreach ($files as $file) {
             $rf->add($relid, $file['name'], $file['size'], $file['date'], $file['pass']);
             echo "-Found {$file['name']}\n";
             $retval[] = $file['name'];
         }
     }
     unset($fetchedBinary);
     return $retval;
 }