Exemplo n.º 1
0
 /**
  * Get count of all bookinfo rows for browse list.
  */
 public function getBookCount($maxage = -1)
 {
     $browseby = $this->getBrowseBy();
     if ($maxage > 0) {
         $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage);
     } else {
         $maxage = "";
     }
     $sql = sprintf("select count(distinct r.bookinfoid) as num from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') %s %s", $browseby, $maxage);
     $res = $this->pdo->queryOneRow($sql, true);
     return $res["num"];
 }
Exemplo n.º 2
0
    /**
     * Add new files for a release ID.
     *
     * @param int    $id          The ID of the release.
     * @param string $name        Name of the file.
     * @param int    $size        Size of the file.
     * @param int    $createdTime Unix time the file was created.
     * @param int    $hasPassword Does it have a password (see Releases class constants)?
     *
     * @return mixed
     */
    public function add($id, $name, $size, $createdTime, $hasPassword)
    {
        $insert = 0;
        $duplicateCheck = $this->pdo->queryOneRow(sprintf('
				SELECT id
				FROM releasefiles
				WHERE releaseid = %d AND name = %s', $id, $this->pdo->escapeString(utf8_encode($name))));
        if ($duplicateCheck === false) {
            $insert = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\tINSERT INTO releasefiles\n\t\t\t\t\t\t(releaseid, name, size, createddate, passworded)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(%d, %s, %s, %s, %d)", $id, $this->pdo->escapeString(utf8_encode($name)), $this->pdo->escapeString($size), $this->pdo->from_unixtime($createdTime), $hasPassword));
        }
        return $insert;
    }
Exemplo n.º 3
0
 /**
  * Get a group id for a group name.
  *
  * @param string $groupName
  *
  * @return mixed
  *
  * @access protected
  */
 protected function _getGroupID($groupName)
 {
     if (!isset($this->_groupList[$groupName])) {
         $group = $this->_pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->_pdo->escapeString($groupName)));
         $this->_groupList[$groupName] = $group['id'];
     }
     return $this->_groupList[$groupName];
 }
Exemplo n.º 4
0
 public function getCount($ragename = "")
 {
     $rsql = '';
     if ($ragename != "") {
         $rsql .= sprintf("AND tvrage.releasetitle LIKE %s ", $this->pdo->escapeString("%" . $ragename . "%"));
     }
     $res = $this->pdo->queryOneRow(sprintf("\n\t\t\t\t\t\tSELECT COUNT(id) AS num\n\t\t\t\t\t\tFROM tvrage\n\t\t\t\t\t\tWHERE 1=1 %s", $rsql));
     return $res["num"];
 }
Exemplo n.º 5
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;
    }
Exemplo n.º 6
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'];
    }
Exemplo n.º 7
0
 public function checkName($release, $echo, $type, $namestatus, $show, $preid = false)
 {
     // Get pre style name from releases.name
     if (preg_match_all(self::PREDB_REGEX, $release['textstring'], $matches) && !preg_match('/Source\\s\\:/i', $release['textstring'])) {
         foreach ($matches as $match) {
             foreach ($match as $val) {
                 $title = $this->pdo->queryOneRow("SELECT title, id from prehash WHERE title = " . $this->pdo->escapeString(trim($val)));
                 if ($title !== false) {
                     $this->updateRelease($release, $title['title'], $method = "preDB: Match", $echo, $type, $namestatus, $show, $title['id']);
                     $preid = true;
                 }
             }
         }
     }
     // if only processing for PreDB match skip to return
     if ($preid !== true) {
         switch ($type) {
             case "PAR2, ":
                 $this->fileCheck($release, $echo, $type, $namestatus, $show);
                 break;
             case "NFO, ":
                 $this->nfoCheckTV($release, $echo, $type, $namestatus, $show);
                 $this->nfoCheckMov($release, $echo, $type, $namestatus, $show);
                 $this->nfoCheckMus($release, $echo, $type, $namestatus, $show);
                 $this->nfoCheckTY($release, $echo, $type, $namestatus, $show);
                 $this->nfoCheckG($release, $echo, $type, $namestatus, $show);
                 continue;
             case "Filenames, ":
                 $this->fileCheck($release, $echo, $type, $namestatus, $show);
                 continue;
             default:
                 $this->tvCheck($release, $echo, $type, $namestatus, $show);
                 $this->movieCheck($release, $echo, $type, $namestatus, $show);
                 $this->gameCheck($release, $echo, $type, $namestatus, $show);
                 $this->appCheck($release, $echo, $type, $namestatus, $show);
         }
         // set NameFixer process flags after run
         if ($namestatus == 1 && $this->matched === false) {
             switch ($type) {
                 case "NFO, ":
                     $this->_updateSingleColumn('proc_nfo', self::PROC_NFO_DONE, $release['releaseid']);
                     break;
                 case "Filenames, ":
                     $this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release['releaseid']);
                     break;
                 case "PAR2, ":
                     $this->_updateSingleColumn('proc_par2', self::PROC_FILES_DONE, $release['releaseid']);
                     break;
             }
         }
     }
     return $this->matched;
 }
Exemplo n.º 8
0
    /**
     * Get file info from inside PAR2, store it in DB, attempt to get a release name.
     *
     * @param string $fileLocation
     */
    protected function _siftPAR2Info($fileLocation)
    {
        $this->_par2Info->open($fileLocation);
        if ($this->_par2Info->error) {
            return;
        }
        $releaseInfo = $this->pdo->queryOneRow(sprintf('
				SELECT UNIX_TIMESTAMP(postdate) AS postdate, proc_pp
				FROM releases
				WHERE id = %d', $this->_release['id']));
        if ($releaseInfo === false) {
            return;
        }
        // Only get a new name if the category is OTHER.
        $foundName = true;
        if (NN_RENAME_PAR2 && $releaseInfo['proc_pp'] == 0 && in_array((int) $this->_release['categoryid'], [\Category::CAT_BOOK_OTHER, \Category::CAT_GAME_OTHER, \Category::CAT_MOVIE_OTHER, \Category::CAT_MUSIC_OTHER, \Category::CAT_PC_MOBILEOTHER, \Category::CAT_TV_OTHER, \Category::CAT_MISC_HASHED, \Category::CAT_XXX_OTHER, \Category::CAT_MISC_OTHER])) {
            $foundName = false;
        }
        $filesAdded = 0;
        $files = $this->_par2Info->getFileList();
        foreach ($files as $file) {
            if (!isset($file['name'])) {
                continue;
            }
            // If we found a name and added 10 files, stop.
            if ($foundName === true && $filesAdded > 10) {
                break;
            }
            // Add to release files.
            if ($this->_addPAR2Files) {
                if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf('SELECT id FROM releasefiles WHERE releaseid = %d AND name = %s', $this->_release['id'], $this->pdo->escapeString($file['name']))) === false) {
                    // Try to add the files to the DB.
                    if ($this->_releaseFiles->add($this->_release['id'], $file['name'], $file['size'], $releaseInfo['postdate'], 0)) {
                        $filesAdded++;
                    }
                }
            } else {
                $filesAdded++;
            }
            // Try to get a new name.
            if ($foundName === false) {
                $this->_release['textstring'] = $file['name'];
                $this->_release['releaseid'] = $this->_release['id'];
                if ($this->_nameFixer->checkName($this->_release, $this->_echoCLI ? 1 : 0, 'PAR2, ', 1, 1) === true) {
                    $foundName = true;
                }
            }
        }
        // Update the file count with the new file count + old file count.
        $this->pdo->queryExec(sprintf('UPDATE releases SET rarinnerfilecount = rarinnerfilecount + %d WHERE id = %d', $filesAdded, $this->_release['id']));
        $this->_foundPAR2Info = true;
    }
Exemplo n.º 9
0
    /**
     * Update Sphinx Relases index for given releaseid.
     *
     * @param int $releaseID
     * @param \newznab\db\Settings $pdo
     */
    public function updateRelease($releaseID, Settings $pdo)
    {
        if (!is_null($this->sphinxQL)) {
            $new = $pdo->queryOneRow(sprintf('
							SELECT r.id, r.name, r.searchname, r.fromname, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
							FROM releases r
							LEFT JOIN releasefiles rf ON (r.id=rf.releaseid)
							WHERE r.id = %d
							GROUP BY r.id LIMIT 1', $releaseID));
            if ($new !== false) {
                $this->insertRelease($new);
            }
        }
    }
Exemplo n.º 10
0
 /**
  * Get an episodeinfo row by name.
  */
 public function getEpisodeInfoByName($showtitle, $fullep, $epabsolute = '0')
 {
     $db = new Settings();
     if ($epabsolute == '0') {
         //as string - not int.
         if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $fullep)) {
             $additionalSql = sprintf('AND fullep = %s', $db->escapeString($fullep));
         } else {
             $additionalSql = sprintf('AND airdate LIKE %s', $db->escapeString($fullep . ' %'));
         }
     } else {
         $additionalSql = sprintf('AND epabsolute = %s', $db->escapeString($epabsolute));
     }
     return $db->queryOneRow(sprintf('SELECT * FROM episodeinfo WHERE showtitle = %s %s', $db->escapeString($showtitle), $additionalSql));
 }
Exemplo n.º 11
0
    /**
     * Directs flow for updating child AniDB tables
     *
     * @param array $AniDBInfoArray
     */
    private function updateAniChildTables($AniDBInfoArray = array())
    {
        $check = $this->pdo->queryOneRow(sprintf('
							SELECT ai.anidbid AS info
							FROM anidb_info ai
							WHERE ai.anidbid = %d', $this->anidbId));
        if ($check === false) {
            $picture = $this->insertAniDBInfoEps($AniDBInfoArray);
        } else {
            $picture = $this->updateAniDBInfoEps($AniDBInfoArray);
        }
        if (!empty($picture) && !file_exists($this->imgSavePath . $this->anidbId . ".jpg")) {
            (new \ReleaseImage($this->pdo))->saveImage($this->anidbId, 'http://img7.anidb.net/pics/anime/' . $picture, $this->imgSavePath);
        }
    }
Exemplo n.º 12
0
    /**
     * Safe backfill using posts. Going back to a date specified by the user on the site settings.
     * This does 1 group for x amount of parts until it reaches the date.
     *
     * @param string $articles
     *
     * @return void
     */
    public function safeBackfill($articles = '')
    {
        $groupname = $this->pdo->queryOneRow(sprintf('
				SELECT name FROM groups
				WHERE first_record_postdate BETWEEN %s AND NOW()
				AND backfill = 1
				ORDER BY name ASC', $this->pdo->escapeString($this->_safeBackFillDate)));
        if (!$groupname) {
            $dMessage = 'No groups to backfill, they are all at the target date ' . $this->_safeBackFillDate . ", or you have not enabled them to be backfilled in the groups page.\n";
            if ($this->_debug) {
                $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL);
            }
            exit($dMessage);
        } else {
            $this->backfillAllGroups($groupname['name'], $articles);
        }
    }
Exemplo n.º 13
0
 /**
  * Process all untagged releases to see if they are found in predb.
  */
 public function processReleases($daysback = 3)
 {
     if ($this->echooutput) {
         echo "Predb   : Updating releases with pre data\n";
     }
     $matched = 0;
     $releasesQuery = $this->pdo->queryDirect(sprintf('SELECT id, searchname FROM releases WHERE preid IS NULL AND adddate > DATE_SUB(NOW(), INTERVAL %d DAY)', $daysback));
     while ($arr = $this->pdo->getAssocArray($releasesQuery)) {
         $arr['searchname'] = str_replace(' ', '_', $arr['searchname']);
         $sql = sprintf("SELECT id FROM predb WHERE dirname = %s LIMIT 1", $this->pdo->escapeString($arr['searchname']));
         $predbQuery = $this->pdo->queryOneRow($sql);
         if ($predbQuery) {
             $this->pdo->queryExec(sprintf('UPDATE releases SET preid = %d WHERE id = %d', $predbQuery['id'], $arr['id']));
             $matched++;
         }
     }
     if ($this->echooutput) {
         echo "Predb   : Matched pre data to " . $matched . " releases\n";
     }
 }
Exemplo n.º 14
0
 /**
  * Get Genre id's Of the title
  *
  * @param $arr - Array or String
  *
  * @return string - If array .. 1,2,3,4 if string .. 1
  */
 private function getGenreID($arr)
 {
     $ret = null;
     if (!is_array($arr)) {
         $res = $this->pdo->queryOneRow("SELECT id FROM genres WHERE title = " . $this->pdo->escapeString($arr));
         if ($res !== false) {
             return $res["id"];
         }
     }
     foreach ($arr as $key => $value) {
         $res = $this->pdo->queryOneRow("SELECT id FROM genres WHERE title = " . $this->pdo->escapeString($value));
         if ($res !== false) {
             $ret .= "," . $res["id"];
         } else {
             $ret .= "," . $this->insertGenre($value);
         }
     }
     $ret = ltrim($ret, ",");
     return $ret;
 }
Exemplo n.º 15
0
    protected function _updateConsoleTable($con = [])
    {
        $ri = new \ReleaseImage($this->pdo);
        $check = $this->pdo->queryOneRow(sprintf('
							SELECT id
							FROM consoleinfo
							WHERE asin = %s', $this->pdo->escapeString($con['asin'])));
        if ($check === false) {
            $consoleId = $this->pdo->queryInsert(sprintf("INSERT INTO consoleinfo (title, asin, url, salesrank, platform, publisher, genreid, esrb, releasedate, review, cover, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, NOW(), NOW())", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $con['salesrank'], $this->pdo->escapeString($con['platform']), $this->pdo->escapeString($con['publisher']), $con['consolegenreid'] == -1 ? "null" : $con['consolegenreid'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover']));
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
        } else {
            $consoleId = $check['id'];
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
            $this->update($consoleId, $con['title'], $con['asin'], $con['url'], $con['salesrank'], $con['platform'], $con['publisher'], isset($con['releasedate']) ? $con['releasedate'] : null, $con['esrb'], $con['cover'], $con['consolegenreid'], isset($con['review']) ? $con['review'] : null);
        }
        return $consoleId;
    }
Exemplo n.º 16
0
 /**
  * Insert the NZB details into the database.
  *
  * @param $nzbDetails
  *
  * @return bool
  *
  * @access protected
  */
 protected function insertNZB($nzbDetails)
 {
     // Make up a GUID for the release.
     $this->relGuid = $this->releases->createGUID();
     // Remove part count from subject.
     $partLess = preg_replace('/(\\(\\d+\\/\\d+\\))*$/', 'yEnc', $nzbDetails['subject']);
     // Remove added yEnc from above and anything after.
     $subject = utf8_encode(trim(preg_replace('/yEnc.*$/i', 'yEnc', $partLess)));
     $renamed = 0;
     if ($nzbDetails['useFName']) {
         // If the user wants to use the file name.. use it.
         $cleanName = $nzbDetails['useFName'];
         $renamed = 1;
     } else {
         // Pass the subject through release cleaner to get a nicer name.
         $cleanName = $this->releaseCleaner->releaseCleaner($subject, $nzbDetails['from'], $nzbDetails['totalSize'], $nzbDetails['groupName']);
         if (isset($cleanName['properlynamed'])) {
             $cleanName = $cleanName['cleansubject'];
             $renamed = isset($cleanName['properlynamed']) && $cleanName['properlynamed'] === true ? 1 : 0;
         }
     }
     $escapedSubject = $this->pdo->escapeString($subject);
     $escapedFromName = $this->pdo->escapeString($nzbDetails['from']);
     // Look for a duplicate on name, poster and size.
     $dupeCheck = $this->pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE name = %s AND fromname = %s AND size BETWEEN %s AND %s', $escapedSubject, $escapedFromName, $this->pdo->escapeString($nzbDetails['totalSize'] * 0.99), $this->pdo->escapeString($nzbDetails['totalSize'] * 1.01)));
     if ($dupeCheck === false) {
         $escapedSearchName = $this->pdo->escapeString($cleanName);
         // Insert the release into the DB.
         $relID = $this->releases->insertRelease(['name' => $escapedSubject, 'searchname' => $escapedSearchName, 'totalpart' => $nzbDetails['totalFiles'], 'groupid' => $nzbDetails['groupid'], 'guid' => $this->pdo->escapeString($this->relGuid), 'postdate' => $this->pdo->escapeString($nzbDetails['postDate']), 'fromname' => $escapedFromName, 'size' => $this->pdo->escapeString($nzbDetails['totalSize']), 'categoryid' => $this->category->determineCategory($nzbDetails['groupid'], $cleanName), 'isrenamed' => $renamed, 'reqidstatus' => 0, 'prehashid' => 0, 'nzbstatus' => NZB::NZB_ADDED]);
     } else {
         //$this->echoOut('This release is already in our DB so skipping: ' . $subject);
         return false;
     }
     if (isset($relID) && $relID === false) {
         $this->echoOut('ERROR: Problem inserting: ' . $subject);
         return false;
     }
     return true;
 }
Exemplo n.º 17
0
 /**
  * Get count of all consoleinfo rows for browse list.
  */
 public function getConsoleCount($cat, $maxage = -1, $excludedcats = [])
 {
     $browseby = $this->getBrowseBy();
     $catsrch = "";
     if (count($cat) > 0 && $cat[0] != -1) {
         $catsrch = " (";
         foreach ($cat as $category) {
             if ($category != -1) {
                 $categ = new Category();
                 if ($categ->isParent($category)) {
                     $children = $categ->getChildren($category);
                     $chlist = "-99";
                     foreach ($children as $child) {
                         $chlist .= ", " . $child["id"];
                     }
                     if ($chlist != "-99") {
                         $catsrch .= " r.categoryid in (" . $chlist . ") or ";
                     }
                 } else {
                     $catsrch .= sprintf(" r.categoryid = %d or ", $category);
                 }
             }
         }
         $catsrch .= "1=2 )";
     }
     if ($maxage > 0) {
         $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage);
     } else {
         $maxage = "";
     }
     $exccatlist = "";
     if (count($excludedcats) > 0) {
         $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")";
     }
     $sql = sprintf("select count(r.id) as num from releases r inner join consoleinfo con on con.id = r.consoleinfoid and con.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist);
     $res = $this->pdo->queryOneRow($sql, true);
     return $res["num"];
 }
Exemplo n.º 18
0
    /**
     * Returns unix time for an article number.
     *
     * @param int    $post      The article number to get the time from.
     * @param array  $groupData Usenet group info from NNTP selectGroup method.
     *
     * @return bool|int
     */
    public function postdate($post, array $groupData)
    {
        // Set table names
        $groupID = $this->_groups->getIDByName($groupData['group']);
        $group = [];
        if ($groupID !== '') {
            $group = $this->_groups->getCBPTableNames($this->_tablePerGroup, $groupID);
        }
        $currentPost = $post;
        $attempts = $date = 0;
        do {
            // Try to get the article date locally first.
            if ($groupID !== '') {
                // Try to get locally.
                $local = $this->_pdo->queryOneRow(sprintf('
						SELECT b.date AS date
						FROM %s b, %s p
						WHERE b.id = p.binaryid
						AND b.groupid = %s
						AND p.number = %s LIMIT 1', $group['bname'], $group['pname'], $groupID, $currentPost));
                if ($local !== false) {
                    $date = $local['date'];
                    break;
                }
            }
            // If we could not find it locally, try usenet.
            $header = $this->_nntp->getXOVER($currentPost);
            if (!$this->_nntp->isError($header)) {
                // Check if the date is set.
                if (isset($header[0]['Date']) && strlen($header[0]['Date']) > 0) {
                    $date = $header[0]['Date'];
                    break;
                }
            }
            // Try to get a different article number.
            if (abs($currentPost - $groupData['first']) > abs($groupData['last'] - $currentPost)) {
                $tempPost = round($currentPost / (mt_rand(1005, 1012) / 1000), 0, PHP_ROUND_HALF_UP);
                if ($tempPost < $groupData['first']) {
                    $tempPost = $groupData['first'];
                }
            } else {
                $tempPost = round(mt_rand(1005, 1012) / 1000 * $currentPost, 0, PHP_ROUND_HALF_UP);
                if ($tempPost > $groupData['last']) {
                    $tempPost = $groupData['last'];
                }
            }
            // If we got the same article number as last time, give up.
            if ($tempPost === $currentPost) {
                break;
            }
            $currentPost = $tempPost;
            if ($this->_debug) {
                $this->_colorCLI->doEcho($this->_colorCLI->debug('Postdate retried ' . $attempts . " time(s)."));
            }
        } while ($attempts++ <= 20);
        // If we didn't get a date, set it to now.
        if (!$date) {
            $date = time();
        } else {
            $date = strtotime($date);
        }
        if ($this->_debug) {
            $this->_debugging->log('Binaries', "postdate", 'Article (' . $post . "'s) date is (" . $date . ') (' . $this->daysOld($date) . " days old)", \Logger::LOG_INFO);
        }
        return $date;
    }
Exemplo n.º 19
0
 /**
  *
  */
 public function processReleases()
 {
     $results = $this->pdo->queryDirect(sprintf("SELECT id, searchname, rageid, anidbid, seriesfull, season, episode, tvtitle FROM releases WHERE episodeinfoid IS NULL AND categoryid IN ( SELECT id FROM category WHERE parentid = %d ) LIMIT 150", Category::CAT_PARENT_TV));
     if ($this->pdo->getNumRows($results) > 0) {
         if ($this->echooutput) {
             echo "TheTVDB : Looking up last " . $this->pdo->getNumRows($results) . " releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($results)) {
             unset($TheTVDBAPIArray, $episodeArray, $fullep, $epabsolute, $additionalSql);
             $seriesName = '';
             if ($arr['rageid'] > 0) {
                 $seriesName = $this->pdo->queryOneRow(sprintf('SELECT releasetitle AS seriesName FROM tvrage WHERE rageid = %d', $arr['rageid']));
             } elseif ($arr['anidbid'] > 0) {
                 $seriesName = $this->pdo->queryOneRow(sprintf('SELECT title AS seriesName FROM anidb WHERE anidbid = %d', $arr['anidbid']));
             }
             if (empty($seriesName) || !$seriesName) {
                 $this->notFound($seriesName, "", $arr['id'], false);
                 continue;
             }
             $seriesName = str_replace('`', '\'', $seriesName['seriesName']);
             if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $arr['seriesfull'])) {
                 $fullep = str_pad(str_replace('S', '', $arr['season']), 2, '0', STR_PAD_LEFT) . 'x' . str_pad(str_replace('E', '', $arr['episode']), 2, '0', STR_PAD_LEFT);
             } else {
                 $fullep = str_replace('/', '-', $arr['seriesfull']);
             }
             $TheTVDBAPIArray = $this->getSeriesInfoByName($seriesName);
             if (!$TheTVDBAPIArray) {
                 $seriesid = $this->lookupSeriesID($seriesName);
                 if ($seriesid > 0) {
                     $TheTVDBAPIArray = $this->TheTVDBAPI($seriesid, $seriesName);
                     if ($TheTVDBAPIArray) {
                         $this->addSeries($TheTVDBAPIArray);
                         $this->addEpisodes($TheTVDBAPIArray);
                     } else {
                         $this->addEmptySeries($seriesName);
                         $this->notFound($seriesName, $fullep, $arr['id']);
                         continue;
                     }
                 } else {
                     $this->addEmptySeries($seriesName);
                     $this->notFound($seriesName, $fullep, $arr['id']);
                     continue;
                 }
             } else {
                 if ($TheTVDBAPIArray['tvdbid'] > 0 && time() - strtotime($TheTVDBAPIArray['createddate']) > 604800) {
                     $TheTVDBAPIArray = $this->TheTVDBAPI($TheTVDBAPIArray['tvdbid'], $seriesName);
                     $this->updateSeries($TheTVDBAPIArray['tvdbid'], $TheTVDBAPIArray['actors'], $TheTVDBAPIArray['airsday'], $TheTVDBAPIArray['airstime'], $TheTVDBAPIArray['contentrating'], $TheTVDBAPIArray['firstaired'], $TheTVDBAPIArray['genre'], $TheTVDBAPIArray['imdbid'], $TheTVDBAPIArray['network'], $TheTVDBAPIArray['overview'], $TheTVDBAPIArray['rating'], $TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $TheTVDBAPIArray['seriesname'], $TheTVDBAPIArray['status']);
                     $this->addEpisodes($TheTVDBAPIArray);
                 }
             }
             if ($TheTVDBAPIArray['tvdbid'] > 0) {
                 $epabsolute = '0';
                 if ($arr['anidbid'] > 0) {
                     if (preg_match('/S(?P<season>\\d+)[ED](?P<episode>\\d+)/', $arr['episode'], $seasonEpisode)) {
                         $arr['season'] = $seasonEpisode['season'];
                         $arr['episode'] = $seasonEpisode['episode'];
                     } else {
                         $epabsolute = $arr['episode'];
                     }
                 }
                 $Episode = new Episode();
                 $episodeArray = $Episode->getEpisodeInfoByName($seriesName, $fullep, (string) $epabsolute);
                 if (!$episodeArray) {
                     $this->notFound($seriesName, $fullep, $arr['id']);
                     continue;
                 }
             } else {
                 $this->notFound($seriesName, $fullep, $arr['id']);
                 continue;
             }
             $additionalSql = '';
             if ($arr['anidbid'] > 0 && $episodeArray['epabsolute'] > 0) {
                 $additionalSql = sprintf(', season = NULL, episode = %d, tvtitle = %s, tvairdate = %s', $episodeArray['epabsolute'], $this->pdo->escapeString($episodeArray['epabsolute'] . ' - ' . str_replace('\'', '`', $episodeArray['eptitle'])), $this->pdo->escapeString($episodeArray['airdate']));
             }
             $this->pdo->queryExec(sprintf('UPDATE releases SET tvdbid = %d, episodeinfoid = %d %s WHERE id = %d', $TheTVDBAPIArray['tvdbid'], $episodeArray['id'], $additionalSql, $arr['id']));
             if ($this->echooutput) {
                 echo 'TheTVDB : ' . $seriesName . ' ' . $fullep . " returned " . $episodeArray['tvdbid'] . "\n";
             }
         }
     }
 }
Exemplo n.º 20
0
 /**
  * Performing parsing.
  */
 public function process()
 {
     // Default query for both full db and last 4 hours.
     $sql = "SELECT r.searchname, r.name, r.fromname, r.id as rid, r.categoryid, r.guid, r.postdate,\n\t\t\t   rn.id as nfoid,\n\t\t\t   g.name as groupname,\n\t\t\t   GROUP_CONCAT(rf.name) as filenames\n\t\tFROM releases r\n\t\tLEFT JOIN releasenfo rn ON (rn.releaseid = r.id)\n\t\tLEFT JOIN groups g ON (g.id = r.groupid)\n\t\tLEFT JOIN releasefiles rf ON (rf.releaseid = r.id)\n\t\tWHERE r.categoryid in (' . Category::CAT_TV_OTHER . ',' . Category::CAT_MOVIE_OTHER . ',' . Category::CAT_MISC_OTHER . ',' . Category::CAT_XXX_OTHER . ')\n\t\t%s\n\t\tGROUP BY r.id";
     $res = $this->pdo->query(sprintf($sql, $this->limited ? "AND r.adddate BETWEEN NOW() - INTERVAL 4 HOUR AND NOW()" : ""));
     $this->releasestocheck = sizeof($res);
     if ($res) {
         echo "PostPrc : Parsing last " . $this->releasestocheck . " releases in the Other-Misc categories\n";
         foreach ($res as $rel) {
             $tempname = $foundName = $methodused = '';
             //Knoc.One
             if (preg_match("/KNOC.ONE/i", $rel['name'])) {
                 $title = '';
                 $items = preg_split("/(\\.| )/", $rel['name']);
                 foreach ($items as $value) {
                     if (preg_match("/^[a-z]+\$/i", $value)) {
                         $len = strlen($value);
                         if ($len > 2) {
                             $title .= substr($value, -2) . substr($value, 0, -2) . " ";
                         } elseif ($len = 2) {
                             $title .= substr($value, -1) . substr($value, 0, -1) . " ";
                         } else {
                             $title .= $value . " ";
                         }
                     } else {
                         $title .= $value . " ";
                     }
                 }
                 $foundName = $title;
                 $methodused = "Knoc.One";
                 $this->determineCategory($rel, $foundName, $methodused);
             }
             ///
             ///Use the Nfo to try to get the proper Releasename.
             ///
             $nfo = $this->pdo->queryOneRow(sprintf("select uncompress(nfo) as nfo from releasenfo where releaseid = %d", $rel['rid']));
             if ($nfo && $foundName == "") {
                 $this->nfosprocessed++;
                 $nfo = $nfo['nfo'];
                 //LOUNGE releases
                 if (preg_match('/([a-z0-9.]+\\.MBLURAY)/i', $nfo, $matches)) {
                     $foundName = $matches[1];
                     $methodused = "LOUNGE";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //AsianDVDClub releases
                 if (preg_match('/adc-[a-z0-9]{1,10}/', $rel['name'])) {
                     if (preg_match('/.*\\(\\d{4}\\).*/i', $nfo, $matches)) {
                         $foundName = $matches[0];
                         $methodused = "AsianDVDClub";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                 }
                 //ACOUSTiC  releases
                 if (preg_match('/ACOUSTiC presents \\.\\.\\..*?([a-z0-9].*?\\(.*?\\))/is', $nfo, $matches)) {
                     $foundName = $matches[1] . ".MBLURAY";
                     $methodused = "ACOUSTiC ";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //Japhson  releases
                 if (preg_match('/Japhson/i', $nfo, $matches)) {
                     $movie = new Movie();
                     $imdbID = null;
                     if (preg_match('/tt(\\d{7})/i', $nfo, $matches)) {
                         $imdbId = $matches[1];
                         $movCheck = $movie->fetchImdbProperties($imdbId);
                         $foundName = $movCheck['title'];
                         if (!preg_match('/(19|20)\\d{2}/i', $foundName)) {
                             $foundName = $foundName . "." . $movCheck['year'];
                         }
                         if (preg_match('/language.*?\\b([a-z0-9]+)\\b/i', $nfo, $matches)) {
                             if (!preg_match('/English/i', $matches[1])) {
                                 $foundName = $foundName . "." . $matches[1];
                             }
                         }
                         if (preg_match('/audio.*?\\b(\\w+)\\b/i', $nfo, $matches)) {
                             if (preg_match('/(Chinese|German|Dutch|Spanish|Hebrew|Finnish|Norwegian)/i', $matches[1])) {
                                 $foundName = $foundName . "." . $matches[1];
                             }
                         }
                         if (preg_match('/(video|resolution|video res).*?(1080|720|816|820|272|1280 @|528|1920)/i', $nfo, $matches)) {
                             if ($matches[2] == '1280 @') {
                                 $matches[2] = '720';
                             }
                             if ($matches[2] == '1920') {
                                 $matches[2] = '1080';
                             }
                             $foundName = $foundName . "." . $matches[2];
                         }
                         if (preg_match('/source.*?\\b(DVD9|DVD5|BDRIP|DVD\\-?RIP|BLURAY)\\b/i', $nfo, $matches)) {
                             $foundName = $foundName . "." . $matches[1];
                         }
                         if (preg_match('/(video|resolution|video res).*?(XVID|X264|WMV)/i', $nfo, $matches)) {
                             $foundName = $foundName . "." . $matches[2];
                         }
                         if (preg_match('/audio.*?\\b(DTS|AC3)\\b/i', $nfo, $matches)) {
                             $foundName = $foundName . "." . $matches[1];
                         }
                         $foundName = $foundName . "-Japhson";
                         $methodused = "Japhson";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                 }
                 //AIHD  releases
                 if (preg_match('/ALWAYS iN HiGH/i', $nfo, $matches)) {
                     $movie = new Movie();
                     $imdbID = null;
                     if (preg_match('/tt(\\d{7})/i', $nfo, $matches)) {
                         $imdbId = $matches[1];
                         $movCheck = $movie->fetchImdbProperties($imdbId);
                         $foundName = $movCheck['title'];
                         if (!preg_match('/(19|20)\\d{2}/i', $foundName)) {
                             $foundName = $foundName . "." . $movCheck['year'];
                         }
                         if (preg_match('/L\\.([a-z0-9]+)\\b/i', $nfo, $matches)) {
                             if (!preg_match('/En/i', $matches[1])) {
                                 $foundName = $foundName . "." . $matches[1];
                             }
                         }
                         if (preg_match('/(V).*?(1080|720|816|820|272|1280 @|528|1920)/i', $nfo, $matches)) {
                             if ($matches[2] == '1280 @') {
                                 $matches[2] = '720';
                             }
                             if ($matches[2] == '1920') {
                                 $matches[2] = '1080';
                             }
                             $foundName = $foundName . "." . $matches[2];
                         }
                         if (preg_match('/V.*?\\b(DVD9|DVD5|BDRIP|DVD\\-?RIP|BLURAY)\\b/i', $nfo, $matches)) {
                             $foundName = $foundName . "." . $matches[1];
                         }
                         if (preg_match('/(V).*?(XVID|X264|WMV)/i', $nfo, $matches)) {
                             $foundName = $foundName . "." . $matches[2];
                         }
                         if (preg_match('/A.*?\\b(DTS|AC3)\\b/i', $nfo, $matches)) {
                             $foundName = $foundName . "." . $matches[1];
                         }
                         $foundName = $foundName . "-AIHD";
                         $methodused = "AIHD";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                 }
                 //IMAGiNE releases
                 if (preg_match('/\\*\\s+([a-z0-9]+(?:\\.|_| )[a-z0-9\\.\\_\\- ]+ \\- imagine)\\s+\\*/i', $nfo, $matches)) {
                     $foundName = $matches[1];
                     $methodused = "imagine";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //LEGION releases
                 if (preg_match('/([a-z0-9 \\.\\-]+LEGi0N)/is', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "Legion";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //SWAGGER releases
                 if (preg_match('/(S  W  A  G  G  E  R|swg.*?nfo)/i', $nfo) && $foundName == "") {
                     if (preg_match('/presents.*?([a-z0-9].*?\\((19|20)\\d{2}\\))/is', $nfo, $matches)) {
                         $foundName = $matches[1];
                     }
                     if (preg_match('/language.*?\\b([a-z0-9]+)\\b/i', $nfo, $matches)) {
                         if ($matches[1] != "english") {
                             $foundName = $foundName . "." . $matches[1];
                         }
                     }
                     if (preg_match('/resolution.*?(1080|720)/i', $nfo, $matches)) {
                         $foundName = $foundName . ".BluRay." . $matches[1];
                     }
                     if (preg_match('/video.*?\\b([a-z0-9]+)\\b/i', $nfo, $matches)) {
                         $foundName = $foundName . "." . $matches[1];
                     }
                     if (preg_match('/audio.*?\\b([a-z0-9]+)\\b/i', $nfo, $matches)) {
                         $foundName = $foundName . "." . $matches[1];
                     }
                     $foundName = $foundName . "-SWAGGER";
                     $methodused = "SWAGGER";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //cm8 releases
                 if (preg_match('/([a-z0-9]+(?:\\.|_| )[a-z0-9\\.\\_\\- \'\\)\\(]+\\-(futv|crimson|qcf|runner|clue|ftp|episode|momentum|PFA|topaz|vision|tdp|haggis|nogrp|shirk|imagine|santi|sys|deimos|ltu|ficodvdr|cm8|dvdr|Nodlabs|aaf|sprinter|exvid|flawl3ss|rx|magicbox|done|unveil))\\b/i', $nfo, $matches) && $foundName == "") {
                     //echo "this: ".$matches[1]."\n";
                     $foundName = $matches[1];
                     $methodused = "cm8";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //river
                 if (preg_match('/([a-z0-9\\.\\_\\-]+\\-(webios|river|w4f|sometv|ngchd|C4|gf|bov|26k|ftw))\\b/i', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "river-1";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 if (preg_match('/([a-z0-9]+(?:\\.|_| )[a-z0-9\\.\\_\\- \'\\)\\(]+\\-(CiA|Anarchy|RemixHD|FTW|Revott|WAF|CtrlHD|Telly|Nif|Line|NPW|Rude|EbP|CRisC|SHK|AssAss1ns|Leverage|BBW|NPW))\\b/i', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "river-2";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 if (preg_match('/([a-z0-9]+(?:\\.|_| )[a-z0-9\\.\\_\\- \'\\)\\(]+\\-(XPD|RHyTM))\\b/i', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "river-3";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 if (preg_match('/(-PROD$|-BOV$|-NMR$|$-HAGGiS|-JUST$|CRNTV$|-MCA$|int$|-DEiTY$|-VoMiT$|-iNCiTE$|-BRUTUS$|-DCN$|-saints$|-sfm$|-lol$|-fov$|-logies$|-c4tv$|-fqm$|-jetset$|-ils$|-miragetv$|-gfvid$|-btl$|-terra$)/i', $rel['searchname']) && $foundName == "") {
                     $foundName = $rel['searchname'];
                     $methodused = "river-4";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //SANTi releases
                 if (preg_match('/\\b([a-z0-9]+(?:\\.|_| )[a-z0-9\\.\\_\\- \']+\\-santi)\\b/i', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "SANTi";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //INSPiRAL releases
                 if (preg_match('/^([a-z0-9]+(?:\\.|_| )[a-z0-9\\.\\_\\- ]+ \\- INSPiRAL)\\s+/im', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "INSPiRAL";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //CIA releases
                 if (preg_match('/Release NAME.*?\\:.*?([a-z0-9][a-z0-9\\.\\ ]+)\\b.*?([a-z0-9][a-z0-9\\.\\ ]+\\-CIA)\\b/is', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1] . $matches[2];
                     $methodused = "CIA";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //HDChina releases
                 if (preg_match('/HDChina/', $nfo) && $foundName == "") {
                     if (preg_match('/Disc Title\\:.*?\\b([a-z0-9\\ \\.\\-\\_()]+\\-HDChina)/i', $nfo, $matches)) {
                         $foundName = $matches[1];
                         $methodused = "HDChina";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                 }
                 //Pringles
                 if (preg_match('/PRiNGLES/', $nfo) && $foundName == "") {
                     if (preg_match('/is giving you.*?\\b([a-z0-9 ]+)\\s/i', $nfo, $matches)) {
                         $foundName = $matches[1];
                         $foundName = rtrim($foundName);
                         $foundName = ltrim($foundName);
                     }
                     if (preg_match('/this release.*?((19|20)\\d{2})/i', $nfo, $matches)) {
                         $foundName = $foundName . "." . $matches[1];
                         $foundName = rtrim($foundName);
                     }
                     if (preg_match('/\\[x\\] (Danish|Norwegian|Swedish|Finish|Other)/i', $nfo, $matches)) {
                         $foundName = $foundName . "." . $matches[1];
                     }
                     if (preg_match('/\\[x\\] (DVD9|DVD5)/i', $nfo, $matches)) {
                         $foundName = $foundName . "." . $matches[1];
                     }
                     $foundName = $foundName . "-PRiNGLES";
                     $methodused = "Pringles";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //Fairlight releases
                 if (preg_match('/\\/Team FairLight/', $nfo) && $foundName == "") {
                     $title = null;
                     $os = null;
                     $method = null;
                     if (preg_match('/\\b([a-z0-9\\ \\- \\_()\\.]+) \\(c\\)/i', $nfo, $matches)) {
                         $title = $matches['1'];
                         $foundName = $title;
                     }
                     $foundName = $foundName . "-FLT";
                     $methodused = "FairLight";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //CORE releases
                 if (preg_match('/Supplied.*?\\:.*?(CORE)/', $nfo) || preg_match('/Packaged.*?\\:.*?(CORE)/', $nfo) && $foundName == "") {
                     $title = null;
                     $os = null;
                     $method = null;
                     if (preg_match('/\\b([a-z0-9\\.\\-\\_\\+\\ ]+) \\*[a-z0-9]+\\*/i', $nfo, $matches)) {
                         $title = $matches['1'];
                         $foundName = $title;
                     }
                     if (preg_match('/Crack\\/.*?\\:.*?([a-z]+)/i', $nfo, $matches)) {
                         $method = $matches['1'];
                         $foundName = $foundName . " " . $method;
                     }
                     if (preg_match('/OS.*?\\:.*?([a-z]+)/i', $nfo, $matches)) {
                         $os = $matches['1'];
                         $foundName = $foundName . " " . $os;
                     }
                     $foundName = $foundName . "-CORE";
                     $methodused = "CORE";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //CompleteRelease
                 if (preg_match('/Complete name.*?([a-z0-9].*?\\-[a-z0-9]+)\\b/i', $nfo, $matches) && $foundName == "") {
                     $foundName = $matches[1];
                     $methodused = "CompleteRelease";
                     $this->determineCategory($rel, $foundName, $methodused);
                 }
                 //Livesets
                 if (preg_match('/\\nLivesets.*?\\n.*?\\n.*?\\n.*?\\n.*?\\n(?P<name>\\w.*?)\\n(?P<album>\\w.*?)\\n/im', $nfo, $matches) && $foundName == "") {
                     $artist = $matches['name'];
                     $title = $matches['album'];
                     $source = null;
                     $year = null;
                     if (preg_match('/Year.*?\\:{1,2} ?(?P<year>(19|20)\\d{2})/i', $nfo, $matches)) {
                         $year = $matches[1];
                     } elseif (preg_match('/date.*?\\:.*?(?P<year>(19|20)\\d{2})/i', $nfo, $matches)) {
                         $year = $matches[1];
                     }
                     if (preg_match('/(web|cable|sat)/i', $title)) {
                         $source = "";
                     } elseif (preg_match('/Source.*?\\:{1,2} ?(?P<source>.*?)(\\s{2,}|\\s{1,})/i', $nfo, $matches)) {
                         $source = $matches[1];
                         if ($source == "Satellite") {
                             $source = "Sat";
                         }
                     }
                     if ($artist) {
                         $tempname = $artist;
                         if ($title) {
                             $tempname = $tempname . "-" . $title;
                         }
                         if ($source) {
                             $tempname = $tempname . "-" . $source;
                         }
                         if ($year) {
                             $tempname = $tempname . "-" . $year;
                         }
                         $tempname = preg_replace("/[^a-zA-Z,0-9,\\-,\\s]/", "", $tempname);
                         $foundName = $tempname;
                         $methodused = "Live Sets";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                 }
                 //Typical scene regex
                 if (preg_match('/(?P<source>Source[\\s\\.]*?:|fix for nuke)?(?:\\s|\\]|\\[)?(?P<name>[a-z0-9\'\\-]+(?:\\.|_)[a-z0-9\\.\\-_\'&]+\\-[a-z0-9&]+)(?:\\s|\\[|\\])/i', $nfo, $matches) && $foundName == "") {
                     if (empty($matches['source'])) {
                         if (!preg_match('/usenet\\-space/i', $matches['name'])) {
                             $foundName = $matches['name'];
                             $methodused = "Scene";
                             $this->determineCategory($rel, $foundName, $methodused);
                         }
                     }
                 }
             }
             //The Big One
             if (preg_match_all('/([a-z0-9\\ ]+)\\.{1,}(\\:|\\[)(?P<name>.*)(\\s{2}|\\s{1})/i', $nfo, $matches) && $foundName == "") {
                 $lut = array();
                 foreach ($matches[1] as $key => $k) {
                     $lut[str_replace(' ', '', strtolower(trim($k)))] = trim($matches[3][$key]);
                 }
                 $year = null;
                 $vidsource = null;
                 $series = null;
                 $season = null;
                 $episode = null;
                 $language = null;
                 $artist = null;
                 $source = null;
                 foreach ($lut as $k => $v) {
                     $v = rtrim($v);
                     if (!$year && preg_match('/((19|20)\\d{2})/', $v, $matches)) {
                         $year = $matches[1];
                     }
                     if (!$vidsource && preg_match('/(xvid|x264|h264|wmv|divx)/i', $v, $matches)) {
                         $vidsource = $matches[1];
                     }
                     if (!$season && preg_match('/(season|seizon).*?(\\d{1,3})/i', $v, $matches)) {
                         $season = $matches[2];
                     }
                     if (!$episode && preg_match('/(Episode|ep).*?(\\d{1,3})/i', $v, $matches)) {
                         $episode = $matches[2];
                     }
                 }
                 if (isset($lut['artist'])) {
                     $del = "-";
                     if (isset($lut['artist'])) {
                         $lut['artist'] = trim($lut['artist'], " ");
                         $tempname = $lut['artist'];
                     }
                     if (isset($lut['title'])) {
                         $tempname = $tempname . $del . $lut['title'];
                     }
                     if (isset($lut['album']) && !isset($lut['title'])) {
                         $tempname = $tempname . $del . $lut['album'];
                     }
                     if (isset($lut['track']) && !isset($lut['title']) && !isset($lut['album'])) {
                         $tempname = $tempname . $del . $lut['track'];
                     }
                     if (!isset($lut['source'])) {
                         $lut['source'] = 'WEB';
                     }
                     if (isset($lut['source']) && !preg_match('/SAT/i', $tempname)) {
                         $tempname = $tempname . $del . $lut['source'];
                     }
                     if (!preg_match('/(19|20)\\d{2}/', $tempname) && $year) {
                         $tempname = $tempname . $del . $year;
                     }
                     if (isset($lut['ripper'])) {
                         $tempname = $tempname . $del . $lut['ripper'];
                     }
                     $tempname = preg_replace("/[^a-zA-Z,0-9,\\-,\\&,\\s]/", "", $tempname);
                     $tempname = preg_replace("/[ ]{2,}/", "", $tempname);
                     $methodused = "The Big One Music";
                     $foundName = $tempname;
                     $this->determineCategory($rel, $foundName, $methodused);
                 } else {
                     if (isset($lut['title'])) {
                         $del = " ";
                         if (isset($lut['series'])) {
                             $tempname = $lut['series'];
                         }
                         $tempname = $tempname . $del . $lut['title'];
                         if ($season && $episode) {
                             $tempname = $tempname . $del . "S" . str_pad($season, 2, '0', STR_PAD_LEFT) . 'E' . str_pad($episode, 2, '0', STR_PAD_LEFT);
                         } else {
                             if ($season) {
                                 $tempname = $tempname . $del . "S" . $season;
                             }
                             if ($episode) {
                                 $tempname = $tempname . $del . "Ep" . $episode;
                             }
                         }
                         if (isset($lut['source']) && !preg_match('/SAT/i', $lut['title'])) {
                             $tempname = $tempname . $del . $lut['source'];
                         }
                         if (!preg_match('/(19|20)\\d{2}/', $tempname) && $year) {
                             $tempname = $tempname . $del . $year;
                         }
                         if (isset($lut['language'])) {
                             $tempname = $tempname . $del . $lut['language'];
                         }
                         if ($vidsource) {
                             $tempname = $tempname . $del . $vidsource;
                         }
                         $tempname = preg_replace("/ /", " ", $tempname);
                         $tempname = preg_replace("/[^a-zA-Z,0-9,\\-,\\&,\\s]/", " ", $tempname);
                         $tempname = preg_replace("/[ ]+/", " ", $tempname);
                         $methodused = "The Big One Other";
                         $foundName = $tempname;
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                 }
             }
             ///
             ///unable to extract releasename from nfo, try the rar file
             ///
             if ($rel['filenames'] && $foundName == '') {
                 $this->releasefilesprocessed++;
                 $files = explode(',', $rel['filenames']);
                 if (![$files]) {
                     $files = [$files];
                 }
                 // Scene regex
                 $sceneRegex = '/([a-z0-9\'\\-\\.\\_\\(\\)\\+\\ ]+\\-[a-z0-9\'\\-\\.\\_\\(\\)\\ ]+)(.*?\\\\.*?|)\\.(?:\\w{3,4})$/i';
                 foreach ($files as $file) {
                     // Petje Releases
                     if (preg_match('/Petje \\<petje\\@pietamientje\\.com\\>/', $rel['fromname'], $matches3) && $foundName == '') {
                         if (preg_match('/.*\\.(mkv|avi|mp4|wmv|divx)/', $file, $matches4)) {
                             $array_new = explode('\\', $matches4[0]);
                             foreach ($array_new as $item) {
                                 if (preg_match('/.*\\((19|20\\d{2})\\)$/', $item, $matched)) {
                                     //echo $matched[0].".720p.x264-Petje";
                                     //print_r($matched);
                                     $foundName = $matched[0] . ".720p.x264-Petje";
                                     $methodused = "Petje";
                                     $this->determineCategory($rel, $foundName, $methodused);
                                     break 2;
                                 }
                             }
                         }
                     }
                     //3D Remux
                     if (preg_match('/.*Remux\\.mkv/', $file, $matches4)) {
                         $foundName = str_replace(".mkv", "", $matches4[0]);
                         $methodused = "3D Remux";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     //QoQ Extended
                     if (preg_match('/Q\\-sbuSLN.*/i', $file, $matches4)) {
                         $new1 = preg_match('/( )?(\\.wmv|\\.divx|\\.avi|\\.mkv)/i', $matches4[0], $matched);
                         $new2 = str_replace($matched[0], "", $matches4[0]);
                         $foundName = strrev($new2);
                         $methodused = "QoQ Extended";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     // Directory\Title.Year.Format.Group.mkv
                     if (preg_match('/(?<=\\\\).*?BLURAY.(1080|720)P.*?KNORLOADING(?=\\.MKV)/i', $file, $matches3) && $foundName == '') {
                         $foundName = $matches3['0'];
                         $methodused = "a.b.hdtv.x264";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     // ReleaseGroup.Title.Format.mkv
                     if (preg_match('/(?<=swg_|swghd\\-|lost\\-|veto\\-|kaka\\-|abd\\-|airline\\-|daa\\-|data\\-|japhson\\-|ika\\-|lng\\-|nrdhd\\-|saimorny\\-|sparks\\-|ulshd\\-|nscrns\\-|ifpd\\-|invan\\-|an0\\-|besthd\\-|muxhd\\-|s7\\-).*?((1080|720)|P)(?=\\.MKV)/i', $file, $matches3) && $foundName == '') {
                         $foundName = str_replace("_", ".", $matches3['0']);
                         $methodused = "a.b.hdtv.x264";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     // Title.Format.ReleaseGroup.mkv
                     if (preg_match('/.*?(1080|720)(|P).(SON)/i', $file, $matches3) && $foundName == '') {
                         $foundName = str_replace("_", ".", $matches3['0']);
                         $methodused = "a.b.hdtv.x264";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     //epubmobi
                     if (preg_match('/.*\\.(epub|mobi|azw3|pdf|prc|lit|rtf|azw|cbr|doc)/', $file, $matches4)) {
                         $foundName = str_replace(".doc", "", str_replace(".cbr", "", str_replace(".prc", "", str_replace(".pdf", "", str_replace(".azw3", "", str_replace(".mobi", "", str_replace(".epub", "", str_replace(".rtf", "", str_replace(".azw", "", str_replace(".lit", "", $matches4[0]))))))))));
                         $methodused = "EpubMobi";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     //Reversed name
                     if (preg_match('/[a-z0-9\\(\\)\'\\!\\,\\.\\-\\ \\_]+(BEW|p027|p0801)[a-z0-9\\(\\)\\,\'\\!\\ \\-\\.]+/i', $file, $matches4)) {
                         $new1 = preg_match('/( )?(\\.m2ts|\\.wmv|\\.avi|.mp4|\\.mkv)/i', $matches4[0], $matched);
                         $new2 = str_replace($matched[0], "", $matches4[0]);
                         $foundName = strrev($new2);
                         $methodused = "Reversed";
                         $this->determineCategory($rel, $foundName, $methodused);
                     }
                     //Check rarfile contents for a scene name
                     if (preg_match($sceneRegex, $file, $matches) && $foundName == '') {
                         //Simply Releases Toppers
                         if (preg_match('/(\\\\)(?P<name>.*?ReleaseS Toppers)/', $file, $matches1) && $foundName == '') {
                             $foundName = $matches1['name'];
                             $methodused = "Release Files-1";
                             $this->determineCategory($rel, $foundName, $methodused);
                         }
                         //Scene format no folder.
                         if (preg_match('/^([a-z0-9\\.\\_\\- ]+\\-[a-z0-9\\_]+)(\\\\|)$/i', $matches[1]) && $foundName == '') {
                             if (strlen($matches['1']) >= 15) {
                                 $foundName = $matches['1'];
                                 $methodused = "Scene format no folder.";
                                 $this->determineCategory($rel, $foundName, $methodused);
                             }
                         }
                         //Check to see if file is inside of a folder. Use folder name if it is
                         if (preg_match('/^(.*?\\\\)(.*?\\\\|)(.*?)$/i', $file, $matches1) && $foundName == '') {
                             if (preg_match('/^([a-z0-9\\.\\_\\- ]+\\-[a-z0-9\\_]+)(\\\\|)$/i', $matches1['1'], $res)) {
                                 $foundName = $res['1'];
                                 $methodused = "Release Files-1";
                                 $this->determineCategory($rel, $foundName, $methodused);
                             }
                             if (preg_match('/(?!UTC)([a-z0-9]+[a-z0-9\\.\\_\\- \'\\)\\(]+(\\d{4}|HDTV).*?\\-[a-z0-9]+)/i', $matches1['1'], $res) && $foundName == '') {
                                 $foundName = $res['1'];
                                 $methodused = "Release Files-2";
                                 $this->determineCategory($rel, $foundName, $methodused);
                             }
                             if (preg_match('/^([a-z0-9\\.\\_\\- ]+\\-[a-z0-9\\_]+)(\\\\|)$/i', $matches1['2'], $res) && $foundName == '') {
                                 $foundName = $res['1'];
                                 $methodused = "Release Files-3";
                                 $this->determineCategory($rel, $foundName, $methodused);
                             }
                             if (preg_match('/^([a-z0-9\\.\\_\\- ]+\\-(?:.+)\\(html\\))\\\\/i', $matches1['1'], $res) && $foundName == '') {
                                 $foundName = $res['1'];
                                 $methodused = "Release Files-4";
                                 $this->determineCategory($rel, $foundName, $methodused);
                             }
                         }
                         if (preg_match('/(?!UTC)([a-z0-9]+[a-z0-9\\.\\_\\- \'\\)\\(]+(\\d{4}|HDTV).*?\\-[a-z0-9]+)/i', $file, $matches2) && $foundName == '') {
                             $foundName = $matches2['1'];
                             $methodused = "Release Files-4";
                             $this->determineCategory($rel, $foundName, $methodused);
                         }
                     }
                 }
                 //RAR file contents release name matching
                 /*if (sizeof($files) > 0 && $foundName == '')
                 					{
                 						echo "RAR checking\n";
                 						//Loop through releaseFiles to find a match
                 						foreach($files as $rarFile)
                 						{
                 							//echo "-{$rarFile}\n";
                 							if ($foundName == '')
                 							{
                 								//Lookup name via reqid (filename)
                 								if (preg_match('/\.(avi|mkv|mp4|mov|wmv|iso|img|gcm|ps3|wad|ac3|nds|bin|cue|mdf)/i', $rarFile))
                 								{
                 									$this->pdo->getSetting('reqidurl;
                 									$lookupUrl = 'http://allfilled/query.php?t=alt.binaries.srrdb&reqid='.urlencode(basename($rarFile));
                 									echo '-lookup: '.$lookupUrl."\n";
                 									$xml = Utility::getUrl(['url' => $lookupUrl]);
                 									//$xml = false;
                 
                 									if ($xml !== false)
                 									{
                 										$xmlObj = @simplexml_load_string($xml);
                 										$arrXml = objectsIntoArray($xmlObj);
                 
                 										if (isset($arrXml["item"]) && is_array($arrXml["item"]) && isset($arrXml["item"]["@attributes"]) && is_array($arrXml["item"]["@attributes"]))
                 										{
                 											$foundName = $arrXml["item"]["@attributes"]["title"];
                 										}
                 									}
                 								}
                 							}
                 						}
                 					}*/
             }
             // do par check if user has elected for downloading extra stuff
             if ($this->pdo->getSetting('unrarpath') != '' && $foundName == "") {
                 $nzb = new NZB();
                 $nzbfile = $nzb->getNZBPath($rel['guid']);
                 $nzbInfo = new nzbInfo();
                 $nzbInfo->loadFromFile($nzbfile);
                 if (!empty($nzbInfo->parfiles) && empty($nzbInfo->rarfiles) && empty($nzbInfo->audiofiles)) {
                     $nntp = new NNTP();
                     $nntp->doConnect();
                     if ($this->verbose) {
                         echo "Checking Par\n";
                     }
                     foreach ($nzbInfo->parfiles as $parfile) {
                         $this->parsprocessed++;
                         $parBinary = $nntp->getMessages($parfile['groups'][0], $parfile['segments'], $this->verbose);
                         if ($parBinary) {
                             $par2 = new Par2info();
                             $par2->setData($parBinary);
                             if (!$par2->error) {
                                 $parFiles = $par2->getFileList();
                                 foreach ($parFiles as $file) {
                                     if (isset($file['name']) && (preg_match('/.*part0*1\\.rar$/iS', $file['name'], $matches) || preg_match('/(?!part0*1)\\.rar$/iS', $file['name'], $matches) || preg_match('/\\.001$/iS', $file['name'], $matches))) {
                                         $foundName = preg_replace('/^(.*)(\\.part0*1\\.rar|\\.rar|\\.001)$/i', '\\1', $file['name']);
                                         $methodused = "Par file";
                                         $this->determineCategory($rel, $foundName, $methodused);
                                         break;
                                     }
                                 }
                             }
                         }
                         unset($parBinary);
                         if ($foundName != "") {
                             break;
                         }
                     }
                     $nntp->doQuit();
                 }
             }
             ///
             ///	This is a last ditch effort, build a ReleaseName from the Nfo
             ///
             if ($nfo && ($foundName == "" || $methodused == 'Scene format no folder.')) {
                 //LastNfoAttempt
                 if (preg_match('/tt(\\d{7})/i', $nfo, $matches) && $foundName == "") {
                     $movie = new Movie();
                     $imdbId = $matches[1];
                     $movCheck = $movie->fetchImdbProperties($imdbId);
                     $buffer = Utility::getUrl(['url' => 'http://akas.imdb.com/title/tt' . $imdbId . '/']);
                     if (!preg_match('/content\\=\\"video\\.tv\\_show\\"/i', $buffer)) {
                         if (isset($movCheck['title'])) {
                             $foundName = $movCheck['title'];
                             if (!preg_match('/(19|20)\\d{2}/i', $foundName)) {
                                 $foundName = $foundName . "." . (isset($movCheck['year']) ? $movCheck['year'] : "");
                             }
                             if (preg_match('/language.*?\\b([a-z0-9]+)\\b/i', $nfo, $matches)) {
                                 if (!preg_match('/English/i', $matches[1])) {
                                     $foundName = $foundName . "." . $matches[1];
                                 }
                             }
                             if (preg_match('/audio.*?\\b(\\w+)\\b/i', $nfo, $matches)) {
                                 if (preg_match('/(Chinese|German|Dutch|Spanish|Hebrew|Finnish|Norwegian)/i', $matches[1])) {
                                     $foundName = $foundName . "." . $matches[1];
                                 }
                             }
                             if (preg_match('/(video|resolution|video res).*?(1080|720|816|820|272|1280 @|528|1920)/i', $nfo, $matches)) {
                                 if ($matches[2] == '1280 @') {
                                     $matches[2] = '720';
                                 }
                                 if ($matches[2] == '1920') {
                                     $matches[2] = '1080';
                                 }
                                 $foundName = $foundName . "." . $matches[2];
                             }
                             if (preg_match('/source.*?\\b(DVD9|DVD5|BDRIP|DVD\\-?RIP|BLURAY|BD)\\b/i', $nfo, $matches)) {
                                 if ($matches[1] == 'BD') {
                                     $matches[1] = 'Bluray.x264';
                                 }
                                 $foundName = $foundName . "." . $matches[1];
                             }
                             if (preg_match('/(video|resolution|video res).*?(XVID|X264|WMV)/i', $nfo, $matches)) {
                                 $foundName = $foundName . "." . $matches[2];
                             }
                             if (preg_match('/audio.*?\\b(DTS|AC3)\\b/i', $nfo, $matches)) {
                                 $foundName = $foundName . "." . $matches[1];
                             }
                             $foundName = $foundName . "-NoGroup";
                             $methodused = "LastNfoAttempt";
                             $this->determineCategory($rel, $foundName, $methodused);
                         }
                     }
                 }
             }
             if ($foundName == '' && $this->verbose) {
                 echo "ReleaseID: \t\t" . $rel["rid"] . "\n" . " Group: \t\t" . $rel["groupname"] . "\n" . " Old Name: \t\t" . $rel["name"] . "\n" . " Old SearchName: \t" . $rel["searchname"] . "\n" . " Status: \t\tNo new name found.\n\n";
             }
         }
     }
     if ($this->verbose) {
         echo $this->releasestocheck . " releases checked\n" . $this->nfosprocessed . " of " . $this->releasestocheck . " releases had nfo's processed\n" . $this->parsprocessed . " of " . $this->releasestocheck . " releases had par's processed\n" . $this->releasefilesprocessed . " of " . $this->releasestocheck . " releases had releasefiles processed\n" . $this->numupdated . " of " . $this->releasestocheck . " releases " . ($this->releasestocheck > 0 ? floor($this->numupdated / $this->releasestocheck * 100) . "%" : "") . " changed\n";
     }
 }
Exemplo n.º 21
0
    /**
     * 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.groupid = ' . $groupID;
        $optionsQuery = self::NfoQueryString($this->pdo);
        $res = $this->pdo->query(sprintf('
				SELECT r.id, r.guid, r.groupid, 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]);
            $tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]);
            foreach ($res as $arr) {
                $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['groupid'], $groups->getByNameByID($arr['groupid']));
                if ($fetchedBinary !== false) {
                    // Insert nfo into database.
                    $cp = 'COMPRESS(%s)';
                    $nc = $this->pdo->escapeString($fetchedBinary);
                    $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT id FROM releasenfo WHERE releaseid = %d', $arr['id']));
                    if (!isset($ckreleaseid['id'])) {
                        $this->pdo->queryInsert(sprintf('INSERT INTO releasenfo (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.
                    if ($processTvrage == 1) {
                        $rageId = $this->parseRageId($fetchedBinary);
                        if ($rageId !== 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 %s %s', NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery));
        if ($releases instanceof Traversable) {
            foreach ($releases as $release) {
                $this->pdo->queryExec(sprintf('DELETE FROM releasenfo WHERE nfo IS NULL AND releaseid = %d', $release['id']));
            }
        }
        // Set releases with no NFO.
        $this->pdo->queryExec(sprintf('
				UPDATE releases r
				SET r.nfostatus = %d
				WHERE r.nzbstatus = %d
				AND r.nfostatus < %d %s %s', self::NFO_FAILED, NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery));
        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;
    }
Exemplo n.º 22
0
 /**
  * Return a single PRE for a release.
  *
  * @param int $preID
  *
  * @return array
  */
 public function getOne($preID)
 {
     return $this->pdo->queryOneRow(sprintf('SELECT * FROM prehash WHERE id = %d', $preID));
 }
Exemplo n.º 23
0
function window_sharing($tmux_session)
{
    $pdo = new Settings();
    $sharing = $pdo->queryOneRow('SELECT enabled, posting, fetching FROM sharing');
    $t = new \Tmux();
    $tmux = $t->get();
    $tmux_share = isset($tmux->run_sharing) ? $tmux->run_sharing : 0;
    if ($tmux_share && $sharing['enabled'] == 1 && ($sharing['posting'] == 1 || $sharing['fetching'] == 1)) {
        exec("tmux new-window -t {$tmux_session} -n Sharing 'printf \"]2;comment_sharing\"'");
    }
}
Exemplo n.º 24
0
 public function getSourceById($id)
 {
     $db = new Settings();
     $sql = sprintf("SELECT * FROM spotnabsources WHERE id = %d", $id);
     return $db->queryOneRow($sql);
 }
Exemplo n.º 25
0
printf($mask, '=========================', '=======', '==========', '===============', '===============', '===============', '===============');
if ($run instanceof \Traversable) {
    foreach ($run as $table) {
        if ($table['total'] > $argv[1] || $table['free'] > $argv[1]) {
            printf($mask, $table['table'], $table['engine'], str_replace('row_format=', '', $table['format']), number_format($table['data'], 2) . " MB", number_format($table['index'], 2) . " MB", number_format($table['free'], 2) . " MB", number_format($table['total'], 2) . " MB");
        }
        $data += $table['data'];
        $index += $table['index'];
        $free += $table['free'];
        $total += $table['total'];
    }
}
printf($mask, '=========================', '=======', '==========', '===============', '===============', '===============', '===============');
printf($mask, 'Table Name', 'Engine', 'Row_Format', 'Data Size', 'Index Size', 'Free Space', 'Total Size');
printf($mask, '', '', '', number_format($data, 2) . " MB", number_format($index, 2) . " MB", number_format($free, 2) . " MB", number_format($total, 2) . " MB");
$myisam = $pdo->queryOneRow("SELECT CONCAT(ROUND(KBS/POWER(1024,IF(pw<0,0,IF(pw>3,0,pw)))+0.49999), " . "SUBSTR(' KMG',IF(pw<0,0,IF(pw>3,0,pw))+1,1)) recommended_key_buffer_size " . "FROM (SELECT SUM(index_length) KBS " . "FROM information_schema.tables " . "WHERE engine='MyISAM' AND table_schema NOT IN ('information_schema','mysql')) A, (SELECT 3 pw) B;", false);
$innodb = $pdo->queryOneRow("SELECT CONCAT(ROUND(KBS/POWER(1024,IF(pw<0,0,IF(pw>3,0,pw)))+0.49999), " . "SUBSTR(' KMG',IF(pw<0,0,IF(pw>3,0,pw))+1,1)) recommended_innodb_buffer_pool_size " . "FROM (SELECT SUM(index_length) KBS " . "FROM information_schema.tables " . "WHERE engine='InnoDB') A,(SELECT 3 pw) B;", false);
$a = $myisam['recommended_key_buffer_size'];
if ($myisam['recommended_key_buffer_size'] === null) {
    $a = '12M';
}
$b = $innodb['recommended_innodb_buffer_pool_size'];
if ($innodb['recommended_innodb_buffer_pool_size'] === null) {
    $b = '12M';
}
// Get current variables
$aa = $pdo->queryOneRow("SHOW VARIABLES WHERE Variable_name = 'key_buffer_size'", false);
$bb = $pdo->queryOneRow("SHOW VARIABLES WHERE Variable_name = 'innodb_buffer_pool_size'", false);
if ($aa['value'] >= 1073741824) {
    $current_a = $aa['value'] / 1024 / 1024 / 1024;
    $current_a .= "G";
Exemplo n.º 26
0
 /**
  * Get a blacklist row from database.
  */
 public function getBlacklistByID($id)
 {
     $db = new Settings();
     return $db->queryOneRow(sprintf("select * from binaryblacklist where id = %d ", $id));
 }
Exemplo n.º 27
0
 /**
  * Returns the nfo from the database (blob)
  */
 public function getNfo($relid, &$nfoout)
 {
     $db = new Settings();
     // Has NFO Query
     $mnfo = "SELECT uncompress(rn.nfo) as nfo FROM releases r " . "INNER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.id = r.releasenfoid " . "WHERE rn.nfo IS NOT NULL AND r.id = %d LIMIT 1";
     $res = $db->queryOneRow(sprintf($mnfo, $relid));
     if ($res && isset($res['nfo'])) {
         $nfoout = $res['nfo'];
         return true;
     }
     return false;
 }
Exemplo n.º 28
0
 public function getNameByID($ID)
 {
     $db = new newznab\db\Settings();
     $parent = $db->queryOneRow(sprintf("SELECT title FROM category WHERE id = %d", substr($ID, 0, 1) . "000"));
     $cat = $db->queryOneRow(sprintf("SELECT title FROM category WHERE id = %d", $ID));
     return $parent["title"] . " " . $cat["title"];
 }
Exemplo n.º 29
0
    /**
     * Attempt to get a better name from a par2 file and categorize the release.
     *
     * @note Called from NZBContents.php
     *
     * @param string $messageID MessageID from NZB file.
     * @param int    $relID     id of the release.
     * @param int    $groupID   Group id of the release.
     * @param \NNTP   $nntp      Class NNTP
     * @param int    $show      Only show result or apply iy.
     *
     * @return bool
     */
    public function parsePAR2($messageID, $relID, $groupID, &$nntp, $show)
    {
        if ($messageID === '') {
            return false;
        }
        $query = $this->pdo->queryOneRow(sprintf('
				SELECT id, groupid, categoryid, name, searchname, UNIX_TIMESTAMP(postdate) AS post_date, id AS releaseid
				FROM releases
				WHERE isrenamed = 0
				AND id = %d', $relID));
        if ($query === false) {
            return false;
        }
        // Only get a new name if the category is OTHER.
        $foundName = true;
        if (!in_array((int) $query['categoryid'], array(\Category::CAT_BOOK_OTHER, \Category::CAT_GAME_OTHER, \Category::CAT_MOVIE_OTHER, \Category::CAT_MUSIC_OTHER, \Category::CAT_PC_MOBILEOTHER, \Category::CAT_TV_OTHER, \Category::CAT_MISC_HASHED, \Category::CAT_XXX_OTHER, \Category::CAT_MISC_OTHER))) {
            $foundName = false;
        }
        // Get the PAR2 file.
        $par2 = $nntp->getMessages($this->groups->getByNameByID($groupID), $messageID, $this->alternateNNTP);
        if ($nntp->isError($par2)) {
            return false;
        }
        // Put the PAR2 into Par2Info, check if there's an error.
        $this->_par2Info->setData($par2);
        if ($this->_par2Info->error) {
            return false;
        }
        // Get the file list from Par2Info.
        $files = $this->_par2Info->getFileList();
        if ($files !== false && count($files) > 0) {
            $filesAdded = 0;
            // Loop through the files.
            foreach ($files as $file) {
                if (!isset($file['name'])) {
                    continue;
                }
                // If we found a name and added 10 files, stop.
                if ($foundName === true && $filesAdded > 10) {
                    break;
                }
                if ($this->addpar2) {
                    // Add to release files.
                    if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf('
								SELECT id
								FROM releasefiles
								WHERE releaseid = %d
								AND name = %s', $relID, $this->pdo->escapeString($file['name']))) === false) {
                        // Try to add the files to the DB.
                        if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) {
                            $filesAdded++;
                        }
                    }
                } else {
                    $filesAdded++;
                }
                // Try to get a new name.
                if ($foundName === false) {
                    $query['textstring'] = $file['name'];
                    if ($this->nameFixer->checkName($query, 1, 'PAR2, ', 1, $show) === true) {
                        $foundName = true;
                    }
                }
            }
            // If we found some files.
            if ($filesAdded > 0) {
                $this->debugging->log(get_class(), __FUNCTION__, 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO);
                // Update the file count with the new file count + old file count.
                $this->pdo->queryExec(sprintf('
						UPDATE releases
						SET rarinnerfilecount = rarinnerfilecount + %d
						WHERE id = %d', $filesAdded, $relID));
            }
            if ($foundName === true) {
                return true;
            }
        }
        return false;
    }
Exemplo n.º 30
0
<?php

require_once dirname(__FILE__) . "/config.php";
use newznab\db\Settings;
use newznab\processing\PProcess;
$c = new ColorCLI();
if (!isset($argv[1])) {
    exit($c->error("This script is not intended to be run manually, it is called from fixreleasenames_threaded.py."));
} else {
    if (isset($argv[1])) {
        $db = new Settings();
        $namefixer = new \NameFixer(['Settings' => $pdo]);
        $pieces = explode(' ', $argv[1]);
        if (isset($pieces[1]) && $pieces[0] == 'nfo') {
            $release = $pieces[1];
            if ($res = $db->queryOneRow(sprintf('SELECT rel.guid AS guid, nfo.releaseid AS nfoid, rel.groupid, rel.categoryid, rel.name, rel.searchname, uncompress(nfo) AS textstring, rel.id AS releaseid FROM releases rel INNER JOIN releasenfo nfo ON (nfo.releaseid = rel.id) WHERE rel.id = %d', $release))) {
                //ignore encrypted nfos
                if (preg_match('/^=newz\\[NZB\\]=\\w+/', $res['textstring'])) {
                    $namefixer->done = $namefixer->matched = false;
                    $db->queryDirect(sprintf('UPDATE releases SET proc_nfo = 1 WHERE id = %d', $res['releaseid']));
                    $namefixer->checked++;
                    echo '.';
                } else {
                    //echo $res['textstring']."\n";
                    $namefixer->done = $namefixer->matched = false;
                    if ($namefixer->checkName($res, true, 'NFO, ', 1, 1) !== true) {
                        echo '.';
                    }
                    $namefixer->checked++;
                }
            }