Esempio n. 1
0
    /**
     * Deletes stored AniDB entries in the database
     *
     * @param int $anidbID
     */
    public function deleteTitle($anidbID)
    {
        $this->pdo->queryExec(sprintf('
						DELETE at, ai, ae
						FROM anidb_titles AS at
						LEFT OUTER JOIN anidb_info ai USING (anidbid)
						LEFT OUTER JOIN anidb_episodes ae USING (anidbid)
						WHERE anidbid = %d', $anidbID));
    }
Esempio n. 2
0
 /**
  * Get the count of how many NZB's the user has downloaded in the past day.
  *
  * @param int $userID
  *
  * @return int
  */
 public function getDownloadRequests($userID)
 {
     // Clear old requests.
     $this->pdo->queryExec(sprintf('DELETE FROM user_downloads WHERE user_id = %d AND timestamp < DATE_SUB(NOW(), INTERVAL 1 DAY)', $userID));
     $value = $this->pdo->queryOneRow(sprintf('SELECT COUNT(id) AS num FROM user_downloads WHERE user_id = %d AND timestamp > DATE_SUB(NOW(), INTERVAL 1 DAY)', $userID));
     return $value === false ? 0 : (int) $value['num'];
 }
Esempio n. 3
0
 /**
  * If a collection has been stuck for $this->collectionTimeout hours, delete it, it's bad.
  *
  * @param array $group
  * @param string $where
  *
  * @void
  * @access private
  */
 private function processStuckCollections(array $group, $where)
 {
     $obj = $this->pdo->queryExec(sprintf("\n\t\t\t\tDELETE c, b, p FROM %s c\n\t\t\t\tLEFT JOIN %s b ON (c.id=b.collection_id)\n\t\t\t\tLEFT JOIN %s p ON (b.id=p.binaryid)\n\t\t\t\tWHERE\n\t\t\t\t\tc.added <\n\t\t\t\t\tDATE_SUB((SELECT value FROM settings WHERE setting = 'last_run_time'), INTERVAL %d HOUR)\n\t\t\t\t%s", $group['cname'], $group['bname'], $group['pname'], $this->collectionTimeout, $where));
     if ($this->echoCLI && is_object($obj) && $obj->rowCount()) {
         $this->pdo->log->doEcho($this->pdo->log->primary('Deleted ' . $obj->rowCount() . ' broken/stuck collections.'));
     }
 }
Esempio n. 4
0
File: XXX.php Progetto: Jay204/nZEDb
 /**
  * Process releases with no xxxinfo ID's.
  *
  */
 public function processXXXReleases()
 {
     // Get all releases without an IMpdo id.
     $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.xxxinfo_id = 0\n\t\t\t\tAND r.categoryid BETWEEN 6000 AND 6040\n\t\t\t\tLIMIT %d", $this->movieqty));
     $movieCount = count($res);
     if ($movieCount > 0) {
         if ($this->echooutput) {
             $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $movieCount . " XXX releases."));
         }
         // Loop over releases.
         foreach ($res as $arr) {
             $idcheck = -2;
             // Try to get a name.
             if ($this->debug && $this->echooutput) {
                 $this->pdo->log->doEcho("DB name: " . $arr['searchname'], true);
             }
             if ($this->parseXXXSearchName($arr['searchname']) !== false) {
                 $this->currentRelID = $arr['id'];
                 $movieName = $this->currentTitle;
                 if ($this->echooutput) {
                     $this->pdo->log->doEcho($this->pdo->log->primaryOver("Looking up: ") . $this->pdo->log->headerOver($movieName), true);
                 }
                 $idcheck = $this->updateXXXInfo($movieName);
             } else {
                 $this->pdo->log->doEcho(".", true);
             }
             $this->pdo->queryExec(sprintf('UPDATE releases SET xxxinfo_id = %d WHERE id = %d', $idcheck, $arr['id']));
         }
     } elseif ($this->echooutput) {
         $this->pdo->log->doEcho($this->pdo->log->header('No xxx releases to process.'));
     }
 }
Esempio n. 5
0
 public function addFull($id, $xml)
 {
     $ckid = $this->pdo->queryOneRow(sprintf('SELECT releaseid FROM releaseextrafull WHERE releaseid = %s', $id));
     if (!isset($ckid['releaseid'])) {
         return $this->pdo->queryExec(sprintf('INSERT INTO releaseextrafull (releaseid, mediainfo) VALUES (%d, %s)', $id, $this->pdo->escapeString($xml)));
     }
 }
Esempio n. 6
0
    /**
     * Fetch a comment and insert it.
     *
     * @param string $messageID Message-ID for the article.
     * @param string $siteID    ID of the site.
     *
     * @return bool
     *
     * @access protected
     */
    protected function insertNewComment(&$messageID, &$siteID)
    {
        // Get the article body.
        $body = $this->nntp->getMessages(self::group, $messageID);
        // Check if there's an error.
        if ($this->nntp->isError($body)) {
            return false;
        }
        // Decompress the body.
        $body = @gzinflate($body);
        if ($body === false) {
            return false;
        }
        // JSON Decode the body.
        $body = json_decode($body, true);
        if ($body === false) {
            return false;
        }
        // Just in case.
        if (!isset($body['USER']) || !isset($body['SID']) || !isset($body['RID']) || !isset($body['TIME']) | !isset($body['BODY'])) {
            return false;
        }
        // Insert the comment.
        if ($this->pdo->queryExec(sprintf('
				INSERT INTO release_comments
				(text, createddate, shareid, nzb_guid, siteid, username, user_id, releaseid, shared, host)
				VALUES (%s, %s, %s, UNHEX(%s), %s, %s, 0, 0, 2, "")', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($siteID), $this->pdo->escapeString(substr($body['USER'], 0, 3) === 'sn-' ? 'SH_ANON' : 'SH_' . $body['USER'])))) {
            return true;
        }
        return false;
    }
Esempio n. 7
0
    public function processGamesReleases()
    {
        $res = $this->pdo->queryDirect(sprintf('
				SELECT searchname, id
				FROM releases
				WHERE nzbstatus = 1 %s
				AND gamesinfo_id = 0
				AND categoryid = 4050
				ORDER BY postdate DESC
				LIMIT %d', $this->renamed, $this->gameQty));
        if ($res instanceof \Traversable && $res->rowCount() > 0) {
            if ($this->echoOutput) {
                $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' games release(s).'));
            }
            foreach ($res as $arr) {
                // Reset maxhitrequest
                $this->maxHitRequest = false;
                $startTime = microtime(true);
                $usedgb = false;
                $gameInfo = $this->parseTitle($arr['searchname']);
                if ($gameInfo !== false) {
                    if ($this->echoOutput) {
                        $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($gameInfo['title'] . ' (PC)'));
                    }
                    // Check for existing games entry.
                    $gameCheck = $this->getGamesInfoByName($gameInfo['title']);
                    if ($gameCheck === false) {
                        $gameId = $this->updateGamesInfo($gameInfo);
                        $usedgb = true;
                        if ($gameId === false) {
                            $gameId = -2;
                            // Leave gamesinfo_id 0 to parse again
                            if ($this->maxHitRequest === true) {
                                $gameId = 0;
                            }
                        }
                    } else {
                        $gameId = $gameCheck['id'];
                    }
                    // Update release.
                    $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', $gameId, $arr['id']));
                } else {
                    // Could not parse release title.
                    $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', -2, $arr['id']));
                    if ($this->echoOutput) {
                        echo '.';
                    }
                }
                // Sleep to not flood giantbomb.
                $diff = floor((microtime(true) - $startTime) * 1000000);
                if ($this->sleepTime * 1000 - $diff > 0 && $usedgb === true) {
                    usleep($this->sleepTime * 1000 - $diff);
                }
            }
        } else {
            if ($this->echoOutput) {
                $this->pdo->log->doEcho($this->pdo->log->header('No games releases to process.'));
            }
        }
    }
Esempio n. 8
0
 public function startRunning()
 {
     if (!$this->isRunning()) {
         return $this->pdo->queryExec("UPDATE tmux SET value = '1' WHERE setting = 'running'");
     }
     return true;
 }
Esempio n. 9
0
    /**
     * No request ID was found, update the release.
     *
     * @param int $releaseID
     * @param int $status
     */
    protected function _requestIdNotFound($releaseID, $status)
    {
        if ($releaseID == 0) {
            return;
        }
        $this->pdo->queryExec(sprintf('
				UPDATE releases SET reqidstatus = %d WHERE id = %d', $status, $releaseID));
    }
Esempio n. 10
0
 /**
  * @param bool $local
  */
 public function processMusicReleases($local = false)
 {
     $res = $this->pdo->queryDirect(sprintf('SELECT searchname, id FROM releases ' . 'WHERE musicinfoid IS NULL AND nzbstatus = 1 %s AND categoryid IN (3010, 3040, 3050) ' . 'ORDER BY postdate DESC LIMIT %d', $this->renamed, $this->musicqty));
     if ($res instanceof \Traversable && $res->rowCount() > 0) {
         if ($this->echooutput) {
             $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' music release(s).'));
         }
         foreach ($res as $arr) {
             $startTime = microtime(true);
             $usedAmazon = false;
             $album = $this->parseArtist($arr['searchname']);
             if ($album !== false) {
                 $newname = $album["name"] . ' (' . $album["year"] . ')';
                 if ($this->echooutput) {
                     $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($newname));
                 }
                 // Do a local lookup first
                 $musicCheck = $this->getMusicInfoByName('', $album["name"]);
                 if ($musicCheck === false && in_array($album['name'] . $album['year'], $this->failCache)) {
                     // Lookup recently failed, no point trying again
                     if ($this->echooutput) {
                         $this->pdo->log->doEcho($this->pdo->log->headerOver('Cached previous failure. Skipping.') . PHP_EOL);
                     }
                     $albumId = -2;
                 } else {
                     if ($musicCheck === false && $local === false) {
                         $albumId = $this->updateMusicInfo($album['name'], $album['year']);
                         $usedAmazon = true;
                         if ($albumId === false) {
                             $albumId = -2;
                             $this->failCache[] = $album['name'] . $album['year'];
                         }
                     } else {
                         $albumId = $musicCheck['id'];
                     }
                 }
                 // Update release.
                 $this->pdo->queryExec(sprintf("UPDATE releases SET musicinfoid = %d WHERE id = %d", $albumId, $arr["id"]));
             } else {
                 $this->pdo->queryExec(sprintf("UPDATE releases SET musicinfoid = %d WHERE id = %d", -2, $arr["id"]));
                 echo '.';
             }
             // Sleep to not flood amazon.
             $diff = floor((microtime(true) - $startTime) * 1000000);
             if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) {
                 usleep($this->sleeptime * 1000 - $diff);
             }
         }
         if ($this->echooutput) {
             echo "\n";
         }
     } else {
         if ($this->echooutput) {
             $this->pdo->log->doEcho($this->pdo->log->header('No music releases to process.'));
         }
     }
 }
Esempio n. 11
0
    /** This function updates a single variable column in releases
     *  The first parameter is the column to update, the second is the value
     *  The final parameter is the ID of the release to update
     *
     * @param string  $column
     * @param integer $status
     * @param integer $id
     */
    private function _updateSingleColumn($column = '', $status = 0, $id = 0)
    {
        if ($column !== '' && $id !== 0) {
            $this->pdo->queryExec(sprintf('
							UPDATE releases
							SET %s = %s
							WHERE id = %d', $column, is_numeric($status) ? $status : $this->pdo->escapeString($status), $id));
        }
    }
Esempio n. 12
0
 /**
  * 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 ['hidden' => false, 'ID' => $messageID];
         } elseif ($hiddenNFO === true && strlen($hiddenID) > 1) {
             return ['hidden' => true, 'ID' => $hiddenID];
         }
     }
     return false;
 }
Esempio n. 13
0
    public function processConsoleReleases()
    {
        $res = $this->pdo->queryDirect(sprintf('
							SELECT searchname, id
							FROM releases
							WHERE nzbstatus = %d %s
							AND consoleinfoid IS NULL
							AND categoryid BETWEEN 1000 AND 1999
							ORDER BY postdate DESC
							LIMIT %d', NZB::NZB_ADDED, $this->renamed, $this->gameqty));
        if ($res instanceof Traversable && $res->rowCount() > 0) {
            if ($this->echooutput) {
                $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' console release(s).'));
            }
            foreach ($res as $arr) {
                $startTime = microtime(true);
                $usedAmazon = false;
                $gameId = self::CONS_NTFND;
                $gameInfo = $this->parseTitle($arr['searchname']);
                if ($gameInfo !== false) {
                    if ($this->echooutput) {
                        $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($gameInfo['title'] . ' (' . $gameInfo['platform'] . ')'));
                    }
                    // Check for existing console entry.
                    $gameCheck = $this->getConsoleInfoByName($gameInfo['title'], $gameInfo['platform']);
                    if ($gameCheck === false) {
                        $gameId = $this->updateConsoleInfo($gameInfo);
                        $usedAmazon = true;
                    } else {
                        if ($this->echooutput) {
                            $this->pdo->log->doEcho($this->pdo->log->headerOver("Found Local: ") . $this->pdo->log->primary("{$gameCheck['title']} - {$gameCheck['platform']}") . PHP_EOL);
                        }
                        $gameId = $gameCheck['id'];
                    }
                } elseif ($this->echooutput) {
                    echo '.';
                }
                // Update release.
                $this->pdo->queryExec(sprintf('
								UPDATE releases
								SET consoleinfoid = %d
								WHERE id = %d', $gameId, $arr['id']));
                // Sleep to not flood amazon.
                $diff = floor((microtime(true) - $startTime) * 1000000);
                if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) {
                    usleep($this->sleeptime * 1000 - $diff);
                }
            }
        } else {
            if ($this->echooutput) {
                $this->pdo->log->doEcho($this->pdo->log->header('No console releases to process.'));
            }
        }
    }
Esempio n. 14
0
 /**
  * Check if Tmux is running, stop it if it is.
  *
  * @return bool
  * @access public
  */
 public function isRunning()
 {
     if ($this->get()->running == 1) {
         $this->pdo->queryExec("UPDATE tmux SET value = '0' WHERE setting = 'RUNNING'");
         $sleep = $this->get()->monitor_delay;
         echo $this->pdo->log->header("Stopping tmux scripts and waiting {$sleep} seconds for all panes to shutdown");
         sleep($sleep);
         return true;
     }
     return false;
 }
Esempio n. 15
0
    /**
     * Updates existing anime info in anidb info/episodes tables
     *
     * @param array $AniDBInfoArray
     *
     * @return string
     */
    private function updateAniDBInfoEps($AniDBInfoArray = [])
    {
        $this->pdo->queryExec(sprintf('
						UPDATE anidb_info
						SET type = %s, startdate = %s, enddate = %s, related = %s,
							similar = %s, creators = %s, description = %s,
							rating = %s, picture = %s, categories = %s, characters = %s,
							updated = NOW()
						WHERE anidbid = %d', $this->pdo->escapeString($AniDBInfoArray['type']), $this->pdo->escapeString($AniDBInfoArray['startdate']), $this->pdo->escapeString($AniDBInfoArray['enddate']), $this->pdo->escapeString($AniDBInfoArray['related']), $this->pdo->escapeString($AniDBInfoArray['similar']), $this->pdo->escapeString($AniDBInfoArray['creators']), $this->pdo->escapeString($AniDBInfoArray['description']), $this->pdo->escapeString($AniDBInfoArray['rating']), $this->pdo->escapeString($AniDBInfoArray['picture']), $this->pdo->escapeString($AniDBInfoArray['categories']), $this->pdo->escapeString($AniDBInfoArray['characters']), $this->anidbId));
        $this->insertAniDBEpisodes($AniDBInfoArray['epsarr']);
        return $AniDBInfoArray['picture'];
    }
Esempio n. 16
0
 /**
  * Check if the tables exists for the group_id, make new tables for table per group.
  *
  * @param int $groupID
  *
  * @return bool
  */
 public function createNewTPGTables($groupID)
 {
     foreach (['collections', 'binaries', 'parts', 'partrepair'] as $tableName) {
         if ($this->pdo->queryExec(sprintf('SELECT * FROM %s_%s LIMIT 1', $tableName, $groupID), true) === false) {
             if ($this->pdo->queryExec(sprintf('CREATE TABLE %s_%s LIKE %s', $tableName, $groupID, $tableName), true) === false) {
                 return false;
             } else {
                 if ($tableName === 'collections') {
                     $this->pdo->queryExec(sprintf('CREATE TRIGGER delete_collections_%s BEFORE DELETE ON collections_%s FOR EACH ROW BEGIN' . ' DELETE FROM binaries_%s WHERE collectionid = OLD.id; DELETE FROM parts_%s WHERE collection_id = OLD.id; END', $groupID, $groupID, $groupID, $groupID));
                 }
             }
         }
     }
     return true;
 }
Esempio n. 17
0
    /**
     * Write an NZB to the hard drive for a single release.
     *
     * @param int    $relID   The ID of the release in the DB.
     * @param string $relGuid The guid of the release.
     * @param string $name    The name of the release.
     * @param string $cTitle  The name of the category this release is in.
     *
     * @return bool Have we successfully written the NZB to the hard drive?
     *
     * @access public
     */
    public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle)
    {
        $path = $this->buildNZBPath($relGuid, $this->nzbSplitLevel, true) . $relGuid . '.nzb.gz';
        $fp = gzopen($path, 'wb7');
        if ($fp) {
            $nzb_guid = '';
            gzwrite($fp, sprintf($this->_nzbHeadString, htmlspecialchars($cTitle, ENT_QUOTES, 'utf-8'), htmlspecialchars($name, ENT_QUOTES, 'utf-8')));
            $collections = $this->pdo->queryDirect($this->_collectionsQuery . $relID);
            if ($collections instanceof \Traversable) {
                foreach ($collections as $collection) {
                    $poster = htmlspecialchars($collection['fromname'], ENT_QUOTES, 'utf-8');
                    $binaries = $this->pdo->queryDirect(sprintf($this->_binariesQuery, $collection['id']));
                    if ($binaries instanceof \Traversable) {
                        foreach ($binaries as $binary) {
                            // Buffer segment writes, increases performance.
                            $string = '';
                            $parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $binary['id']));
                            if ($parts instanceof \Traversable) {
                                foreach ($parts as $part) {
                                    if ($nzb_guid === '') {
                                        $nzb_guid = $part['messageid'];
                                    }
                                    $string .= '  <segment bytes="' . $part['size'] . '" number="' . $part['partnumber'] . '">' . htmlspecialchars($part['messageid'], ENT_QUOTES, 'utf-8') . "</segment>\n";
                                }
                            }
                            gzwrite($fp, '<file poster="' . $poster . '" date="' . $collection['udate'] . '" subject="' . htmlspecialchars($binary['name'], ENT_QUOTES, 'utf-8') . ' (1/' . $binary['totalparts'] . ")\">\n <groups>\n  <group>" . $collection['groupname'] . "</group>\n </groups>\n <segments>\n" . $string . " </segments>\n</file>\n");
                        }
                    }
                }
            }
            gzwrite($fp, '</nzb>');
            gzclose($fp);
            if (is_file($path)) {
                // Mark release as having NZB and delete CBP.
                $this->pdo->queryExec(sprintf('
						UPDATE releases SET nzbstatus = %d %s WHERE id = %d;
						DELETE c, b, p FROM %s c JOIN %s b ON(c.id=b.collection_id) STRAIGHT_JOIN %s p ON(b.id=p.binaryid) WHERE c.releaseid = %d', NZB::NZB_ADDED, $nzb_guid === '' ? '' : ', nzb_guid = UNHEX( ' . $this->pdo->escapestring(md5($nzb_guid)) . ' )', $relID, $this->_tableNames['cName'], $this->_tableNames['bName'], $this->_tableNames['pName'], $relID));
                // Chmod to fix issues some users have with file permissions.
                chmod($path, 0777);
                return true;
            } else {
                echo "ERROR: {$path} does not exist.\n";
            }
        }
        return false;
    }
Esempio n. 18
0
    /**
     * Try to get a title from a Linux_2rename.sh file for alt.binaries.u4e group.
     *
     * @param $fileLocation
     */
    protected function _processU4ETitle($fileLocation)
    {
        // Open the file for reading.
        $handle = @fopen($fileLocation, 'r');
        // Check if it failed.
        if ($handle) {
            // Loop over the file line by line.
            while (($buffer = fgets($handle, 16384)) !== false) {
                // Check if we find the word
                if (stripos($buffer, 'mkdir') !== false) {
                    // Get a new name.
                    $newName = trim(str_replace('mkdir ', '', $buffer));
                    // Check if it's a empty string or not.
                    if (empty($newName)) {
                        continue;
                    }
                    // Get a new category ID.
                    $newCategory = $this->_categorize->determineCategory($newName, $this->_release['group_id']);
                    $newTitle = $this->pdo->escapeString(substr($newName, 0, 255));
                    // Update the release with the data.
                    $this->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', $newTitle, $newCategory, $this->_release['id']));
                    $this->sphinx->updateReleaseSearchName($this->_release['id'], $newTitle);
                    // Echo the changed name to CLI.
                    if ($this->_echoCLI) {
                        \NameFixer::echoChangedReleaseName(array('new_name' => $newName, 'old_name' => $this->_release['searchname'], 'new_category' => $newCategory, 'old_category' => $this->_release['categoryid'], 'group' => $this->_release['group_id'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_processU4ETitle'));
                    }
                    // Break out of the loop.
                    break;
                }
            }
            // Close the file.
            fclose($handle);
        }
        // Delete the file.
        @unlink($fileLocation);
    }
Esempio n. 19
0
 /**
  * Update a TV show category ID for a user's "my show" TV show.
  * @param int   $uID    ID of the user.
  * @param int   $rageID ID of the TV show.
  * @param array $catID  List of category ID's.
  */
 public function updateShow($uID, $rageID, $catID = array())
 {
     $this->pdo->queryExec(sprintf("UPDATE userseries SET categoryid = %s WHERE user_id = %d AND rageid = %d", !empty($catID) ? $this->pdo->escapeString(implode('|', $catID)) : "NULL", $uID, $rageID));
 }
Esempio n. 20
0
 public function data_update($content)
 {
     return $this->pdo->queryExec(sprintf("UPDATE content SET role = %d, title = %s, url = %s, body = %s, metadescription = %s, metakeywords = %s, contenttype = %d, showinmenu = %d, status = %d, ordinal = %d WHERE id = %d", $content->role, $this->pdo->escapeString($content->title), $this->pdo->escapeString($content->url), $this->pdo->escapeString($content->body), $this->pdo->escapeString($content->metadescription), $this->pdo->escapeString($content->metakeywords), $content->contenttype, $content->showinmenu, $content->status, $content->ordinal, $content->id));
 }
Esempio n. 21
0
								LEFT OUTER JOIN release_files rf ON r.id = rf.releaseid AND rf.ishashed = 1
								WHERE r.guid %s
								AND nzbstatus = 1 AND r.ishashed = 1
								AND r.dehashstatus BETWEEN -6 AND 0
								AND r.preid = 0
								ORDER BY r.dehashstatus DESC, r.postdate ASC
								LIMIT %s', $pdo->likeString($guidChar, false, true), $maxperrun));
                if ($releases instanceof \Traversable) {
                    foreach ($releases as $release) {
                        if (preg_match('/[a-fA-F0-9]{32,40}/i', $release['name'], $matches)) {
                            $namefixer->matchPredbHash($matches[0], $release, 1, 1, true, 1);
                        } else {
                            if (preg_match('/[a-fA-F0-9]{32,40}/i', $release['filename'], $matches)) {
                                $namefixer->matchPredbHash($matches[0], $release, 1, 1, true, 1);
                            } else {
                                $pdo->queryExec(sprintf("UPDATE releases SET dehashstatus = %d - 1 WHERE id = %d", $release['dehashstatus'], $release['releaseid']));
                                echo '.';
                            }
                        }
                    }
                }
                break;
            case $pieces[0] === 'par2' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun):
                $releases = $pdo->queryDirect(sprintf('
								SELECT r.id AS releaseid, r.guid, r.group_id
								FROM releases r
								WHERE r.guid %s
								AND r.nzbstatus = 1
								AND r.proc_par2 = 0
								AND r.preid = 0
								ORDER BY r.postdate ASC
Esempio n. 22
0
function create_guids($live, $delete = false)
{
    $pdo = new Settings();
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $timestart = TIME();
    $relcount = $deleted = $total = 0;
    $relrecs = false;
    if ($live == "true") {
        $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC"));
    } else {
        if ($live == "limited") {
            $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000"));
        }
    }
    if ($relrecs) {
        $total = $relrecs->rowCount();
    }
    if ($total > 0) {
        echo $pdo->log->header("Creating nzb_guids for " . number_format($total) . " releases.");
        $releases = new Releases(['Settings' => $pdo]);
        $nzb = new NZB($pdo);
        $releaseImage = new ReleaseImage($pdo);
        $reccnt = 0;
        if ($relrecs instanceof Traversable) {
            foreach ($relrecs as $relrec) {
                $reccnt++;
                $nzbpath = $nzb->NZBPath($relrec['guid']);
                if ($nzbpath !== false) {
                    $nzbfile = nzedb\utility\Utility::unzipGzipFile($nzbpath);
                    if ($nzbfile) {
                        $nzbfile = @simplexml_load_string($nzbfile);
                    }
                    if (!$nzbfile) {
                        if (isset($delete) && $delete == 'delete') {
                            //echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n";
                            $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                            $deleted++;
                        }
                        continue;
                    }
                    $binary_names = array();
                    foreach ($nzbfile->file as $file) {
                        $binary_names[] = $file["subject"];
                    }
                    if (count($binary_names) == 0) {
                        if (isset($delete) && $delete == 'delete') {
                            //echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n";
                            $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                            $deleted++;
                        }
                        continue;
                    }
                    asort($binary_names);
                    foreach ($nzbfile->file as $file) {
                        if ($file["subject"] == $binary_names[0]) {
                            $segment = $file->segments->segment;
                            $nzb_guid = md5($segment);
                            $pdo->queryExec("UPDATE releases set nzb_guid = " . $pdo->escapestring($nzb_guid) . " WHERE id = " . $relrec["id"]);
                            $relcount++;
                            $consoletools->overWritePrimary("Created: [" . $deleted . "] " . $consoletools->percentString($reccnt, $total) . " Time:" . $consoletools->convertTimer(TIME() - $timestart));
                            break;
                        }
                    }
                } else {
                    if (isset($delete) && $delete == 'delete') {
                        //echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting.");
                        $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                    }
                }
            }
        }
        if ($relcount > 0) {
            echo "\n";
        }
        echo $pdo->log->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart));
    } else {
        echo $pdo->log->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart));
        exit($pdo->log->info("No releases are missing the guid."));
    }
}
Esempio n. 23
0
 /**
  * Update upcoming table.
  *
  * @param string $source
  * @param $type
  * @param string|false $info
  *
  * @return boolean|int
  */
 protected function updateInsUpcoming($source, $type, $info)
 {
     return $this->pdo->queryExec(sprintf("\n\t\t\t\tINSERT INTO upcoming_releases (source, typeid, info, updateddate)\n\t\t\t\tVALUES (%s, %d, %s, NOW())\n\t\t\t\tON DUPLICATE KEY UPDATE info = %s", $this->pdo->escapeString($source), $type, $this->pdo->escapeString($info), $this->pdo->escapeString($info)));
 }
Esempio n. 24
0
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\ConsoleTools;
use nzedb\Groups;
use nzedb\db\Settings;
$pdo = new Settings();
if (!isset($argv[1]) || $argv[1] != 'true') {
    exit($pdo->log->error("\nThis script will move all collections, binaries, parts into tables per group.\n\n" . "php {$argv['0']} true                ...: To process all parts and leave the parts/binaries/collections tables intact.\n" . "php {$argv['0']} true truncate       ...: To process all parts and truncate parts/binaries/collections tables after completed.\n"));
}
$start = time();
$consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$groups = new Groups(['Settings' => $pdo]);
$actgroups = $pdo->query("SELECT DISTINCT group_id from collections");
echo $pdo->log->info("Creating new collections, binaries, and parts tables for each group that has collections.");
foreach ($actgroups as $group) {
    $pdo->queryExec("DROP TABLE IF EXISTS collections_" . $group['group_id']);
    $pdo->queryExec("DROP TABLE IF EXISTS binaries_" . $group['group_id']);
    $pdo->queryExec("DROP TABLE IF EXISTS parts_" . $group['group_id']);
    if ($groups->createNewTPGTables($group['group_id']) === false) {
        exit($pdo->log->error("\nThere is a problem creating new parts/files tables for group {$group['name']}.\n"));
    }
}
$collections_rows = $pdo->queryDirect("SELECT group_id FROM collections GROUP BY group_id");
echo $pdo->log->info("Counting parts, this could table a few minutes.");
$parts_count = $pdo->queryOneRow("SELECT COUNT(*) AS cnt FROM parts");
$i = 0;
if ($collections_rows instanceof \Traversable) {
    foreach ($collections_rows as $row) {
        $groupName = $groups->getByNameByID($row['group_id']);
        echo $pdo->log->header("Processing {$groupName}");
        //collection
Esempio n. 25
0
    if ($titles instanceof \Traversable) {
        foreach ($titles as $row) {
            $matched = 0;
            $searched = 0;
            $matched = $namefixer->matchPredbFT($row, 1, 1, true, $show);
            //echo "Pre Title " . $row['title'] . " is translated to search string: ";
            //echo $pdo->log->header($matched);
            if ($matched > 0) {
                $searched = 1;
                $counted++;
            } elseif ($matched < 0) {
                $searched = -6;
                echo "*";
            } else {
                $searched = $row['searched'] - 1;
                echo ".";
            }
            $pdo->queryExec(sprintf("UPDATE predb SET searched = %d WHERE id = %d", $searched, $row['preid']));
            if (!isset($argv[2]) || $argv[2] !== 'show') {
                $consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $consoletools->percentString(++$counter, $total));
            }
        }
    }
    if ($total > 0) {
        echo $pdo->log->header("\nRenamed " . number_format($counted) . " releases in " . $consoletools->convertTime(TIME() - $timestart) . ".");
    } else {
        echo $pdo->log->info("\nNothing to do.");
    }
} else {
    echo $pdo->log->info("No work to process.\n");
}
Esempio n. 26
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\ConsoleTools;
use nzedb\db\Settings;
$pdo = new Settings();
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$ran = false;
if (isset($argv[1]) && $argv[1] === "all") {
    if (isset($argv[2]) && $argv[2] === "true") {
        $ran = true;
        $where = '';
        if (isset($argv[3]) && $argv[3] === "truncate") {
            echo "Truncating tables\n";
            $pdo->queryExec("TRUNCATE TABLE consoleinfo");
            $pdo->queryExec("TRUNCATE TABLE gamesinfo");
            $pdo->queryExec("TRUNCATE TABLE movieinfo");
            $pdo->queryExec("TRUNCATE TABLE video_data");
            $pdo->queryExec("TRUNCATE TABLE musicinfo");
            $pdo->queryExec("TRUNCATE TABLE bookinfo");
            $pdo->queryExec("TRUNCATE TABLE release_nfos");
            $pdo->queryExec("TRUNCATE TABLE releaseextrafull");
            $pdo->queryExec("TRUNCATE TABLE xxxinfo");
        }
        echo $pdo->log->header("Resetting all postprocessing");
        $qry = $pdo->queryDirect("SELECT id FROM releases");
        $affected = 0;
        if ($qry instanceof \Traversable) {
            $total = $qry->rowCount();
            foreach ($qry as $releases) {
                $pdo->queryExec(sprintf("\n\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\tSET consoleinfoid = NULL, gamesinfo_id = 0, imdbid = NULL, musicinfoid = NULL,\n\t\t\t\t\t\t\tbookinfoid = NULL, rageid = -1, xxxinfo_id = 0, passwordstatus = -1, haspreview = -1,\n\t\t\t\t\t\t\tjpgstatus = 0, videostatus = 0, audiostatus = 0, nfostatus = -1\n\t\t\t\t\t\tWHERE id = %d", $releases['id']));
Esempio n. 27
0
<?php

require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
require_once nZEDb_LIB . 'utility' . DS . 'CopyFileTree.php';
use nzedb\db\Settings;
$reorg = nZEDb_MISC . 'testing' . DS . 'NZBs' . DS . 'nzb-reorg.php';
$pdo = new Settings();
$level = $pdo->getSetting('nzbsplitlevel');
$nzbpath = $pdo->getSetting('nzbpath');
if (!isset($argv[1])) {
    exit("WARNING: Run convert_from_newznab.php BEFORE running this script.\nUsage php copy_from_newznab.php path_to_newznab_base\n");
} else {
    if (isset($argv[1]) && !file_exists($argv[1])) {
        exit("{$argv['1']}) is an invalid path\n");
    } else {
        $source = realpath($argv[1] . DS . 'nzbfiles');
        $files = new \nzedb\utility\CopyFileTree($argv[1], $nzbpath);
        echo "Copying nzbs from " . $argv[1] . "\n";
        $files->copy('*');
        $source = realpath($argv[1] . DS . 'www' . DS . 'covers');
        // NN+ path, do not change.
        $files = new \nzedb\utility\CopyFileTree($source, nZEDb_COVERS);
        echo "Copying covers from {$source}\n";
        $files->copy('*');
        echo "Setting nzbstatus for all releases\n";
        $pdo->queryExec("UPDATE releases SET nzbstatus = 1");
        system("php {$reorg} {$level} {$nzbpath}");
    }
}
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (see LICENSE.txt in the base directory.  If
 * not, see:
 *
 * @link <http://www.gnu.org/licenses/>.
 * @author niel
 * @copyright 2014 nZEDb
 */
require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php';
use nzedb\db\Settings;
$pdo = new Settings();
if (!$pdo->getSetting('tablepergroup')) {
    exit("Tables per groups is not enabled, quitting!");
}
// Doing it this way in case there are tables existing not related to the active/backfill list (i.e. I don't have a clue when these tables get deleted so I'm doing any that are there).
$tables = $pdo->queryDirect("SELECT SUBSTR(TABLE_NAME, 12) AS suffix FROM information_schema.TABLES WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND TABLE_NAME LIKE 'collections%' ORDER BY TABLE_NAME");
$query1 = "ALTER table collections%s add noise char(32) not null default '' after releaseid";
if ($tables instanceof \Traversable) {
    foreach ($tables as $table) {
        echo "Updating table collections{$table['suffix']}" . PHP_EOL;
        $pdo->queryExec(sprintf($query1, $table['suffix']), true);
    }
    echo 'All done!' . PHP_EOL;
}
Esempio n. 29
0
 /**
  * Update a category.
  * @param $id
  * @param $status
  * @param $desc
  * @param $disablepreview
  * @param $minsize
  *
  * @return bool
  */
 public function update($id, $status, $desc, $disablepreview, $minsize)
 {
     return $this->pdo->queryExec(sprintf("UPDATE category SET disablepreview = %d, status = %d, description = %s, minsize = %d\n\t\t\t\tWHERE id = %d", $disablepreview, $status, $this->pdo->escapeString($desc), $minsize, $id));
 }
Esempio n. 30
0
}
echo $pdo->log->warning("This script removes all releases, nzb files, samples, previews , nfos, truncates all article tables and resets all groups.");
echo $pdo->log->header("Are you sure you want reset the DB?  Type 'DESTROY' to continue:  \n");
echo $pdo->log->warningOver("\n");
$line = fgets(STDIN);
if (trim($line) != 'DESTROY') {
    exit($pdo->log->error("This script is dangerous you must type DESTROY for it function."));
}
echo "\n";
echo $pdo->log->header("Thank you, continuing...\n\n");
$timestart = time();
$relcount = 0;
$ri = new ReleaseImage($pdo);
$nzb = new NZB($pdo);
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$pdo->queryExec("UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL");
echo $pdo->log->primary("Reseting all groups completed.");
$arr = ["tvrage_titles", "release_nfos", "release_comments", 'sharing', 'sharing_sites', "users_releases", "user_movies", "user_series", "movieinfo", "musicinfo", "release_files", "audio_data", "release_subtitles", "video_data", "releaseextrafull", "parts", "missed_parts", "binaries", "collections", "releases"];
foreach ($arr as &$value) {
    $rel = $pdo->queryExec("TRUNCATE TABLE {$value}");
    if ($rel !== false) {
        echo $pdo->log->primary("Truncating {$value} completed.");
    }
}
unset($value);
$sql = "SHOW table status";
$tables = $pdo->query($sql);
foreach ($tables as $row) {
    $tbl = $row['name'];
    if (preg_match('/collections_\\d+/', $tbl) || preg_match('/binaries_\\d+/', $tbl) || preg_match('/parts_\\d+/', $tbl) || preg_match('/missed_parts_\\d+/', $tbl) || preg_match('/\\d+_collections/', $tbl) || preg_match('/\\d+_binaries/', $tbl) || preg_match('/\\d+_parts/', $tbl) || preg_match('/\\d+_missed_parts_\\d+/', $tbl)) {
        $rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl));