Esempio n. 1
0
 public function getConsoleInfoByName($title, $platform)
 {
     //only used to get a count of words
     $searchwords = $searchsql = '';
     $ft = $this->pdo->queryDirect("SHOW INDEX FROM consoleinfo WHERE key_name = 'ix_consoleinfo_title_platform_ft'");
     if ($ft->rowCount() !== 2) {
         $searchsql .= sprintf(" title %s AND platform %s'", $this->pdo->likeString($title, true, true), $this->pdo->likeString($platform, true, true));
     } else {
         $title = preg_replace('/( - | -|\\(.+\\)|\\(|\\))/', ' ', $title);
         $title = preg_replace('/[^\\w ]+/', '', $title);
         $title = trim(preg_replace('/\\s\\s+/i', ' ', $title));
         $title = trim($title);
         $words = explode(' ', $title);
         foreach ($words as $word) {
             $word = trim(rtrim(trim($word), '-'));
             if ($word !== '' && $word !== '-') {
                 $word = '+' . $word;
                 $searchwords .= sprintf('%s ', $word);
             }
         }
         $searchwords = trim($searchwords);
         $searchsql .= sprintf(" MATCH(title, platform) AGAINST(%s IN BOOLEAN MODE) AND platform = %s", $this->pdo->escapeString($searchwords), $this->pdo->escapeString($platform));
     }
     return $this->pdo->queryOneRow(sprintf("SELECT * FROM consoleinfo WHERE %s", $searchsql));
 }
Esempio n. 2
0
    /**
     * Retrieve alternate release with same or similar searchname
     *
     * @param string $guid
     * @param string $searchname
     * @param string $userid
     * @return string
     */
    public function getAlternate($guid, $searchname, $userid)
    {
        $this->pdo->queryInsert(sprintf("INSERT IGNORE INTO dnzb_failures (userid, guid) VALUES (%d, %s)", $userid, $this->pdo->escapeString($guid)));
        $rel = $this->pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE guid = %s', $this->pdo->escapeString($guid)));
        $this->postComment($rel['id'], $userid);
        $alternate = $this->pdo->queryOneRow(sprintf('SELECT * FROM releases r
			WHERE r.searchname %s
			AND r.guid NOT IN (SELECT guid FROM dnzb_failures WHERE userid = %d)', $this->pdo->likeString($searchname), $userid));
        return $alternate;
    }
Esempio n. 3
0
    /**
     * Retrieve alternate release with same or similar searchname
     *
     * @param string $guid
     * @param string $userid
     * @return string
     */
    public function getAlternate($guid, $userid)
    {
        $rel = $this->pdo->queryOneRow(sprintf('
				SELECT id, searchname, categoryid
				FROM releases
				WHERE guid = %s', $this->pdo->escapeString($guid)));
        if ($rel === false) {
            return false;
        }
        $insert = $this->pdo->queryInsert(sprintf('
				INSERT IGNORE INTO dnzb_failures (release_id, userid, failed)
				VALUES (%d, %d, 1)', $rel['id'], $userid));
        // If we didn't actually insert the row, don't add a comment
        if (is_numeric($insert) && $insert > 0) {
            $this->postComment($rel['id'], $userid);
        }
        $alternate = $this->pdo->queryOneRow(sprintf('
				SELECT r.guid
				FROM releases r
				LEFT JOIN dnzb_failures df ON r.id = df.release_id
				WHERE r.searchname %s
				AND df.release_id IS NULL
				AND r.categoryid = %d
				AND r.id != %d
				ORDER BY r.postdate DESC', $this->pdo->likeString($rel['searchname'], true, true), $rel['categoryid'], $rel['id']));
        return $alternate;
    }
Esempio n. 4
0
    /**
     * Retrieve alternate release with same or similar searchname
     *
     * @param string $guid
     * @param string $searchname
     * @param string $userid
     * @return string
     */
    public function getAlternate($guid, $searchname, $userid)
    {
        $rel = $this->pdo->queryOneRow(sprintf('
				SELECT id, categoryid
				FROM releases
				WHERE guid = %s', $this->pdo->escapeString($guid)));
        // Specifying LAST_INSERT_ID on releaseid will return the releaseid
        // if the row was actually inserted and not updated
        $insert = $this->pdo->queryInsert(sprintf('
				INSERT INTO dnzb_failures (release_id, userid, failed)
				VALUES (LAST_INSERT_ID(%d), %d, 1)
				ON DUPLICATE KEY UPDATE failed = failed + 1', $rel['id'], $userid));
        // If we didn't actually insert the row, don't add a comment
        if ((int) $insert > 0) {
            $this->postComment($rel['id'], $userid);
        }
        $alternate = $this->pdo->queryOneRow(sprintf('
				SELECT r.*
				FROM releases r
				LEFT JOIN dnzb_failures df ON r.id = df.release_id
				WHERE r.searchname %s
				AND df.release_id IS NULL
				AND r.categoryid = %d', $this->pdo->likeString($searchname, true, true), $rel['categoryid'], $userid));
        return $alternate;
    }
Esempio n. 5
0
 /**
  * Remove releases that contain .wmv files and Codec\Setup.exe files, aka that spam poster.
  * Thanks to dizant from nZEDb forums for parts of the sql query
  *
  * @return string|boolean
  */
 protected function removeCodecPoster()
 {
     $this->method = 'Codec Poster';
     $regex = "rf.name REGEXP 'x264.*\\.(wmv|avi)\$'";
     $regex2 = "rf.name REGEXP '\\\\.*((DVDrip|BRRip)[. ].*[. ](R[56]|HQ)|720p[ .](DVDrip|HQ)|" . "Webrip.*[. ](R[56]|Xvid|AC3|US)|720p.*[. ]WEB-DL[. ]Xvid[. ]AC3[. ]US|" . "HDRip.*[. ]Xvid[. ]DD5).*[. ]avi\$'";
     $codec = '\\Codec%Setup.exe';
     $codec2 = '\\Codec%Installer.exe';
     $iferror = 'If_you_get_error.txt';
     $ifnotplaying = 'read me if the movie not playing.txt';
     $frenchv = 'Lisez moi si le film ne demarre pas.txt';
     $nl = 'lees me als de film niet spelen.txt';
     $german = 'Lesen Sie mir wenn der Film nicht abgespielt.txt';
     $german2 = 'Lesen Sie mir, wenn der Film nicht starten.txt';
     $categories = sprintf("r.categoryid IN (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", Category::CAT_MOVIE_3D, Category::CAT_MOVIE_BLURAY, Category::CAT_MOVIE_DVD, Category::CAT_MOVIE_FOREIGN, Category::CAT_MOVIE_HD, Category::CAT_MOVIE_OTHER, Category::CAT_MOVIE_SD, Category::CAT_XXX_WMV, Category::CAT_XXX_X264, Category::CAT_XXX_XVID, Category::CAT_XXX_OTHER);
     switch (nZEDb_RELEASE_SEARCH_TYPE) {
         case ReleaseSearch::SPHINX:
             $rs = new ReleaseSearch($this->pdo);
             $codecFT1 = str_replace('=10000;', '=1000000;', $rs->getSearchSQL(['filename' => 'x264|wmv|avi|DVDrip|BRRip|R5|R6|HQ|Webrip|Xvid|AC3|HDRip|DD5']));
             $codecFT2 = str_replace('=10000;', '=1000000;', $rs->getSearchSQL(['filename' => 'Codec|error|txt|installer|vlc']));
             $ftJoin = $rs->getFullTextJoinString();
             break;
         default:
             $codecFT1 = $codecFT2 = $ftJoin = '';
             break;
     }
     $codeclike = sprintf("\n\t\t\t\tSELECT r.guid, r.searchname, r.id FROM releases r %s\n\t\t\t\tSTRAIGHT_JOIN release_files rf ON r.id = rf.releaseid\n\t\t\t\tWHERE %s %s AND\n\t\t\t\t\t(rf.name %s OR rf.name %s OR\n\t\t\t\t\trf.name %s OR rf.name %s OR\n\t\t\t\t\trf.name %s OR rf.name %s OR\n\t\t\t\t\trf.name %s OR rf.name %s)\n\t\t\t\t%s", $ftJoin, $categories, $codecFT2, $this->pdo->likeString($codec, true, true), $this->pdo->likeString($codec2, true, true), $this->pdo->likeString($iferror, true, true), $this->pdo->likeString($ifnotplaying, true, true), $this->pdo->likeString($frenchv, true, true), $this->pdo->likeString($nl, true, true), $this->pdo->likeString($german, true, true), $this->pdo->likeString($german2, true, true), $this->crapTime);
     $this->query = sprintf("SELECT r.guid, r.searchname, r.id FROM releases r %s\n\t\t\tSTRAIGHT_JOIN release_files rf ON (r.id = rf.releaseid)\n\t\t\tWHERE %s %s\n\t\t\tAND (%s OR %s) %s\n\t\t\tUNION %s", $ftJoin, $categories, $codecFT1, $regex, $regex2, $this->crapTime, $codeclike);
     if ($this->checkSelectQuery() === false) {
         return $this->returnError();
     }
     return $this->deleteReleases();
 }
Esempio n. 6
0
 /**
  * @param int    $aniDbID
  * @param string $episodeNumber
  * @param int    $offset
  * @param int    $limit
  * @param string $name
  * @param array  $cat
  * @param int    $maxAge
  *
  * @return array
  */
 public function searchbyAnidbId($aniDbID, $episodeNumber = '', $offset = 0, $limit = 100, $name = '', $cat = [-1], $maxAge = -1)
 {
     $baseSql = sprintf("%s\n\t\t\tWHERE r.passwordstatus <= %d %s %s %s %s %s", $name !== '' ? $this->releaseSearch->getFullTextJoinString() : '', $this->showPasswords(), $aniDbID > -1 ? sprintf(' AND anidbid = %d ', $aniDbID) : '', is_numeric($episodeNumber) ? sprintf(" AND r.episode '%s' ", $this->pdo->likeString($episodeNumber)) : '', $name !== '' ? $this->releaseSearch->getSearchSQL(['searchname' => $name]) : '', $this->categorySQL($cat), $maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '');
     $sql = sprintf("SELECT SQL_CALC_FOUND_ROWS r.*,\n\t\t\t\tCONCAT(cp.title, ' > ', c.title) AS category_name,\n\t\t\t\tCONCAT(cp.id, ',', c.id) AS category_ids,\n\t\t\t\tgroups.name AS group_name,\n\t\t\t\trn.id AS nfoid\n\t\t\tFROM releases r\n\t\t\tINNER JOIN category c ON c.id = r.categoryid\n\t\t\tINNER JOIN groups ON groups.id = r.group_id\n\t\t\tLEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.nfo IS NOT NULL\n\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t%s\n\t\t\tORDER BY postdate DESC\n\t\t\tLIMIT %d OFFSET %d", $baseSql, $limit, $offset);
     $releases = $this->pdo->query($sql);
     $releases[0]['_totalrows'] = $this->pdo->get_Found_Rows();
     return $releases;
 }
Esempio n. 7
0
 /**
  * Supplementary function for getByTitle that queries for a like match
  *
  * @param        $title
  * @param        $type
  * @param int    $source
  *
  * @return array|false
  */
 public function getTitleLoose($title, $type, $source = 0)
 {
     $return = false;
     if (!empty($title)) {
         $return = $this->pdo->queryOneRow(sprintf("\n\t\t\t\t\tSELECT v.id\n\t\t\t\t\tFROM videos v\n\t\t\t\t\tLEFT JOIN videos_aliases va ON v.id = va.videos_id\n\t\t\t\t\tWHERE (v.title %1\$s\n\t\t\t\t\tOR va.title %1\$s)\n\t\t\t\t\tAND type = %2\$d %3\$s", $this->pdo->likeString(rtrim($title, '%'), false, false), $type, $source > 0 ? 'AND v.source = ' . $source : ''));
     }
     return $return;
 }
Esempio n. 8
0
 /**
  * Get all users / extra data from other tables.
  *
  * @param        $start
  * @param        $offset
  * @param        $orderBy
  * @param string $userName
  * @param string $email
  * @param string $host
  * @param string $role
  * @param bool   $apiRequests
  *
  * @return array
  */
 public function getRange($start, $offset, $orderBy, $userName = '', $email = '', $host = '', $role = '', $apiRequests = false)
 {
     if ($apiRequests) {
         $this->clearApiRequests(false);
         $query = "\n\t\t\t\tSELECT users.*, user_roles.name AS rolename, COUNT(user_requests.id) AS apirequests\n\t\t\t\tFROM users\n\t\t\t\tINNER JOIN user_roles ON user_roles.id = users.role\n\t\t\t\tLEFT JOIN user_requests ON user_requests.user_id = users.id\n\t\t\t\tWHERE users.id != 0 %s %s %s %s\n\t\t\t\tAND email != '*****@*****.**'\n\t\t\t\tGROUP BY users.id\n\t\t\t\tORDER BY %s %s %s";
     } else {
         $query = "\n\t\t\t\tSELECT users.*, user_roles.name AS rolename\n\t\t\t\tFROM users\n\t\t\t\tINNER JOIN user_roles ON user_roles.id = users.role\n\t\t\t\tWHERE 1=1 %s %s %s %s\n\t\t\t\tORDER BY %s %s %s";
     }
     $order = $this->getBrowseOrder($orderBy);
     return $this->pdo->query(sprintf($query, $userName != '' ? 'AND users.username ' . $this->pdo->likeString($userName) : '', $email != '' ? 'AND users.email ' . $this->pdo->likeString($email) : '', $host != '' ? 'AND users.host ' . $this->pdo->likeString($host) : '', $role != '' ? 'AND users.role = ' . $role : '', $order[0], $order[1], $start === false ? '' : 'LIMIT ' . $offset . ' OFFSET ' . $start));
 }
Esempio n. 9
0
    /**
     * Retrives the count of Anime titles for pager functions optionally filtered by title
     *
     * @param string $animetitle
     * @return int
     */
    public function getAnimeCount($animetitle = '')
    {
        $rsql = '';
        if ($animetitle != '') {
            $rsql .= sprintf('AND at.title %s', $this->pdo->likeString($animetitle, true, true));
        }
        $res = $this->pdo->queryOneRow(sprintf('SELECT COUNT(at.anidbid) AS num
				FROM anidb_titles AS at LEFT JOIN anidb_info AS ai USING (anidbid)
				WHERE 1=1 %s', $rsql));
        return $res['num'];
    }
Esempio n. 10
0
    /**
     * Retrieve alternate release with same or similar searchname
     *
     * @param string $guid
     * @param string $searchname
     * @param string $userid
     * @return string
     */
    public function getAlternate($guid, $searchname, $userid)
    {
        //status values
        // 0/false 	= successfully downloaded
        // 1/true 	= failed download
        $this->pdo->queryInsert(sprintf("INSERT IGNORE INTO dnzb_failures (userid, guid) VALUES (%d, %s)", $userid, $this->pdo->escapeString($guid)));
        $alternate = $this->pdo->queryOneRow(sprintf('SELECT * FROM releases r
			WHERE r.searchname %s
			AND r.guid NOT IN (SELECT guid FROM failed_downloads WHERE userid = %d)', $this->pdo->likeString($searchname), $userid));
        return $alternate;
    }
Esempio n. 11
0
 /**
  * @return string
  */
 public function getBrowseBy()
 {
     $browseby = ' ';
     $browsebyArr = $this->getBrowseByOptions();
     foreach ($browsebyArr as $bbk => $bbv) {
         if (isset($_REQUEST[$bbk]) && !empty($_REQUEST[$bbk])) {
             $bbs = stripslashes($_REQUEST[$bbk]);
             $browseby .= 'boo.' . $bbv . ' ' . $this->pdo->likeString($bbs, true, true) . ' AND ';
         }
     }
     return $browseby;
 }
Esempio n. 12
0
 /**
  * Try to fetch an IMDB id locally.
  *
  * @return int|bool   Int, the imdbid when true, Bool when false.
  */
 protected function localIMDBsearch()
 {
     $query = 'SELECT imdbid FROM movieinfo';
     $andYearIn = '';
     //If we found a year, try looking in a 4 year range.
     if ($this->currentYear !== false) {
         $start = (int) $this->currentYear - 2;
         $end = (int) $this->currentYear + 2;
         $andYearIn = 'AND year IN (';
         while ($start < $end) {
             $andYearIn .= $start . ',';
             $start++;
         }
         $andYearIn .= $end . ')';
     }
     $IMDBCheck = $this->pdo->queryOneRow(sprintf('%s WHERE title %s %s', $query, $this->pdo->likeString($this->currentTitle), $andYearIn));
     // Look by %word%word%word% etc..
     if ($IMDBCheck === false) {
         $pieces = explode(' ', $this->currentTitle);
         $tempTitle = '%';
         foreach ($pieces as $piece) {
             $tempTitle .= str_replace(["'", "!", '"'], '', $piece) . '%';
         }
         $IMDBCheck = $this->pdo->queryOneRow(sprintf("%s WHERE replace(replace(title, \"'\", ''), '!', '') %s %s", $query, $this->pdo->likeString($tempTitle), $andYearIn));
     }
     // Try replacing er with re ?
     if ($IMDBCheck === false) {
         $tempTitle = str_replace('er', 're', $this->currentTitle);
         if ($tempTitle !== $this->currentTitle) {
             $IMDBCheck = $this->pdo->queryOneRow(sprintf('%s WHERE title %s %s', $query, $this->pdo->likeString($tempTitle), $andYearIn));
             // Final check if everything else failed.
             if ($IMDBCheck === false) {
                 $pieces = explode(' ', $tempTitle);
                 $tempTitle = '%';
                 foreach ($pieces as $piece) {
                     $tempTitle .= str_replace(["'", "!", '"'], "", $piece) . '%';
                 }
                 $IMDBCheck = $this->pdo->queryOneRow(sprintf("%s WHERE replace(replace(replace(title, \"'\", ''), '!', ''), '\"', '') %s %s", $query, $this->pdo->likeString($tempTitle), $andYearIn));
             }
         }
     }
     return $IMDBCheck === false ? false : (is_numeric($IMDBCheck['imdbid']) ? (int) $IMDBCheck['imdbid'] : false);
 }
Esempio n. 13
0
    /**
     * Get all releases that need to be processed.
     *
     * @param int|string $groupID
     * @param string     $guidChar
     *
     * @void
     */
    protected function _fetchReleases($groupID, &$guidChar)
    {
        $this->_releases = $this->pdo->query(sprintf('SELECT r.id, r.guid, r.name, c.disablepreview, r.size, r.group_id, r.nfostatus, r.completion, r.categoryid, r.searchname, r.preid
				FROM releases r
				LEFT JOIN category c ON c.id = r.categoryid
				WHERE r.nzbstatus = 1
				%s %s %s %s
				AND r.passwordstatus BETWEEN -6 AND -1
				AND r.haspreview = -1
				AND c.disablepreview = 0
				ORDER BY r.passwordstatus ASC, r.postdate DESC
				LIMIT %d', $this->_maxSize, $this->_minSize, $groupID === '' ? '' : 'AND r.group_id = ' . $groupID, $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true), $this->_queryLimit));
        if (is_array($this->_releases)) {
            $this->_totalReleases = count($this->_releases);
        } else {
            $this->_releases = [];
            $this->_totalReleases = 0;
        }
    }
Esempio n. 14
0
 /**
  * Remove releases with more than 1 part, less than 40MB, sample in name. TV/Movie sections.
  *
  * @return boolean|string
  */
 protected function removeSample()
 {
     $this->method = 'Sample';
     switch (nZEDb_RELEASE_SEARCH_TYPE) {
         case ReleaseSearch::SPHINX:
             $rs = new ReleaseSearch($this->pdo);
             $sampleFT = str_replace('=10000;', '=10000000;', $rs->getSearchSQL(['name' => 'sample']));
             $ftJoin = $rs->getFullTextJoinString();
             break;
         default:
             $sampleFT = $ftJoin = '';
             break;
     }
     $this->query = sprintf("SELECT r.guid, r.searchname, r.id\n\t\t\tFROM releases r %s\n\t\t\tWHERE r.totalpart > 1\n\t\t\tAND r.size < 40000000\n\t\t\tAND r.name %s\n\t\t\tAND r.categoryid IN (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d) %s %s", $ftJoin, $this->pdo->likeString('sample', true, true), Category::CAT_TV_ANIME, Category::CAT_TV_DOCUMENTARY, Category::CAT_TV_FOREIGN, Category::CAT_TV_HD, Category::CAT_TV_OTHER, Category::CAT_TV_SD, Category::CAT_TV_SPORT, Category::CAT_TV_WEBDL, Category::CAT_MOVIE_3D, Category::CAT_MOVIE_BLURAY, Category::CAT_MOVIE_DVD, Category::CAT_MOVIE_FOREIGN, Category::CAT_MOVIE_HD, Category::CAT_MOVIE_OTHER, Category::CAT_MOVIE_SD, $sampleFT, $this->crapTime);
     if ($this->checkSelectQuery() === false) {
         return $this->returnError();
     }
     return $this->deleteReleases();
 }
Esempio n. 15
0
File: XXX.php Progetto: Jay204/nZEDb
 /**
  * @return string
  */
 protected function getBrowseBy()
 {
     $browseBy = ' ';
     $browseByArr = array('title', 'director', 'actors', 'genre', 'id');
     foreach ($browseByArr as $bb) {
         if (isset($_REQUEST[$bb]) && !empty($_REQUEST[$bb])) {
             $bbv = stripslashes($_REQUEST[$bb]);
             if ($bb == "genre") {
                 $bbv = $this->getgenreid($bbv);
             }
             if ($bb == 'id') {
                 $browseBy .= 'xxx.' . $bb . '=' . $bbv . ' AND ';
             } else {
                 $browseBy .= 'xxx.' . $bb . ' ' . $this->pdo->likeString($bbv, true, true) . ' AND ';
             }
         }
     }
     return $browseBy;
 }
Esempio n. 16
0
 public function matchPredbFT($pre, $echo, $namestatus, $echooutput, $show)
 {
     $matching = $total = 0;
     $join = $this->_preFTsearchQuery($pre['title']);
     //Find release matches with fulltext and then identify exact matches with cleaned LIKE string
     $res = $this->pdo->queryDirect(sprintf("\n\t\t\t\t\t\t\tSELECT r.id AS releaseid, r.name, r.searchname,\n\t\t\t\t\t\t\t\tr.group_id, r.categoryid\n\t\t\t\t\t\t\tFROM releases r\n\t\t\t\t\t\t\t%1\$s\n\t\t\t\t\t\t\tAND (r.name %2\$s OR r.searchname %2\$s)\n\t\t\t\t\t\t\tAND r.preid = 0\n\t\t\t\t\t\t\tLIMIT 21", $join, $this->pdo->likeString($pre['title'], true, true)));
     if ($res !== false) {
         $total = $res->rowCount();
     }
     // Run if row count is positive, but do not run if row count exceeds 10 (as this is likely a failed title match)
     if ($total > 0 && $total <= 15 && $res instanceof \Traversable) {
         foreach ($res as $row) {
             if ($pre['title'] !== $row['searchname']) {
                 $this->updateRelease($row, $pre['title'], $method = "Title Match source: " . $pre['source'], $echo, "PreDB FT Exact, ", $namestatus, $show, $pre['preid']);
                 $matching++;
             } else {
                 $this->_updateSingleColumn('preid', $pre['preid'], $row['releaseid']);
             }
         }
     } elseif ($total >= 16) {
         $matching = -1;
     }
     return $matching;
 }
Esempio n. 17
0
        $maxperrun = $pieces[2];
        $thread = $pieces[3];
        switch (true) {
            case $pieces[0] === 'nfo' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
                $releases = $pdo->queryDirect(sprintf('
								SELECT r.id AS releaseid, r.guid, r.group_id, r.categoryid, r.name, r.searchname,
									uncompress(nfo) AS textstring
								FROM releases r
								INNER JOIN release_nfos rn ON r.id = rn.releaseid
								WHERE r.guid %s
								AND r.nzbstatus = 1
								AND r.proc_nfo = 0
								AND r.nfostatus = 1
								AND r.preid = 0
								ORDER BY r.postdate DESC
								LIMIT %s', $pdo->likeString($guidChar, false, true), $maxperrun));
                if ($releases instanceof \Traversable) {
                    foreach ($releases as $release) {
                        if (preg_match('/^=newz\\[NZB\\]=\\w+/', $release['textstring'])) {
                            $namefixer->done = $namefixer->matched = false;
                            $pdo->queryDirect(sprintf('UPDATE releases SET proc_nfo = 1 WHERE id = %d', $release['releaseid']));
                            $namefixer->checked++;
                            echo '.';
                        } else {
                            $namefixer->done = $namefixer->matched = false;
                            if ($namefixer->checkName($release, true, 'NFO, ', 1, 1) !== true) {
                                echo '.';
                            }
                            $namefixer->checked++;
                        }
                    }
Esempio n. 18
0
File: Nfo.php Progetto: egandt/nZEDb
    /**
     * Attempt to find NFO files inside the NZB's of releases.
     *
     * @param object $nntp           Instance of class NNTP.
     * @param string $groupID        (optional) Group ID.
     * @param string $guidChar       (optional) First character of the release GUID (used for multi-processing).
     * @param int    $processImdb    (optional) Attempt to find IMDB id's in the NZB?
     * @param int    $processTvrage  (optional) Attempt to find TvRage id's in the NZB?
     *
     * @return int                   How many NFO's were processed?
     *
     * @access public
     */
    public function processNfoFiles($nntp, $groupID = '', $guidChar = '', $processImdb = 1, $processTvrage = 1)
    {
        $ret = 0;
        $guidCharQuery = $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true);
        $groupIDQuery = $groupID === '' ? '' : 'AND r.group_id = ' . $groupID;
        $optionsQuery = self::NfoQueryString($this->pdo);
        $res = $this->pdo->query(sprintf('
				SELECT r.id, r.guid, r.group_id, r.name
				FROM releases r
				WHERE 1=1 %s %s %s
				ORDER BY r.nfostatus ASC, r.postdate DESC
				LIMIT %d', $optionsQuery, $guidCharQuery, $groupIDQuery, $this->nzbs));
        $nfoCount = count($res);
        if ($nfoCount > 0) {
            $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . ($guidChar === '' ? '' : '[' . $guidChar . '] ') . ($groupID === '' ? '' : '[' . $groupID . '] ') . 'Processing ' . $nfoCount . ' NFO(s), starting at ' . $this->nzbs . ' * = hidden NFO, + = NFO, - = no NFO, f = download failed.'));
            if ($this->echo) {
                // Get count of releases per nfo status
                $nfoStats = $this->pdo->queryDirect(sprintf('
						SELECT r.nfostatus AS status, COUNT(*) AS count
						FROM releases r
						WHERE 1=1 %s %s %s
						GROUP BY r.nfostatus
						ORDER BY r.nfostatus ASC', $optionsQuery, $guidCharQuery, $groupIDQuery));
                if ($nfoStats instanceof \Traversable) {
                    $outString = PHP_EOL . 'Available to process';
                    foreach ($nfoStats as $row) {
                        $outString .= ', ' . $row['status'] . ' = ' . number_format($row['count']);
                    }
                    $this->pdo->log->doEcho($this->pdo->log->header($outString . '.'));
                }
            }
            $groups = new Groups(['Settings' => $this->pdo]);
            $nzbContents = new NZBContents(['Echo' => $this->echo, 'NNTP' => $nntp, 'Nfo' => $this, 'Settings' => $this->pdo, 'PostProcess' => new PostProcess(['Echo' => $this->echo, 'Nfo' => $this, 'Settings' => $this->pdo])]);
            $movie = new Movie(['Echo' => $this->echo, 'Settings' => $this->pdo]);
            foreach ($res as $arr) {
                $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['group_id'], $groups->getByNameByID($arr['group_id']));
                if ($fetchedBinary !== false) {
                    // Insert nfo into database.
                    $cp = 'COMPRESS(%s)';
                    $nc = $this->pdo->escapeString($fetchedBinary);
                    $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT releaseid FROM release_nfos WHERE releaseid = %d', $arr['id']));
                    if (!isset($ckreleaseid['releaseid'])) {
                        $this->pdo->queryInsert(sprintf('INSERT INTO release_nfos (nfo, releaseid) VALUES (' . $cp . ', %d)', $nc, $arr['id']));
                    }
                    $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $arr['id']));
                    $ret++;
                    $movie->doMovieUpdate($fetchedBinary, 'nfo', $arr['id'], $processImdb);
                    // If set scan for tvrage info. Disabled for now while TvRage is down. TODO: Add Other Scraper Checks
                    if ($processTvrage == 1) {
                        /*$tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]);
                        		$showId = $this->parseShowId($fetchedBinary);
                        		if ($showId !== false) {
                        			$show = $tvRage->parseNameEpSeason($arr['name']);
                        			if (is_array($show) && $show['name'] != '') {
                        				// Update release with season, ep, and air date info (if available) from release title.
                        				$tvRage->updateEpInfo($show, $arr['id']);
                        				$rid = $tvRage->getByRageID($rageId);
                        				if (!$rid) {
                        					$tvrShow = $tvRage->getRageInfoFromService($rageId);
                        					$tvRage->updateRageInfo($rageId, $show, $tvrShow, $arr['id']);
                        				}
                        			}
                        		}*/
                    }
                }
            }
        }
        // Remove nfo that we cant fetch after 5 attempts.
        $releases = $this->pdo->queryDirect(sprintf('SELECT r.id
				FROM releases r
				WHERE r.nzbstatus = %d
				AND r.nfostatus < %d AND r.nfostatus > %d %s %s', NZB::NZB_ADDED, $this->maxRetries, self::NFO_FAILED, $groupIDQuery, $guidCharQuery));
        if ($releases instanceof \Traversable) {
            foreach ($releases as $release) {
                // remove any release_nfos for failed
                $this->pdo->queryExec(sprintf('
					DELETE FROM release_nfos WHERE nfo IS NULL AND releaseid = %d', $release['id']));
                // set release.nfostatus to failed
                $this->pdo->queryExec(sprintf('
					UPDATE releases r SET r.nfostatus = %d WHERE r.id = %d', self::NFO_FAILED, $release['id']));
            }
        }
        if ($this->echo) {
            if ($nfoCount > 0) {
                echo PHP_EOL;
            }
            if ($ret > 0) {
                $this->pdo->log->doEcho($ret . ' NFO file(s) found/processed.', true);
            }
        }
        return $ret;
    }
Esempio n. 19
0
 /**
  * Format part of a query.
  *
  * @param string $group_regex
  *
  * @return string
  */
 protected function _groupQueryString($group_regex)
 {
     return $group_regex ? 'WHERE group_regex ' . $this->pdo->likeString($group_regex) : '';
 }
Esempio n. 20
0
 public function processTvReleases($groupID = '', $guidChar = '', $lookupTvRage = 1, $local = false)
 {
     $ret = 0;
     if ($lookupTvRage == 0) {
         return $ret;
     }
     $trakt = new TraktTv(['Settings' => $this->pdo]);
     // Get all releases without a rageid which are in a tv category.
     $res = $this->pdo->query(sprintf("\n\t\t\t\tSELECT r.searchname, r.id\n\t\t\t\tFROM releases r\n\t\t\t\tWHERE r.nzbstatus = 1\n\t\t\t\tAND r.rageid = -1\n\t\t\t\tAND r.size > 1048576\n\t\t\t\tAND r.categoryid BETWEEN 5000 AND 5999\n\t\t\t\t%s %s %s\n\t\t\t\tORDER BY r.postdate DESC\n\t\t\t\tLIMIT %d", $groupID === '' ? '' : 'AND r.group_id = ' . $groupID, $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true), $lookupTvRage == 2 ? 'AND r.isrenamed = 1' : '', $this->rageqty));
     $tvcount = count($res);
     if ($this->echooutput && $tvcount > 1) {
         echo $this->pdo->log->header("Processing TV for " . $tvcount . " release(s).");
     }
     foreach ($res as $arr) {
         $show = $this->parseNameEpSeason($arr['searchname']);
         if (is_array($show) && $show['name'] != '') {
             // Update release with season, ep, and airdate info (if available) from releasetitle.
             $this->updateEpInfo($show, $arr['id']);
             // Find the rageID.
             $id = $this->getByTitle($show['cleanname']);
             // Force local lookup only
             if ($local == true) {
                 $lookupTvRage = false;
             }
             if ($id === false && $lookupTvRage) {
                 // If it doesnt exist locally and lookups are allowed lets try to get it.
                 if ($this->echooutput) {
                     echo $this->pdo->log->primaryOver("TVRage ID for ") . $this->pdo->log->headerOver($show['cleanname']) . $this->pdo->log->primary(" not found in local db, checking web.");
                 }
                 $tvrShow = $this->getRageMatch($show);
                 if ($tvrShow !== false && is_array($tvrShow)) {
                     // Get all tv info and add show.
                     $this->updateRageInfo($tvrShow['showid'], $show, $tvrShow, $arr['id']);
                 } else {
                     if ($tvrShow === false) {
                         // If tvrage fails, try trakt.
                         $traktArray = $trakt->traktTVSEsummary($show['name'], $show['season'], $show['episode']);
                         if ($traktArray !== false) {
                             if (isset($traktArray['show']['tvrage_id']) && $traktArray['show']['tvrage_id'] !== 0) {
                                 if ($this->echooutput) {
                                     echo $this->pdo->log->primary('Found TVRage ID on trakt:' . $traktArray['show']['tvrage_id']);
                                 }
                                 $this->updateRageInfoTrakt($traktArray['show']['tvrage_id'], $show, $traktArray, $arr['id']);
                             } else {
                                 $this->add(-2, $show['cleanname'], '', '', '', '');
                             }
                         } else {
                             $this->add(-2, $show['cleanname'], '', '', '', '');
                         }
                     } else {
                         // $tvrShow probably equals -1 but we'll do this as a catchall instead of a specific else if.
                         // Skip because we couldnt connect to tvrage.com.
                     }
                 }
             } else {
                 if ($id > 0) {
                     //if ($this->echooutput) {
                     //    echo $this->pdo->log->AlternateOver("TV series: ") . $this->pdo->log->header($show['cleanname'] . " " . $show['seriesfull'] . (($show['year'] != '') ? ' ' . $show['year'] : '') . (($show['country'] != '') ? ' [' . $show['country'] . ']' : ''));
                     // }
                     $tvairdate = isset($show['airdate']) && !empty($show['airdate']) ? $this->pdo->escapeString($this->checkDate($show['airdate'])) : "NULL";
                     $tvtitle = "NULL";
                     if ($lookupTvRage) {
                         $epinfo = $this->getEpisodeInfo($id, $show['season'], $show['episode']);
                         if ($epinfo !== false) {
                             if (isset($epinfo['airdate'])) {
                                 $tvairdate = $this->pdo->escapeString($this->checkDate($epinfo['airdate']));
                             }
                             if (!empty($epinfo['title'])) {
                                 $tvtitle = $this->pdo->escapeString(trim($epinfo['title']));
                             }
                         }
                     }
                     if ($tvairdate == "NULL") {
                         $this->pdo->queryExec(sprintf('UPDATE releases SET tvtitle = %s, rageid = %d WHERE id = %d', $tvtitle, $id, $arr['id']));
                     } else {
                         $this->pdo->queryExec(sprintf('UPDATE releases SET tvtitle = %s, tvairdate = %s, rageid = %d WHERE id = %d', $tvtitle, $tvairdate, $id, $arr['id']));
                     }
                     // Cant find rageid, so set rageid to n/a.
                 } else {
                     $this->pdo->queryExec(sprintf('UPDATE releases SET rageid = -2 WHERE id = %d', $arr['id']));
                 }
             }
             // Not a tv episode, so set rageid to n/a.
         } else {
             $this->pdo->queryExec(sprintf('UPDATE releases SET rageid = -2 WHERE id = %d', $arr['id']));
         }
         $ret++;
     }
     return $ret;
 }
Esempio n. 21
0
 public function getConsoleInfoByName($title, $platform)
 {
     return $this->pdo->queryOneRow(sprintf("SELECT * FROM consoleinfo WHERE title %s AND platform %s", $this->pdo->likeString($title, true, true), $this->pdo->likeString($platform, true, true)));
 }
Esempio n. 22
0
 /**
  * Retrieves AniDB Info using a cleaned name
  *
  * @param string $searchName
  *
  * @return array|bool
  */
 private function getAnidbByName($searchName = '')
 {
     return $this->pdo->queryOneRow(sprintf("\n\t\t\t\t\t\t\tSELECT at.anidbid, at.title\n\t\t\t\t\t\t\tFROM anidb_titles AS at\n\t\t\t\t\t\t\tWHERE at.title %s", $this->pdo->likeString($searchName, true, true)));
 }