Ejemplo n.º 1
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 (nZEDb_RENAME_PAR2 && $releaseInfo['proc_pp'] == 0 && in_array((int) $this->_release['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;
        }
        $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 release_files 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 ? true : false, '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;
    }
Ejemplo n.º 2
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 \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;
    }
Ejemplo n.º 3
0
     $music = new Music(['Settings' => $page->settings]);
     $mus = $music->getMusicInfo($data['musicinfoid']);
 }
 if ($data['consoleinfoid'] != '') {
     $c = new Console(['Settings' => $page->settings]);
     $con = $c->getConsoleInfo($data['consoleinfoid']);
 }
 if ($data['gamesinfo_id'] != '') {
     $g = new Games(['Settings' => $page->settings]);
     $game = $g->getgamesInfo($data['gamesinfo_id']);
 }
 if ($data['bookinfoid'] != '') {
     $b = new Books(['Settings' => $page->settings]);
     $boo = $b->getBookInfo($data['bookinfoid']);
 }
 $rf = new ReleaseFiles($page->settings);
 $releasefiles = $rf->get($data['id']);
 $predb = new PreDb(['Settings' => $page->settings]);
 $pre = $predb->getForRelease($data['preid']);
 $user = $page->users->getById($page->users->currentUserId());
 $page->smarty->assign('cpapi', $user['cp_api']);
 $page->smarty->assign('cpurl', $user['cp_url']);
 $page->smarty->assign('releasefiles', $releasefiles);
 $page->smarty->assign('release', $data);
 $page->smarty->assign('reVideo', $reVideo);
 $page->smarty->assign('reAudio', $reAudio);
 $page->smarty->assign('reSubs', $reSubs);
 $page->smarty->assign('nfo', $nfo);
 $page->smarty->assign('rage', $rage);
 $page->smarty->assign('movie', $mov);
 $page->smarty->assign('xxx', $xxx);
Ejemplo n.º 4
0
function preName($argv, $argc)
{
    global $pdo;
    $groups = new Groups(['Settings' => $pdo]);
    $category = new Categorize(['Settings' => $pdo]);
    $internal = $external = $pre = 0;
    $show = 2;
    if ($argv[$argc - 1] === 'show') {
        $show = 1;
    } else {
        if ($argv[$argc - 1] === 'bad') {
            $show = 3;
        }
    }
    $counter = 0;
    $pdo->log = new ColorCLI();
    $full = $all = $usepre = false;
    $what = $where = '';
    if ($argv[1] === 'full') {
        $full = true;
    } else {
        if ($argv[1] === 'all') {
            $all = true;
        } else {
            if ($argv[1] === 'preid') {
                $usepre = true;
            } else {
                if (is_numeric($argv[1])) {
                    $what = ' AND adddate > NOW() - INTERVAL ' . $argv[1] . ' HOUR';
                }
            }
        }
    }
    if ($usepre === true) {
        $where = '';
        $why = ' WHERE preid = 0 AND nzbstatus = 1';
    } else {
        if (isset($argv[1]) && is_numeric($argv[1])) {
            $where = '';
            $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
        } else {
            if (isset($argv[2]) && is_numeric($argv[2]) && $full === true) {
                $where = ' AND group_id = ' . $argv[2];
                $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
            } else {
                if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) {
                    $where = ' AND group_id IN ' . $argv[2];
                    $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
                } else {
                    if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) {
                        $where = ' AND group_id IN ' . $argv[2];
                        $why = ' WHERE nzbstatus = 1';
                    } else {
                        if (isset($argv[2]) && is_numeric($argv[2]) && $all === true) {
                            $where = ' AND group_id = ' . $argv[2];
                            $why = ' WHERE nzbstatus = 1 and preid = 0';
                        } else {
                            if (isset($argv[2]) && is_numeric($argv[2])) {
                                $where = ' AND group_id = ' . $argv[2];
                                $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
                            } else {
                                if ($full === true) {
                                    $why = ' WHERE nzbstatus = 1 AND (isrenamed = 0 OR categoryid between 7000 AND 7999)';
                                } else {
                                    if ($all === true) {
                                        $why = ' WHERE nzbstatus = 1';
                                    } else {
                                        $why = ' WHERE 1=1';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    resetSearchnames();
    echo $pdo->log->header("SELECT id, name, searchname, fromname, size, group_id, categoryid FROM releases" . $why . $what . $where . ";\n");
    $res = $pdo->queryDirect("SELECT id, name, searchname, fromname, size, group_id, categoryid FROM releases" . $why . $what . $where);
    $total = $res->rowCount();
    if ($total > 0) {
        $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
        foreach ($res as $row) {
            $groupname = $groups->getByNameByID($row['group_id']);
            $cleanerName = releaseCleaner($row['name'], $row['fromname'], $row['size'], $groupname, $usepre);
            $preid = 0;
            $predb = $predbfile = $increment = false;
            if (!is_array($cleanerName)) {
                $cleanName = trim((string) $cleanerName);
                $propername = $increment = true;
                if ($cleanName != '' && $cleanerName != false) {
                    $run = $pdo->queryOneRow("SELECT id FROM predb WHERE title = " . $pdo->escapeString($cleanName));
                    if (isset($run['id'])) {
                        $preid = $run['id'];
                        $predb = true;
                    }
                }
            } else {
                $cleanName = trim($cleanerName["cleansubject"]);
                $propername = $cleanerName["properlynamed"];
                if (isset($cleanerName["increment"])) {
                    $increment = $cleanerName["increment"];
                }
                if (isset($cleanerName["predb"])) {
                    $preid = $cleanerName["predb"];
                    $predb = true;
                }
            }
            if ($cleanName != '') {
                if (preg_match('/alt\\.binaries\\.e\\-?book(\\.[a-z]+)?/', $groupname)) {
                    if (preg_match('/^[0-9]{1,6}-[0-9]{1,6}-[0-9]{1,6}$/', $cleanName, $match)) {
                        $rf = new ReleaseFiles($pdo);
                        $files = $rf->get($row['id']);
                        foreach ($files as $f) {
                            if (preg_match('/^(?P<title>.+?)(\\[\\w\\[\\]\\(\\). -]+)?\\.(pdf|htm(l)?|epub|mobi|azw|tif|doc(x)?|lit|txt|rtf|opf|fb2|prc|djvu|cb[rz])/', $f["name"], $match)) {
                                $cleanName = $match['title'];
                                break;
                            }
                        }
                    }
                }
                //try to match clean name against predb filename
                $prefile = $pdo->queryOneRow("SELECT id, title FROM predb WHERE filename = " . $pdo->escapeString($cleanName));
                if (isset($prefile['id'])) {
                    $preid = $prefile['id'];
                    $cleanName = $prefile['title'];
                    $predbfile = true;
                    $propername = true;
                }
                if ($cleanName != $row['name'] && $cleanName != $row['searchname']) {
                    if (strlen(utf8_decode($cleanName)) <= 3) {
                    } else {
                        $determinedcat = $category->determineCategory($row["group_id"], $cleanName);
                        if ($propername == true) {
                            $pdo->queryExec(sprintf("UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, " . "iscategorized = 1, isrenamed = 1, searchname = %s, categoryid = %d, preid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id']));
                        } else {
                            $pdo->queryExec(sprintf("UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL,  " . "iscategorized = 1, searchname = %s, categoryid = %d, preid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id']));
                        }
                        if ($increment === true) {
                            $internal++;
                        } else {
                            if ($predb === true) {
                                $pre++;
                            } else {
                                if ($predbfile === true) {
                                    $pre++;
                                } else {
                                    if ($propername === true) {
                                        $external++;
                                    }
                                }
                            }
                        }
                        if ($show === 1) {
                            $oldcatname = $category->getNameByID($row["categoryid"]);
                            $newcatname = $category->getNameByID($determinedcat);
                            NameFixer::echoChangedReleaseName(['new_name' => $cleanName, 'old_name' => $row["searchname"], 'new_category' => $newcatname, 'old_category' => $oldcatname, 'group' => $groupname, 'release_id' => $row["id"], 'method' => 'misc/testing/Various/renametopre.php']);
                        }
                    }
                } else {
                    if ($show === 3 && preg_match('/^\\[?\\d*\\].+?yEnc/i', $row['name'])) {
                        echo $pdo->log->primary($row['name']);
                    }
                }
            }
            if ($cleanName == $row['name']) {
                $pdo->queryExec(sprintf("UPDATE releases SET isrenamed = 1, iscategorized = 1 WHERE id = %d", $row['id']));
            }
            if ($show === 2 && $usepre === false) {
                $consoletools->overWritePrimary("Renamed Releases:  [Internal=" . number_format($internal) . "][External=" . number_format($external) . "][Predb=" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total));
            } else {
                if ($show === 2 && $usepre === true) {
                    $consoletools->overWritePrimary("Renamed Releases:  [" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total));
                }
            }
        }
    }
    echo $pdo->log->header("\n" . number_format($pre) . " renamed using preDB Match\n" . number_format($external) . " renamed using ReleaseCleaning.php\n" . number_format($internal) . " using renametopre.php\nout of " . number_format($total) . " releases.\n");
    if (isset($argv[1]) && is_numeric($argv[1]) && !isset($argv[2])) {
        echo $pdo->log->header("Categorizing all releases using searchname from the last {$argv[1]} hours. This can take a while, be patient.");
    } else {
        if (isset($argv[1]) && $argv[1] !== "all" && isset($argv[2]) && !is_numeric($argv[2]) && !preg_match('/\\([\\d, ]+\\)/', $argv[2])) {
            echo $pdo->log->header("Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient.");
        } else {
            if (isset($argv[1]) && isset($argv[2]) && (is_numeric($argv[2]) || preg_match('/\\([\\d, ]+\\)/', $argv[2]))) {
                echo $pdo->log->header("Categorizing all non-categorized releases in {$argv[2]} using searchname. This can take a while, be patient.");
            } else {
                echo $pdo->log->header("Categorizing all releases using searchname. This can take a while, be patient.");
            }
        }
    }
    $timestart = TIME();
    if (isset($argv[1]) && is_numeric($argv[1])) {
        $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryID = 0010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true);
    } else {
        if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) {
            $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true);
        } else {
            if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) {
                $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true);
            } else {
                if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "full") {
                    $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true);
                } else {
                    if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "all") {
                        $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true);
                    } else {
                        if (isset($argv[1]) && $argv[1] == "full") {
                            $relcount = catRelease("searchname", "WHERE categoryID = 0010 OR iscategorized = 0", true);
                        } else {
                            if (isset($argv[1]) && $argv[1] == "all") {
                                $relcount = catRelease("searchname", "", true);
                            } else {
                                if (isset($argv[1]) && $argv[1] == "preid") {
                                    $relcount = catRelease("searchname", "WHERE preid = 0 AND nzbstatus = 1", true);
                                } else {
                                    $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryID = 0010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $time = $consoletools->convertTime(TIME() - $timestart);
    echo $pdo->log->header("Finished categorizing " . number_format($relcount) . " releases in " . $time . " seconds, using the usenet subject.\n");
    resetSearchnames();
}
Ejemplo n.º 5
0
<?php

use nzedb\ReleaseFiles;
if (!$page->users->isLoggedIn()) {
    $page->show403();
}
if (!isset($_REQUEST["id"])) {
    $page->show404();
}
$rf = new ReleaseFiles($page->settings);
$files = $rf->getByGuid($_REQUEST["id"]);
if (count($files) == 0) {
    print "No files";
} else {
    //print "<h3 class=\"tooltiphead\">rar archive contains...</h3>\n";
    print "<ul>\n";
    foreach ($files as $f) {
        print "<li>" . htmlentities($f["name"], ENT_QUOTES) . "&nbsp;" . ($f["passworded"] == 1 ? "<img width=\"12\" src=\"" . nZEDb_THEMES_SHARED . "images/icons/lock.gif\" />" : "") . "</li>\n";
    }
    print "</ul>";
}