示例#1
0
文件: NZBGet.php 项目: Jay204/nZEDb
    /**
     * Send a NZB to NZBGet.
     *
     * @param string $guid Release identifier.
     *
     * @return bool|mixed
     *
     * @access public
     */
    public function sendNZBToNZBGet($guid)
    {
        $relData = $this->Releases->getByGuid($guid);
        $string = nzedb\utility\Utility::unzipGzipFile($this->NZB->getNZBPath($guid));
        $string = $string === false ? '' : $string;
        $header = '<?xml version="1.0"?>
			<methodCall>
				<methodName>append</methodName>
				<params>
					<param>
						<value><string>' . $relData['searchname'] . '</string></value>
					</param>
					<param>
						<value><string>' . $relData['category_name'] . '</string></value>
					</param>
					<param>
						<value><i4>0</i4></value>
					</param>
					<param>
						<value><boolean>>False</boolean></value>
					</param>
					<param>
						<value>
							<string>' . base64_encode($string) . '</string>
						</value>
					</param>
				</params>
			</methodCall>';
        nzedb\utility\getUrl($this->fullURL . 'append', 'post', $header);
    }
示例#2
0
 /**
  * Decompress a NZB, load it into simplexml and return.
  *
  * @param string $guid Release guid.
  *
  * @return bool|SimpleXMLElement
  *
  * @access public
  */
 public function LoadNZB($guid)
 {
     // Fetch the NZB location using the GUID.
     $nzbPath = $this->nzb->getNZBPath($guid);
     if ($nzbPath === false) {
         if ($this->echooutput) {
             echo PHP_EOL . $guid . ' appears to be missing the nzb file, skipping.' . PHP_EOL;
         }
         return false;
     }
     $nzbContents = Utility::unzipGzipFile($nzbPath);
     if (!$nzbContents) {
         if ($this->echooutput) {
             echo PHP_EOL . 'Unable to decompress: ' . $nzbPath . ' - ' . fileperms($nzbPath) . ' - may have bad file permissions, skipping.' . PHP_EOL;
         }
         return false;
     }
     $nzbFile = @simplexml_load_string($nzbContents);
     if (!$nzbFile) {
         if ($this->echooutput) {
             echo PHP_EOL . "Unable to load NZB: {$guid} appears to be an invalid NZB, skipping." . PHP_EOL;
         }
         return false;
     }
     return $nzbFile;
 }
示例#3
0
    /**
     * Create NZB files from complete releases.
     *
     * @param int|string $groupID (optional)
     *
     * @return int
     * @access public
     */
    public function createNZBs($groupID)
    {
        $startTime = time();
        $group = $this->groups->getCBPTableNames($this->tablePerGroup, $groupID);
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create the NZB, delete collections/binaries/parts."));
        }
        $releases = $this->pdo->queryDirect(sprintf("\n\t\t\t\tSELECT CONCAT(COALESCE(cp.title,'') , CASE WHEN cp.title IS NULL THEN '' ELSE ' > ' END , c.title) AS title,\n\t\t\t\t\tr.name, r.id, r.guid\n\t\t\t\tFROM releases r\n\t\t\t\tINNER JOIN category c ON r.categoryid = c.id\n\t\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t\tWHERE %s nzbstatus = 0", !empty($groupID) ? ' r.group_id = ' . $groupID . ' AND ' : ' '));
        $deleted = $nzbCount = 0;
        if ($releases && $releases->rowCount()) {
            $total = $releases->rowCount();
            // Init vars for writing the NZB's.
            $this->nzb->initiateForWrite($groupID);
            foreach ($releases as $release) {
                if ($this->nzb->writeNZBforReleaseId($release['id'], $release['guid'], $release['name'], $release['title']) === true) {
                    $nzbCount++;
                    if ($this->echoCLI) {
                        echo $this->pdo->log->primaryOver("Creating NZBs:\t" . $nzbCount . '/' . $total . "\r");
                    }
                }
            }
        }
        $nzbEnd = time();
        if ($nzbCount > 0) {
            if ($this->echoCLI) {
                $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . 'Deleting collections/binaries/parts, be patient.'));
            }
            $deleteQuery = $this->pdo->queryExec(sprintf('
					DELETE c FROM %s c
					INNER JOIN releases r ON r.id = c.releaseid
					WHERE r.nzbstatus = %d
					AND c.filecheck = %d', $group['cname'], \NZB::NZB_ADDED, self::COLLFC_INSERTED));
            if ($deleteQuery !== false) {
                $deleted = $deleteQuery->rowCount();
            }
        }
        $deleteEnd = time();
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary(number_format($nzbCount) . ' NZBs created in ' . ($nzbEnd - $startTime) . ' seconds.' . PHP_EOL . 'Deleted ' . number_format($deleted) . ' collections in ' . ($deleteEnd - $nzbEnd) . ' seconds.' . PHP_EOL . 'Total time: ' . $this->pdo->log->primary($this->consoleTools->convertTime(time() - $startTime))));
        }
        return $nzbCount;
    }
示例#4
0
 /**
  * Get list of contents inside a release's NZB file.
  *
  * @return bool
  */
 protected function _getNZBContents()
 {
     $nzbPath = $this->_nzb->NZBPath($this->_release['guid']);
     if ($nzbPath === false) {
         $this->_echo('NZB not found for GUID: ' . $this->_release['guid'], 'warning');
         // The nzb was not located. decrement the password status.
         $this->pdo->queryExec(sprintf('UPDATE releases SET passwordstatus = passwordstatus - 1 WHERE id = %d', $this->_release['id']));
         return false;
     }
     $nzbContents = \nzedb\utility\Utility::unzipGzipFile($nzbPath);
     // Get a list of files in the nzb.
     $this->_nzbContents = $this->_nzb->nzbFileList($nzbContents);
     if (count($this->_nzbContents) === 0) {
         $this->_echo('NZB is empty or broken for GUID: ' . $this->_release['guid'], 'warning');
         // There does not appear to be any files in the nzb, decrement password status.
         $this->pdo->queryExec(sprintf('UPDATE releases SET passwordstatus = passwordstatus - 1 WHERE id = %d', $this->_release['id']));
         return false;
     }
     // Sort the files inside the NZB.
     usort($this->_nzbContents, ['\\nzedb\\processing\\post\\ProcessAdditional', '_sortNZB']);
     return true;
 }
示例#5
0
 /**
  * Get list of contents inside a release's NZB file.
  *
  * @return bool
  */
 protected function _getNZBContents()
 {
     $nzbPath = $this->_nzb->getNZBPath($this->_release['guid']);
     if ($nzbPath === false) {
         $this->_echo('NZB not found for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     $nzbContents = Utility::unzipGzipFile($nzbPath);
     if (!$nzbContents) {
         $this->_echo('NZB is empty or broken for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     // Get a list of files in the nzb.
     $this->_nzbContents = $this->_nzb->nzbFileList($nzbContents);
     if (count($this->_nzbContents) === 0) {
         $this->_echo('NZB is potentially broken for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     // Sort keys.
     ksort($this->_nzbContents, SORT_NATURAL);
     return true;
 }
示例#6
0
    public function processGID($limit = 500, $batch = 5000, $delete_broken_releases = false)
    {
        // Process until someone presses cntrl-c
        $db = new Settings();
        $nzb = new NZB();
        $processed = 0;
        // We need an offset for tracking unhandled issues
        $offset = 0;
        $fsql = 'SELECT id, name, guid FROM releases ' . 'WHERE gid IS NULL ORDER BY adddate DESC LIMIT %d,%d';
        $usql = "UPDATE releases SET gid = '%s' WHERE id = %d";
        while (1) {
            // finish
            if ($limit > 0 && $processed >= $limit) {
                break;
            }
            $batch = $limit > 0 && $batch > $limit ? $limit : $batch;
            $res = $db->query(sprintf($fsql, $offset, $batch));
            if (!$res) {
                break;
            }
            if (count($res) <= 0) {
                break;
            }
            $offset += $batch;
            foreach ($res as $r) {
                $nzbfile = $nzb->getNZBPath($r["guid"]);
                if ($nzbfile === Null) {
                    continue;
                }
                $nzbInfo = new NZBInfo();
                if (!$nzbInfo->loadFromFile($nzbfile)) {
                    if ($delete_broken_releases) {
                        $release = new Releases();
                        $release->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage);
                        // Free the variable in an attempt to recover memory
                        unset($release);
                        echo '-';
                    } else {
                        // Skip over this one for future fetches
                        $offset++;
                    }
                    continue;
                }
                $gid = false;
                if (!empty($nzbInfo->gid)) {
                    $gid = $nzbInfo->gid;
                }
                // Free the variable in an attempt to recover memory
                unset($nzbInfo);
                if (!$gid) {
                    if ($delete_broken_releases) {
                        $release = new Releases();
                        $release->{$release}->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage);
                        unset($release);
                        echo '-';
                    } else {
                        // Skip over this one for future fetches
                        $offset++;
                    }
                    continue;
                }
                // Update DB With Global Identifer
                $ures = $db->queryExec(sprintf("UPDATE releases SET gid = %s WHERE id = %d", $db->escapeString($gid), $r['id']));
                if ($ures->rowCount() == 0) {
                    printf("\nPostPrc : Failed to update: %s\n", $r['name']);
                }
                // make noise...
                echo '.';
                $processed += 1;
            }
        }
        # Batch update for comment table
        /*$usql = 'UPDATE release_comments, releases '
        		.'SET release_comments.gid = releases.gid, '
        		.'release_comments.nzb_guid = releases.nzb_guid '
        		.'WHERE releases.id = release_comments.releaseid '
        		.'AND release_comments.gid IS NULL '
        		.'AND release_comments.nzb_guid = "" '
        		.'AND releases.nzb_guid IS NOT NULL '
        		.'AND releases.gid IS NOT NULL ';*/
        $affected = $db->queryExec(sprintf('UPDATE release_comments, releases SET release_comments.gid = releases.gid,
											release_comments.nzb_guid = releases.nzb_guid
											WHERE releases.id = release_comments.releaseid
											AND release_comments.gid IS NULL
											AND release_comments.nzb_guid = ""
											AND releases.nzb_guid IS NOT NULL
											AND releases.gid IS NOT NULL '));
        $rows = $affected->rowCount();
        if ($rows > 0) {
            $processed += $rows;
        }
        return $processed;
    }
示例#7
0
文件: Releases.php 项目: Jay204/nZEDb
 /**
  * @param $guids
  *
  * @return string
  */
 public function getZipped($guids)
 {
     $nzb = new NZB($this->pdo);
     $zipFile = new ZipFile();
     foreach ($guids as $guid) {
         $nzbPath = $nzb->NZBPath($guid);
         if ($nzbPath) {
             $nzbContents = nzedb\utility\Utility::unzipGzipFile($nzbPath);
             if ($nzbContents) {
                 $filename = $guid;
                 $r = $this->getByGuid($guid);
                 if ($r) {
                     $filename = $r['searchname'];
                 }
                 $zipFile->addFile($nzbContents, $filename . '.nzb');
             }
         }
     }
     return $zipFile->file();
 }
示例#8
0
/**
 * Compress an imported NZB and store it inside the nzbfiles folder.
 *
 * @param string $relguid    The guid of the release.
 * @param string $nzb        String containing the imported NZB.
 * @param NZB    $NZB
 * @param object $site
 *
 * @return bool
 *
 */
function copyNZBforImport($relguid, $nzb, $NZB, $pdo)
{
    $path = $NZB->getNZBPath($relguid, 0, true);
    $fp = gzopen($path, 'w5');
    if ($fp && $nzb) {
        $date1 = htmlspecialchars(date('F j, Y, g:i a O'), ENT_QUOTES, 'utf-8');
        $article = preg_replace('/dtd">\\s*<nzb xmlns=/', "dtd\">\n<!-- NZB Generated by: nZEDb " . $pdo->version() . ' ' . $date1 . " -->\n<nzb xmlns=", $nzb);
        gzwrite($fp, preg_replace('/<\\/file>\\s*(<!--.+)?\\s*<\\/nzb>\\s*/si', "</file>\n  <!--GrabNZBs-->\n</nzb>", $article));
        gzclose($fp);
        // Chmod to fix issues some users have with file permissions.
        chmod($path, 0777);
        return true;
    } else {
        echo "ERROR: NZB already exists?\n";
        return false;
    }
}
<?php

require_once dirname(__FILE__) . '/../../www/config.php';
use newznab\db\Settings;
$pdo = new Settings();
$n = new NZB();
$s = new Sites();
$items = $pdo->query("SELECT guid FROM releases");
while ($item = array_pop($items)) {
    $guid = $item['guid'];
    $nzbpath = $n->getNZBPath($guid, $pdo->getSetting('nzbpath'));
    $zd = _gzopen($nzbpath, "r");
    $s = gzread($zd, 10);
    if ($s != "<?xml vers") {
        echo "f****d - " . $guid . "\n";
    }
}
示例#10
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";
     }
 }
示例#11
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\db\Settings;
$pdo = new Settings();
if ($argc < 3 || !isset($argv[1]) || isset($argv[1]) && !is_numeric($argv[1])) {
    exit($pdo->log->error("\nIncorrect argument suppplied. This script will delete all duplicate releases matching on name, fromname, group_id and size.\n" . "Unfortunately, I can not guarantee which copy will be deleted.\n\n" . "php remove_exact_dupes.php 10 exact             ...: To delete all duplicates added within the last 10 hours.\n" . "php remove_exact_dupes.php 10 near              ...: To delete all duplicates with size variation of 1% and added within the last 10 hours.\n" . "php remove_exact_dupes.php 0 exact              ...: To delete all duplicates.\n" . "php remove_exact_dupes.php 0 near               ...: To delete all duplicates with size variation of 1%.\n" . "php remove_exact_dupes.php 10 exact dupes/      ...: To delete all duplicates added within the last 10 hours and save a copy of the nzb to dupes folder.\n"));
}
$crosspostt = $argv[1];
$releases = new Releases(['Settings' => $pdo]);
$count = $total = $all = 0;
$nzb = new NZB($pdo);
$ri = new ReleaseImage($pdo);
$consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$size = ' size ';
if ($argv[2] === 'near') {
    $size = ' size between (size *.99) AND (size * 1.01) ';
}
if ($crosspostt != 0) {
    $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1', $crosspostt);
} else {
    $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1');
}
do {
    $resrel = $pdo->queryDirect($query);
    if ($resrel instanceof Traversable) {
        $total = $resrel->rowCount();
        echo $pdo->log->header(number_format($total) . " Releases have Duplicates");
        foreach ($resrel as $rowrel) {
            $nzbpath = $nzb->getNZBPath($rowrel['guid']);
            if (isset($argv[3]) && is_dir($argv[3])) {
示例#12
0
 /**
  * Export to user specified folder.
  *
  * @param array $params
  *
  * @return bool
  *
  * @access public
  */
 public function beginExport($params)
 {
     $gzip = false;
     if ($params[4] === true) {
         $gzip = true;
     }
     $fromDate = $toDate = '';
     $path = $params[0];
     // Check if the path ends with dir separator.
     if (substr($path, -1) !== DS) {
         $path .= DS;
     }
     // Check if it's a directory.
     if (!is_dir($path)) {
         $this->echoOut('Folder does not exist: ' . $path);
         return $this->returnValue();
     }
     // Check if we can write to it.
     if (!is_writable($path)) {
         $this->echoOut('Folder is not writable: ' . $path);
         return $this->returnValue();
     }
     // Check if the from date is the proper format.
     if (isset($params[1]) && $params[1] !== '') {
         if (!$this->checkDate($params[1])) {
             return $this->returnValue();
         }
         $fromDate = $params[1];
     }
     // Check if the to date is the proper format.
     if (isset($params[2]) && $params[2] !== '') {
         if (!$this->checkDate($params[2])) {
             return $this->returnValue();
         }
         $toDate = $params[2];
     }
     // Check if the group_id exists.
     if (isset($params[3]) && $params[3] !== 0) {
         if (!is_numeric($params[3])) {
             $this->echoOut('The group ID is not a number: ' . $params[3]);
             return $this->returnValue();
         }
         $groups = $this->pdo->query('SELECT id, name FROM groups WHERE id = ' . $params[3]);
         if (count($groups) === 0) {
             $this->echoOut('The group ID is not in the DB: ' . $params[3]);
             return $this->returnValue();
         }
     } else {
         $groups = $this->pdo->query('SELECT id, name FROM groups');
     }
     $exported = 0;
     // Loop over groups to take less RAM.
     foreach ($groups as $group) {
         $currentExport = 0;
         // Get all the releases based on the parameters.
         $releases = $this->releases->getForExport($fromDate, $toDate, $group['id']);
         $totalFound = count($releases);
         if ($totalFound === 0) {
             if ($this->echoCLI) {
                 echo 'No releases found to export for group: ' . $group['name'] . PHP_EOL;
             }
             continue;
         }
         if ($this->echoCLI) {
             echo 'Found ' . $totalFound . ' releases to export for group: ' . $group['name'] . PHP_EOL;
         }
         // Create a path to store the new NZB files.
         $currentPath = $path . $this->safeFilename($group['name']) . DS;
         if (!is_dir($currentPath)) {
             mkdir($currentPath);
         }
         foreach ($releases as $release) {
             // Get path to the NZB file.
             $nzbFile = $this->nzb->getNZBPath($release["guid"]);
             // Check if it exists.
             if ($nzbFile === false) {
                 if ($this->echoCLI) {
                     echo 'Unable to find NZB for release with GUID: ' . $release['guid'];
                 }
                 continue;
             }
             // Create path to current file.
             $currentFile = $currentPath . $this->safeFilename($release['searchname']);
             // Check if the user wants them in gzip, copy it if so.
             if ($gzip) {
                 if (!copy($nzbFile, $currentFile . '.nzb.gz')) {
                     if ($this->echoCLI) {
                         echo 'Unable to export NZB with GUID: ' . $release['guid'];
                     }
                     continue;
                 }
                 // If not, decompress it and create a file to store it in.
             } else {
                 $nzbContents = Utility::unzipGzipFile($nzbFile);
                 if (!$nzbContents) {
                     if ($this->echoCLI) {
                         echo 'Unable to export NZB with GUID: ' . $release['guid'];
                     }
                     continue;
                 }
                 $fh = fopen($currentFile . '.nzb', 'w');
                 fwrite($fh, $nzbContents);
                 fclose($fh);
             }
             $currentExport++;
             if ($this->echoCLI && $currentExport % 10 === 0) {
                 echo 'Exported ' . $currentExport . ' of ' . $totalFound . ' nzbs for group: ' . $group['name'] . "\r";
             }
         }
         if ($this->echoCLI && $currentExport > 0) {
             echo 'Exported ' . $currentExport . ' of ' . $totalFound . ' nzbs for group: ' . $group['name'] . PHP_EOL;
         }
         $exported += $currentExport;
     }
     if ($exported > 0) {
         $this->echoOut('Exported total of ' . $exported . ' NZB files to ' . $path);
     }
     return $this->returnValue();
 }
示例#13
0
 /**
  * Check for passworded releases, RAR contents and Sample/Media info
  */
 public function processAdditional($numtoProcess = 100)
 {
     $maxattemptstocheckpassworded = 5;
     $processVideoSample = $this->pdo->getSetting('ffmpegpath') != '' ? true : false;
     $processMediainfo = $this->pdo->getSetting('mediainfopath') != '' ? true : false;
     $processPasswords = $this->pdo->getSetting('unrarpath') != '' ? true : false;
     $processAudioSample = $this->pdo->getSetting('saveaudiopreview') == 1 ? true : false;
     $tmpPath = $this->pdo->getSetting('tmpunrarpath');
     if (substr($tmpPath, -strlen('/')) != '/') {
         $tmpPath = $tmpPath . '/';
     }
     if (!file_exists($tmpPath)) {
         mkdir($tmpPath, 0766, true);
     }
     $nntp = new NNTP();
     $nzb = new NZB();
     //
     // Get out all releases which have not been checked more than max attempts for password.
     //
     $sql = sprintf("select r.id, r.guid, r.name, c.disablepreview from releases r\n\t\t\tleft join category c on c.id = r.categoryid\n\t\t\twhere (r.passwordstatus between %d and -1)\n\t\t\tor (r.haspreview = -1 and c.disablepreview = 0) order by r.postdate desc limit %d ", ($maxattemptstocheckpassworded + 1) * -1, $numtoProcess);
     $result = $this->pdo->query($sql);
     $iteration = $rescount = sizeof($result);
     if ($rescount > 0) {
         echo "PostPrc : Performing additional post processing on last " . $rescount . " releases ...";
         $nntpconnected = false;
         foreach ($result as $rel) {
             echo $iteration-- . ".";
             // Per release defaults
             $passStatus = array(Releases::PASSWD_NONE);
             $blnTookMediainfo = false;
             $blnTookSample = $rel['disablepreview'] == 1 ? true : false;
             //only attempt sample if not disabled
             if ($blnTookSample) {
                 $this->pdo->queryExec(sprintf("update releases set haspreview = 0 where id = %d", $rel['id']));
             }
             //
             // Go through the binaries for this release looking for a rar, a sample, and a mediafile
             //
             $nzbInfo = new nzbInfo();
             $norar = 0;
             // only load nzbs and check for rar files if we are doing something with them.
             if ($processVideoSample || $processMediainfo || $processPasswords || $processAudioSample) {
                 $nzbfile = $nzb->getNZBPath($rel['guid'], $this->pdo->getSetting('nzbpath'));
                 if (!$nzbInfo->loadFromFile($nzbfile)) {
                     continue;
                 }
                 foreach ($nzbInfo->nzb as $nzbsubject) {
                     if (preg_match("/\\w\\.r00/i", $nzbsubject['subject'])) {
                         $norar = 1;
                     }
                 }
             }
             // attempt to process video sample file
             if (!empty($nzbInfo->samplefiles) && $processVideoSample && $blnTookSample === false) {
                 $sampleFile = $nzbInfo->samplefiles[0];
                 //first detected sample
                 $sampleMsgids = array_slice($sampleFile['segments'], 0, 1);
                 //get first segment, increase to get more of the sample
                 $sampleGroup = $sampleFile['groups'][0];
                 //echo "PostPrc : Fetching ".implode($sampleMsgids, ', ')." from {$sampleGroup}\n";
                 if (!$nntpconnected) {
                     $nntpconnected = $nntp->doConnect();
                 }
                 $sampleBinary = $nntp->getMessages($sampleGroup, $sampleMsgids);
                 if ($sampleBinary === false) {
                     echo "\nPostPrc : Couldnt fetch sample\n";
                 } else {
                     $samplefile = $tmpPath . 'sample.avi';
                     file_put_contents($samplefile, $sampleBinary);
                     $blnTookSample = $this->getSample($tmpPath, $this->pdo->getSetting('ffmpegpath'), $rel['guid']);
                     if ($blnTookSample) {
                         $this->updateReleaseHasPreview($rel['guid']);
                     }
                     unlink($samplefile);
                 }
                 unset($sampleBinary);
             }
             // attempt to process loose media file
             if (!empty($nzbInfo->mediafiles) && ($processVideoSample && $blnTookSample === false || $processMediainfo)) {
                 $mediaFile = $nzbInfo->mediafiles[0];
                 //first detected media file
                 $mediaMsgids = array_slice($mediaFile['segments'], 0, 2);
                 //get first two segments
                 $mediaGroup = $mediaFile['groups'][0];
                 //echo "PostPrc : Fetching ".implode($mediaMsgids, ', ')." from {$mediaGroup}\n";
                 if (!$nntpconnected) {
                     $nntpconnected = $nntp->doConnect();
                 }
                 $mediaBinary = $nntp->getMessages($mediaGroup, $mediaMsgids);
                 if ($mediaBinary === false) {
                     echo "\nPostPrc : Couldnt fetch media file\n";
                 } else {
                     $mediafile = $tmpPath . 'sample.avi';
                     file_put_contents($mediafile, $mediaBinary);
                     if ($processVideoSample && $blnTookSample === false) {
                         $blnTookSample = $this->getSample($tmpPath, $this->pdo->getSetting('ffmpegpath'), $rel['guid']);
                         if ($blnTookSample) {
                             $this->updateReleaseHasPreview($rel['guid']);
                         }
                     }
                     if ($processMediainfo) {
                         $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->pdo->getSetting('mediainfopath'), $rel['id']);
                     }
                     unlink($mediafile);
                 }
                 unset($mediaBinary);
             }
             // attempt to process audio sample file
             if (!empty($nzbInfo->audiofiles) && $processAudioSample && $blnTookSample === false) {
                 $audioFile = $nzbInfo->audiofiles[0];
                 //first detected audio file
                 $audioMsgids = array_slice($audioFile['segments'], 0, 1);
                 //get first segment
                 $audioGroup = $audioFile['groups'][0];
                 //echo "PostPrc : Fetching ".implode($audioMsgids, ', ')." from {$audioGroup}\n";
                 if (!$nntpconnected) {
                     $nntpconnected = $nntp->doConnect();
                 }
                 $audioBinary = $nntp->getMessages($audioGroup, $audioMsgids);
                 if ($audioBinary === false) {
                     echo "\nPostPrc : Couldnt fetch audio sample\n";
                 } else {
                     $audiofile = $tmpPath . 'sample.mp3';
                     file_put_contents($audiofile, $audioBinary);
                     $blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']);
                     if ($blnTookSample !== false) {
                         $this->updateReleaseHasPreview($rel['guid'], 2);
                     }
                     if ($processMediainfo) {
                         $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->pdo->getSetting('mediainfopath'), $rel['id']);
                     }
                     if ($this->pdo->getSetting('lamepath') != "") {
                         $this->lameAudioSample($this->pdo->getSetting('lamepath'), $rel['guid']);
                     }
                     unlink($audiofile);
                 }
                 unset($audioBinary);
             }
             if (!empty($nzbInfo->rarfiles) && ($this->pdo->getSetting('checkpasswordedrar') > 0 || ($processVideoSample || $processAudioSample) && $blnTookSample === false || $processMediainfo)) {
                 $mysqlkeepalive = 0;
                 foreach ($nzbInfo->rarfiles as $rarFile) {
                     //dont process any more rars if a passworded rar has been detected and the site is set to automatically delete them
                     if ($this->pdo->getSetting('deletepasswordedrelease') == 1 && max($passStatus) == Releases::PASSWD_RAR) {
                         echo "-Skipping processing of rar {$rarFile['subject']} as this release has already been marked as passworded.\n";
                         continue;
                     }
                     $rarMsgids = array_slice($rarFile['segments'], 0, 1);
                     //get first segment
                     $rarGroup = $rarFile['groups'][0];
                     //echo "PostPrc : Fetching ".implode($rarMsgids, ', ')." from {$rarGroup} (".++$mysqlkeepalive.")\n";
                     if (!$nntpconnected) {
                         $nntpconnected = $nntp->doConnect();
                     }
                     $fetchedBinary = $nntp->getMessages($rarGroup, $rarMsgids);
                     if ($fetchedBinary === false) {
                         //echo "\nPostPrc : Failed fetching rar file\n";
                         $this->pdo->queryExec(sprintf("update releases set passwordstatus = passwordstatus - 1 where id = %d", $rel['id']));
                         continue;
                     } else {
                         $relFiles = $this->processReleaseFiles($fetchedBinary, $rel['id']);
                         if ($this->pdo->getSetting('checkpasswordedrar') > 0 && $processPasswords) {
                             $passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->pdo->getSetting('unrarpath'), $this->pdo->getSetting('checkpasswordedrar'));
                         }
                         // we need to unrar the fetched binary if checkpasswordedrar wasnt 2
                         if ($this->pdo->getSetting('checkpasswordedrar') < 2 && $processPasswords) {
                             $rarfile = $tmpPath . 'rarfile.rar';
                             file_put_contents($rarfile, $fetchedBinary);
                             $execstring = '"' . $this->pdo->getSetting('unrarpath') . '" e -ai -ep -c- -id -r -kb -p- -y -inul "' . $rarfile . '" "' . $tmpPath . '"';
                             $output = Utility::runCmd($execstring, false, true);
                             unlink($rarfile);
                         }
                         if ($processVideoSample && $blnTookSample === false) {
                             $blnTookSample = $this->getSample($tmpPath, $this->pdo->getSetting('ffmpegpath'), $rel['guid']);
                             if ($blnTookSample) {
                                 $this->updateReleaseHasPreview($rel['guid']);
                             }
                         }
                         $blnTookAudioSample = false;
                         if ($processAudioSample && $blnTookSample === false) {
                             $blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']);
                             if ($blnTookSample) {
                                 $blnTookAudioSample = true;
                                 $this->updateReleaseHasPreview($rel['guid'], 2);
                             }
                         }
                         if ($processMediainfo && $blnTookMediainfo === false) {
                             $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->pdo->getSetting('mediainfopath'), $rel['id']);
                         }
                         //
                         // Has to be done after mediainfo
                         //
                         if ($blnTookAudioSample && $this->pdo->getSetting('lamepath') != "") {
                             $this->lameAudioSample($this->pdo->getSetting('lamepath'), $rel['guid']);
                         }
                         if ($mysqlkeepalive % 25 == 0) {
                             $this->pdo->query("select 1");
                         }
                     }
                     //clean up all files
                     foreach (glob($tmpPath . '*') as $v) {
                         unlink($v);
                     }
                 }
                 //end foreach msgid
             } elseif (empty($nzbInfo->rarfiles) && $norar == 1) {
                 $passStatus[] = Releases::PASSWD_POTENTIAL;
             }
             $hpsql = '';
             if (!$blnTookSample) {
                 $hpsql = ', haspreview = 0';
             }
             $sql = sprintf("update releases set passwordstatus = %d %s where id = %d", max($passStatus), $hpsql, $rel["id"]);
             $this->pdo->queryExec($sql);
         }
         //end foreach result
         if ($nntpconnected) {
             $nntp->doQuit();
         }
         echo "\n";
     }
 }
示例#14
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\db\Settings;
if (!isset($argv[1]) || !isset($argv[2])) {
    exit("ERROR: You must supply the level you want to reorganize it to, and the source directory  (You would use: 3 .../nZEDb/resources/nzb/ to move it to 3 levels deep)\n");
}
$pdo = new Settings();
$nzb = new NZB($pdo);
$consoleTools = new ConsoleTools();
$newLevel = $argv[1];
$sourcePath = $argv[2];
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sourcePath));
$filestoprocess = array();
$iFilesProcessed = $iFilesCounted = 0;
$time = TIME();
echo "\nReorganizing files to Level {$newLevel} from: {$sourcePath} This could take a while...\n";
//$consoleTools = new ConsoleTools();
foreach ($objects as $filestoprocess => $nzbFile) {
    if ($nzbFile->getExtension() != "gz") {
        continue;
    }
    $newFileName = $nzb->getNZBPath(str_replace(".nzb.gz", "", $nzbFile->getBasename()), $newLevel, true);
    if ($newFileName != $nzbFile) {
        rename($nzbFile, $newFileName);
        chmod($newFileName, 0777);
    }
    $iFilesProcessed++;
    if ($iFilesProcessed % 100 == 0) {
        $consoleTools->overWrite("Reorganized {$iFilesProcessed}");
    }
示例#15
0
<?php

require_once "config.php";
$page = new AdminPage();
$users = new Users();
$releases = new Releases();
$nzb = new NZB();
if (!$users->isLoggedIn()) {
    $page->show403();
}
if (isset($_GET["id"])) {
    $rel = $releases->getByGuid($_GET["id"]);
    if (!$rel) {
        $page->show404();
    }
    $nzbpath = $nzb->getNZBPath($_GET["id"], $page->settings->getSetting('nzbpath'));
    if (!file_exists($nzbpath)) {
        $page->show404();
    }
    ob_start();
    @readgzfile($nzbpath);
    $nzbfile = ob_get_contents();
    ob_end_clean();
    $ret = $nzb->nzbFileList($nzbfile);
    $page->smarty->assign('rel', $rel);
    $page->smarty->assign('files', $ret);
    $page->title = "File List";
    $page->meta_title = "View Nzb file list";
    $page->meta_keywords = "view,nzb,file,list,description,details";
    $page->meta_description = "View Nzb File List";
    $page->content = $page->smarty->fetch('release-files.tpl');
 /**
  * Writes a zip file of an array of release guids directly to the stream
  */
 public function getZipped($guids)
 {
     $s = new Sites();
     $nzb = new NZB();
     $site = $s->get();
     $zipfile = new zipfile();
     foreach ($guids as $guid) {
         $nzbpath = $nzb->getNZBPath($guid, $site->nzbpath);
         if (file_exists($nzbpath)) {
             ob_start();
             @readgzfile($nzbpath);
             $nzbfile = ob_get_contents();
             ob_end_clean();
             $filename = $guid;
             $r = $this->getByGuid($guid);
             if ($r) {
                 $filename = $r["searchname"];
             }
             $zipfile->addFile($nzbfile, $filename . ".nzb");
         }
     }
     return $zipfile->file();
 }
示例#17
0
<?php

/* Fixes NZB files with a blank first line. */
require dirname(__FILE__) . '/../../../www/config.php';
use nzedb\db\Settings;
$pdo = new Settings();
if (isset($argv[1]) && $argv[1] == "true") {
    $timestart = time();
    $nzbcount = $brokencount = 0;
    $guids = $pdo->queryDirect("SELECT guid FROM releases WHERE nzbstatus = 1 ORDER BY postdate DESC");
    echo $pdo->log->primary("Be patient, this WILL take a very long time, make sure to kill all nZEDb scripts first. There are " . number_format($guids->rowCount()) . " NZB files to scan.");
    $nzb = new NZB($pdo);
    if ($guids instanceof Traversable) {
        foreach ($guids as $guid) {
            $nzbpath = $nzb->NZBPath($guid["guid"]);
            if ($nzbpath !== false) {
                $nzbcount++;
                $nzbfile = nzedb\utility\Utility::unzipGzipFile($nzbpath);
                if ($nzbfile && preg_match('/^[\\r\\n]+<\\?xml/', $nzbfile)) {
                    $brokencount++;
                    $nzbfile = preg_replace('/^[\\r\\n]+<\\?xml/i', '<?xml', $nzbfile);
                    $nzb = preg_replace('/<\\/nzb>.+/i', '</nzb>', $nzbfile);
                    unlink($nzbpath);
                    $fp = gzopen($nzbpath, 'w6');
                    if ($fp) {
                        gzwrite($fp, $nzb, strlen($nzb));
                        gzclose($fp);
                        chmod($nzbpath, 0777);
                    }
                }
                if ($nzbcount % 5000 == 0) {
示例#18
0
<?php

require_once dirname(__FILE__) . '/../../www/config.php';
use newznab\db\Settings;
use newznab\utility\Utility;
$releases = new Releases();
$db = new Settings();
$cat = new Categorize();
$releaseRegex = new ReleaseRegex();
$nzb = new NZB();
$page = new Page();
$num = 0;
$usefilename = true;
$dupecheck = true;
$movefiles = true;
$categoryoverride = -1;
if (empty($argc) || $argc <= 1) {
    $path = "./";
} else {
    $util = new Utility();
    $path = !$util->endsWith($argv[1], "/") ? $argv[1] . "/" : $argv[1];
    if (isset($argv[2])) {
        $usefilename = strtolower($argv[2]) == 'true';
    }
    if (isset($argv[3])) {
        $dupecheck = strtolower($argv[3]) == 'true';
    }
    if (isset($argv[4])) {
        $movefiles = strtolower($argv[4]) == 'true';
    }
    if (isset($argv[5]) && is_numeric($argv[5])) {
示例#19
0
<?php

require_once dirname(__FILE__) . '/../../www/config.php';
use newznab\db\Settings;
$releases = new Releases();
$pdo = new Settings();
$nzb = new NZB();
$nntp = new NNTP();
// read pars for a release GUID, echo out any that look like a rar
$relguid = "249f9ec1f0d68d33b5fa85594ba1a47d";
$nzbfile = $nzb->getNZBPath($relguid, $pdo->getSetting('nzbpath'), true);
$nzbInfo = new nzbInfo();
$nzbInfo->loadFromFile($nzbfile);
$nntp->doConnect();
echo $nzbInfo->summarize();
foreach ($nzbInfo->parfiles as $parfile) {
    echo "Fetching " . $parfile['subject'] . "\n";
    $parBinary = $nntp->getMessages($parfile['groups'][0], $parfile['segments']);
    if ($parBinary) {
        $par2 = new Par2info();
        $par2->setData($parBinary);
        if (!$par2->error) {
            $parFiles = $par2->getFileList();
            foreach ($parFiles as $file) {
                if (preg_match('/.*part0*1\\.rar$/iS', $file['name']) || preg_match('/(?!part0*1)\\.rar$/iS', $file['name']) || preg_match('/\\.001$/iS', $file['name'])) {
                    print_r($file);
                }
            }
        }
    }
    unset($parBinary);
 public function processGID($limit = 500, $batch = 5000, $delete_broken_releases = false)
 {
     // Process until someone presses cntrl-c
     $db = new DB();
     $nzb = new NZB();
     $processed = 0;
     // We need an offset for tracking unhandled issues
     $offset = 0;
     $fsql = 'SELECT ID, name, guid FROM releases ' . 'WHERE GID IS NULL ORDER BY adddate DESC LIMIT %d,%d';
     $usql = "UPDATE releases SET GID = '%s' WHERE ID = %d";
     while (1) {
         // finish
         if ($limit > 0 && $processed >= $limit) {
             break;
         }
         $batch = $limit > 0 && $batch > $limit ? $limit : $batch;
         $res = $db->query(sprintf($fsql, $offset, $batch));
         if (!$res) {
             break;
         }
         if (count($res) <= 0) {
             break;
         }
         $offset += $batch;
         foreach ($res as $r) {
             $nzbfile = $nzb->getNZBPath($r["guid"]);
             if ($nzbfile === Null) {
                 continue;
             }
             $nzbInfo = new NzbInfo();
             if (!$nzbInfo->loadFromFile($nzbfile)) {
                 if ($delete_broken_releases) {
                     $release = new Releases();
                     $release->delete($r['ID']);
                     // Free the variable in an attempt to recover memory
                     unset($release);
                     echo '-';
                 } else {
                     // Skip over this one for future fetches
                     $offset++;
                 }
                 continue;
             }
             $gid = false;
             if (!empty($nzbInfo->gid)) {
                 $gid = $nzbInfo->gid;
             }
             // Free the variable in an attempt to recover memory
             unset($nzbInfo);
             if (!$gid) {
                 if ($delete_broken_releases) {
                     $release = new Releases();
                     $release->delete($r['ID']);
                     unset($release);
                     echo '-';
                 } else {
                     // Skip over this one for future fetches
                     $offset++;
                 }
                 continue;
             }
             // Update DB With Global Identifer
             $ures = $db->exec(sprintf($usql, $gid, $r['ID']));
             if ($ures < 0) {
                 printf("\nPostPrc : Failed to update: %s\n", $r['name']);
             }
             // make noise...
             echo '.';
             $processed += 1;
         }
     }
     # Batch update for comment table
     $usql = 'UPDATE releasecomment, releases ' . 'SET releasecomment.GID = releases.GID ' . 'WHERE releases.ID = releasecomment.releaseID ' . 'AND releasecomment.GID IS NULL ' . 'AND releases.GID IS NOT NULL ';
     $affected = $db->exec(sprintf($usql));
     if ($affected > 0) {
         $processed += $affected;
     }
     return $processed;
 }
示例#21
0
    /**
     * Deletes a single release by GUID, and all the corresponding files.
     *
     * @param array        $identifiers ['g' => Release GUID(mandatory), 'id => ReleaseID(optional, pass false)]
     * @param NZB          $nzb
     * @param ReleaseImage $releaseImage
     */
    public function deleteSingle($identifiers, $nzb, $releaseImage)
    {
        // Delete NZB from disk.
        $nzbPath = $nzb->getNZBPath($identifiers['g']);
        if ($nzbPath) {
            @unlink($nzbPath);
        }
        // Delete images.
        $releaseImage->delete($identifiers['g']);
        //Delete from sphinx.
        $this->sphinxSearch->deleteRelease($identifiers, $this->pdo);
        // Delete from DB.
        $this->pdo->queryDelete(sprintf('
				DELETE r, rn, rc, uc, rf, ra, rs, rv, re
				FROM releases r
				LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id
				LEFT OUTER JOIN releasecomment rc ON rc.releaseid = r.id
				LEFT OUTER JOIN usercart uc ON uc.releaseid = r.id
				LEFT OUTER JOIN releasefiles rf ON rf.releaseid = r.id
				LEFT OUTER JOIN releaseaudio ra ON ra.releaseid = r.id
				LEFT OUTER JOIN releasesubs rs ON rs.releaseid = r.id
				LEFT OUTER JOIN releasevideo rv ON rv.releaseid = r.id
				LEFT OUTER JOIN releaseextrafull re ON re.releaseid = r.id
				WHERE r.guid = %s', $this->pdo->escapeString($identifiers['g'])));
    }
示例#22
0
<?php

use newznab\db\Settings;
$nzb = new NZB($page->settings);
$rel = new Releases(['Settings' => $page->settings]);
$uid = 0;
// Page is accessible only by the rss token, or logged in users.
if ($page->users->isLoggedIn()) {
    $uid = $page->users->currentUserId();
    $maxdls = $page->userdata["downloadrequests"];
    $rsstoken = $page->userdata['rsstoken'];
} else {
    if ($page->settings->getSetting('registerstatus') == Settings::REGISTER_STATUS_API_ONLY) {
        $res = $page->users->getById(0);
    } else {
        if (!isset($_GET["i"]) || !isset($_GET["r"])) {
            header("X-DNZB-RCode: 400");
            header("X-DNZB-RText: Bad request, please supply all parameters!");
            $page->show403();
        }
        $res = $page->users->getByIdAndRssToken($_GET["i"], $_GET["r"]);
        if (!$res) {
            header("X-DNZB-RCode: 401");
            header("X-DNZB-RText: Unauthorised, wrong user ID or rss key!");
            $page->show403();
        }
    }
    $uid = $res["id"];
    $rsstoken = $res['rsstoken'];
    $maxdls = $res["downloadrequests"];
}
require_once "config.php";
require_once WWW_DIR . "/lib/adminpage.php";
require_once WWW_DIR . "/lib/framework/db.php";
require_once FS_ROOT . "/../../www/lib/nzb.php";
require_once FS_ROOT . "/../../www/lib/util.php";
require_once FS_ROOT . "/../../www/lib/nzbinfo.php";
require_once FS_ROOT . "/../../www/lib/category.php";
require_once FS_ROOT . "/../../www/lib/releases.php";
if (!empty($argc)) {
    echo "\n\n***WARNING*** : This method of importing is deprecated - you should use /misc/update_scripts/import.php\n\n\n";
    die;
}
$db = new DB();
$page = new AdminPage();
$nzb = new NZB();
$filestoprocess = array();
$browserpostednames = array();
$cat = new Category();
$releases = new Releases();
if ($page->isPostBack()) {
    $retval = "";
    //
    // Via browser, build an array of all the nzb files uploaded into php /tmp location
    //
    if (isset($_FILES["uploadedfiles"])) {
        foreach ($_FILES["uploadedfiles"]["error"] as $key => $error) {
            if ($error == UPLOAD_ERR_OK) {
                $tmp_name = $_FILES["uploadedfiles"]["tmp_name"][$key];
                $name = $_FILES["uploadedfiles"]["name"][$key];
                $filestoprocess[] = $tmp_name;
示例#24
0
 /**
  * @param array $filesToProcess List of NZB files to import.
  * @param bool|string $useNzbName Use the NZB file name as release name?
  * @param bool $delete Delete the NZB when done?
  * @param bool $deleteFailed Delete the NZB if failed importing?
  *
  * @return string|bool
  *
  * @access public
  */
 public function beginImport($filesToProcess, $useNzbName = false, $delete = true, $deleteFailed = true)
 {
     // Get all the groups in the DB.
     if (!$this->getAllGroups()) {
         if ($this->browser) {
             return $this->retVal;
         } else {
             return false;
         }
     }
     $start = date('Y-m-d H:i:s');
     $nzbsImported = $nzbsSkipped = 0;
     // Loop over the file names.
     foreach ($filesToProcess as $nzbFile) {
         // Check if the file is really there.
         if (is_file($nzbFile)) {
             // Get the contents of the NZB file as a string.
             if (strtolower(substr($nzbFile, -7)) === '.nzb.gz') {
                 $nzbString = Utility::unzipGzipFile($nzbFile);
             } else {
                 $nzbString = file_get_contents($nzbFile);
             }
             if ($nzbString === false) {
                 $this->echoOut('ERROR: Unable to read: ' . $nzbFile);
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
             // Load it as a XML object.
             $nzbXML = @simplexml_load_string($nzbString);
             if ($nzbXML === false || strtolower($nzbXML->getName()) != 'nzb') {
                 $this->echoOut('ERROR: Unable to load NZB XML data: ' . $nzbFile);
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
             // Try to insert the NZB details into the DB.
             $inserted = $this->scanNZBFile($nzbXML, $useNzbName ? str_ireplace('.nzb', '', basename($nzbFile)) : false);
             if ($inserted) {
                 // Try to copy the NZB to the NZB folder.
                 $path = $this->nzb->getNZBPath($this->relGuid, 0, true);
                 // Try to compress the NZB file in the NZB folder.
                 $fp = gzopen($path, 'w5');
                 gzwrite($fp, $nzbString);
                 gzclose($fp);
                 if (!is_file($path)) {
                     $this->echoOut('ERROR: Problem compressing NZB file to: ' . $path);
                     // Remove the release.
                     $this->pdo->queryExec(sprintf("DELETE FROM releases WHERE guid = %s", $this->pdo->escapeString($this->relGuid)));
                     if ($deleteFailed) {
                         @unlink($nzbFile);
                     }
                     $nzbsSkipped++;
                     continue;
                 } else {
                     if ($delete) {
                         // Remove the nzb file.
                         @unlink($nzbFile);
                     }
                     $nzbsImported++;
                     continue;
                 }
             } else {
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
         } else {
             $this->echoOut('ERROR: Unable to fetch: ' . $nzbFile);
             $nzbsSkipped++;
             continue;
         }
     }
     $this->echoOut('Proccessed ' . $nzbsImported . ' NZBs in ' . (strtotime(date('Y-m-d H:i:s')) - strtotime($start)) . ' seconds, ' . $nzbsSkipped . ' NZBs were skipped.');
     if ($this->browser) {
         return $this->retVal;
     } else {
         return true;
     }
 }
示例#25
0
<?php

/*
Filesize Fix Script
If after import you have a bunch of zero sized releases run this
Author: lordgnu <*****@*****.**>
*/
require_once dirname(__FILE__) . '/../../www/config.php';
use newznab\db\Settings;
$pdo = new Settings();
$nzb = new NZB();
$items = $pdo->query("SELECT id,guid FROM releases WHERE size = 0");
$total = count($items);
$compl = 0;
echo "Updating file size for " . count($items) . " release(s)\n";
while ($item = array_pop($items)) {
    $nzbpath = $nzb->getNZBPath($item['guid'], $pdo->getSetting('nzbpath'));
    ob_start();
    @readgzfile($nzbpath);
    $nzbfile = ob_get_contents();
    ob_end_clean();
    $ret = $nzb->nzbFileList($nzbfile);
    $filesize = '0';
    foreach ($ret as $file) {
        $filesize = bcadd($filesize, $file['size']);
    }
    $pdo->queryExec("UPDATE releases SET size = '{$filesize}' WHERE id = '{$item['id']}' LIMIT 1");
    $compl++;
    echo sprintf("[%6d / %6d] %0.2f", $compl, $total, $compl / $total * 100) . '%' . "\n";
}
示例#26
0
         $postfrom = $_POST["postfrom"];
     }
     if (isset($_POST["postto"])) {
         $postto = $_POST["postto"];
     }
     if (isset($_POST["group"])) {
         $group = $_POST["group"];
     }
 }
 if ($path != "") {
     if (substr($path, strlen($path) - 1) != '/') {
         $path = $path . "/";
     }
     $releases = $rel->getForExport($postfrom, $postto, $group);
     $s = new Sites();
     $nzb = new NZB();
     $site = $s->get();
     $nzbCount = 0;
     $total = count($releases);
     foreach ($releases as $release) {
         $catname = safeFilename($release["catName"]);
         if (!file_exists($path . $catname)) {
             mkdir($path . $catname);
         }
         ob_start();
         @readgzfile($nzb->getNZBPath($release["guid"], $site->nzbpath));
         $nzbfile = ob_get_contents();
         ob_end_clean();
         $fh = fopen($path . $catname . "/" . safeFilename($release["searchname"]) . ".nzb", 'w');
         fwrite($fh, $nzbfile);
         fclose($fh);
示例#27
0
 private function scan_releases(&$processed, &$total, $limit = Null)
 {
     // Scan all nzb files whos releases match against data
     // that has no nfo files associated with it.
     //
     // nzb files are further parsed for nfo segments that can
     // be extracted and applied to the release
     $nzb = new NZB();
     $db = new Settings();
     // How many releases to handle at a time
     $batch = Nfo::NNTP_BATCH_COUNT;
     // Build NFO List
     $nfometa = array();
     // Missing NFO Query (oldest first so they don't expire on us)
     $mnfo = "SELECT id,guid, name FROM releases r " . "WHERE r.releasenfoid = " . Nfo::FLAG_NFO_PENDING . " ORDER BY postdate DESC";
     if ($limit !== Null && $limit > 0) {
         $mnfo .= " LIMIT {$limit}";
     }
     $res = $db->query($mnfo);
     if ($res) {
         foreach ($res as $r) {
             $nzbfile = $nzb->getNZBPath($r["guid"]);
             if (!is_file($nzbfile)) {
                 if ($this->verbose) {
                     echo sprintf("%s Missing NZB File: %d/%s ...\n", 'NfoProc', intval($r["id"]), $r["name"]);
                 }
                 $this->setNfoMissing($r["id"]);
                 continue;
             }
             $nzbInfo = new NzbInfo();
             if (!$nzbInfo->loadFromFile($nzbfile)) {
                 if ($this->verbose) {
                     echo sprintf("%s Unable to parse NZB File: %d/%s ...\n", 'NfoProc', intval($r["id"]), $r["name"]);
                 }
                 $this->setNfoMissing($r["id"]);
                 continue;
             }
             $total += 1;
             $filename = basename($nzbfile);
             if ($this->verbose) {
                 echo sprintf("NfoProc : Scanning %s - ", $r["name"]);
             }
             $matches = $this->nfo_scan($nzbInfo);
             unset($nzbInfo);
             if (is_array($matches)) {
                 if (!count($matches)) {
                     if ($this->verbose) {
                         echo "nfo missing.\n";
                     }
                     $this->setNfoMissing($r["id"]);
                     continue;
                 }
             } else {
                 if ($this->verbose) {
                     echo "corrupt nzb.\n";
                 }
                 $this->setNfoMissing($r["id"]);
                 continue;
             }
             if ($this->verbose) {
                 echo count($matches) . " possible nfo(s).\n";
             }
             $processed++;
             // Hash Matches by Release id
             $nfometa[(string) $r["id"]] = $matches;
             if (!($processed % $batch)) {
                 $nfoblob = array();
                 if ($this->verbose) {
                     echo "NfoProc : Retrieval ...";
                 }
                 if ($this->nfo_grab($nfometa, $nfoblob)) {
                     $before = array_keys($nfoblob);
                     $this->parse_blobs($nfometa, $nfoblob);
                     $after = array_keys($nfoblob);
                     $removed = array_diff($before, $after);
                     $this->store_blob($nfometa, $nfoblob, $removed);
                 }
                 if ($this->verbose) {
                     echo "\n";
                 }
                 // Reset nfo list array
                 $nfometa = array();
             }
         }
         if ($processed % $batch) {
             $nfoblob = array();
             if ($this->verbose) {
                 echo "NfoProc : Retrieval ...";
             }
             if ($this->nfo_grab($nfometa, $nfoblob)) {
                 $before = array_keys($nfoblob);
                 $this->parse_blobs($nfometa, $nfoblob);
                 $after = array_keys($nfoblob);
                 $removed = array_diff($before, $after);
                 $this->store_blob($nfometa, $nfoblob, $removed);
             }
             if ($this->verbose) {
                 echo "\n";
             }
         }
     }
     return true;
 }
示例#28
0
文件: filelist.php 项目: Jay204/nZEDb
<?php

if (!$page->users->isLoggedIn()) {
    $page->show403();
}
if (isset($_GET["id"])) {
    $releases = new Releases(['Settings' => $page->settings]);
    $rel = $releases->getByGuid($_GET["id"]);
    if (!$rel) {
        $page->show404();
    }
    $nzb = new NZB($page->settings);
    $nzbpath = $nzb->getNZBPath($_GET["id"]);
    if (!file_exists($nzbpath)) {
        $page->show404();
    }
    $nzbfile = nzedb\utility\Utility::unzipGzipFile($nzbpath);
    $ret = $nzb->nzbFileList($nzbfile);
    $offset = isset($_REQUEST["offset"]) && ctype_digit($_REQUEST['offset']) ? $_REQUEST["offset"] : 0;
    $page->smarty->assign('pagertotalitems', sizeof($ret));
    $page->smarty->assign('pageroffset', $offset);
    $page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE);
    $page->smarty->assign('pagerquerybase', WWW_TOP . "/filelist/" . $_GET["id"] . "/&amp;offset=");
    $page->smarty->assign('pagerquerysuffix', "#results");
    $pager = $page->smarty->fetch("pager.tpl");
    $page->smarty->assign('pager', $pager);
    $page->smarty->assign('rel', $rel);
    $page->smarty->assign('files', array_slice($ret, $offset, ITEMS_PER_PAGE));
    $page->title = "File List";
    $page->meta_title = "View Nzb file list";
    $page->meta_keywords = "view,nzb,file,list,description,details";
示例#29
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."));
    }
}
示例#30
0
文件: getnzb.php 项目: nubzzz/newznab
<?php

require_once WWW_DIR . "/lib/releases.php";
require_once WWW_DIR . "/lib/nzb.php";
$nzb = new NZB();
$rel = new Releases();
$uid = 0;
//
// page is accessible only by the rss token, or logged in users.
//
if (!$users->isLoggedIn()) {
    if (!isset($_GET["i"]) || !isset($_GET["r"])) {
        $page->show403();
    }
    $res = $users->getByIdAndRssToken($_GET["i"], $_GET["r"]);
    if (!$res) {
        $page->show403();
    }
    $uid = $res["ID"];
} else {
    $uid = $users->currentUserId();
}
//
// remove any suffixed id with .nzb which is added to help
// weblogging programs see nzb traffic
//
if (isset($_GET["id"])) {
    $_GET["id"] = preg_replace("/\\.nzb/i", "", $_GET["id"]);
}
//
// user requested a zip of guid,guid,guid releases