$name = $_FILES["uploadedfiles"]["name"][$key]; $filestoprocess[] = $tmp_name; $browserpostednames[$tmp_name] = $name; } } } $groups = $db->query("SELECT ID, name FROM groups"); foreach ($groups as $group) { $siteGroups[$group["name"]] = $group["ID"]; } if (!isset($groups) || count($groups) == 0) { $retval .= "no groups available in the database, add first.<br/>"; } else { foreach ($filestoprocess as $nzbFile) { $nzbInfo = new nzbInfo(); if (!$nzbInfo->loadFromFile($nzbFile, true)) { $retval .= "Failed to load NZB : " . $browserpostednames[$nzbFile] . "<br/>"; continue; } else { $dupes = $db->queryOneRow(sprintf("SELECT EXISTS(SELECT 1 FROM releases WHERE gid = %s) as total", $db->escapeString($nzbInfo->gid))); if ($dupes['total'] > 0) { $retval .= "Duplicate NZB : " . $browserpostednames[$nzbFile] . "<br/>"; continue; } else { $groupID = -1; foreach ($nzbInfo->groups as $group) { $group = (string) $group; if (array_key_exists($group, $siteGroups)) { $groupID = $siteGroups[$group]; $groupName = $group; break;
/** * 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"; } }
/** * 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"; } }
<?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);
function processReleases() { require_once WWW_DIR . "/lib/binaries.php"; $db = new DB(); $currTime_ori = $db->queryOneRow("SELECT NOW() as now"); $cat = new Category(); $nzb = new Nzb(); $s = new Sites(); $releaseRegex = new ReleaseRegex(); $page = new Page(); $groups = new Groups(); $retcount = 0; echo $s->getLicense(); echo "\n\nStarting release update process (" . date("Y-m-d H:i:s") . ")\n"; if (!file_exists($page->site->nzbpath)) { echo "Bad or missing nzb directory - " . $page->site->nzbpath; return -1; } // // Get all regexes for all groups which are to be applied to new binaries // in order of how they should be applied // $releaseRegex->get(); echo "Stage 1 : Applying regex to binaries\n"; $activeCategories = $cat->get(); $catbasedsizes = $db->getLookupAsArray($activeCategories, "ID"); $activeGroups = $groups->getActive(false); $groupbasedminsizes = $db->getLookupAsArray($groups->getAllNoReleases(), "ID"); foreach ($activeGroups as $groupArr) { //check if regexes have already been applied during update binaries if ($groupArr['regexmatchonly'] == 1) { continue; } $groupRegexes = $releaseRegex->getForGroup($groupArr['name']); echo "Stage 1 : Applying " . sizeof($groupRegexes) . " regexes to group " . $groupArr['name'] . "\n"; // Get out all binaries of STAGE0 for current group $newUnmatchedBinaries = array(); $ressql = sprintf("SELECT binaries.ID, binaries.name, binaries.date, binaries.totalParts, binaries.procstat, binaries.fromname from binaries where groupID = %d and procstat IN (%d,%d) and regexID IS NULL order by binaries.date asc", $groupArr['ID'], Releases::PROCSTAT_NEW, Releases::PROCSTAT_TITLENOTMATCHED); $resbin = $db->queryDirect($ressql); $matchedbins = 0; while ($rowbin = $db->getAssocArray($resbin)) { $regexMatches = array(); foreach ($groupRegexes as $groupRegex) { $regexCheck = $releaseRegex->performMatch($groupRegex, $rowbin['name']); if ($regexCheck !== false) { $regexMatches = $regexCheck; break; } } if (!empty($regexMatches)) { $matchedbins++; $relparts = explode("/", $regexMatches['parts']); $db->exec(sprintf("update binaries set relname = replace(%s, '_', ' '), relpart = %d, reltotalpart = %d, procstat=%d, categoryID=%s, regexID=%d, reqID=%s where ID = %d", $db->escapeString($regexMatches['name']), $relparts[0], $relparts[1], Releases::PROCSTAT_TITLEMATCHED, $regexMatches['regcatid'], $regexMatches['regexID'], $db->escapeString($regexMatches['reqID']), $rowbin["ID"])); } else { if ($rowbin['procstat'] == Releases::PROCSTAT_NEW) { $newUnmatchedBinaries[] = $rowbin['ID']; } } } //mark as not matched if (!empty($newUnmatchedBinaries)) { $db->exec(sprintf("update binaries set procstat=%d where ID IN (%s)", Releases::PROCSTAT_TITLENOTMATCHED, implode(',', $newUnmatchedBinaries))); } } // // Move all binaries from releases which have the correct number of files on to the next stage. // echo "Stage 2 : Marking binaries where all parts are available"; $result = $db->queryDirect(sprintf("SELECT relname, date, SUM(reltotalpart) AS reltotalpart, groupID, reqID, fromname, SUM(num) AS num, coalesce(g.minfilestoformrelease, s.minfilestoformrelease) as minfilestoformrelease FROM ( SELECT relname, reltotalpart, groupID, reqID, fromname, max(date) as date, COUNT(ID) AS num FROM binaries WHERE procstat = %s GROUP BY relname, reltotalpart, groupID, reqID, fromname ORDER BY NULL ) x left outer join groups g on g.ID = x.groupID inner join ( select value as minfilestoformrelease from site where setting = 'minfilestoformrelease' ) s GROUP BY relname, groupID, reqID, fromname, minfilestoformrelease ORDER BY NULL", Releases::PROCSTAT_TITLEMATCHED)); while ($row = $db->getAssocArray($result)) { $retcount++; // // Less than the site permitted number of files in a release. Dont discard it, as it may // be part of a set being uploaded. // if ($row["num"] < $row["minfilestoformrelease"]) { //echo "Number of files in release ".$row["relname"]." less than site/group setting (".$row['num']."/".$row["minfilestoformrelease"].")\n"; //$db->exec(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname = %s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]) )); } elseif ($row["num"] >= $row["reltotalpart"]) { $incomplete = false; if ($row['reltotalpart'] == 0 && strtotime($currTime_ori['now']) - strtotime($row['date']) < 14400) { $incomplete = true; } else { // Check that the binary is complete $binlist = $db->query(sprintf("SELECT binaries.ID, totalParts, date, COUNT(DISTINCT parts.messageID) AS num FROM binaries, parts WHERE binaries.ID=parts.binaryID AND binaries.relname = %s AND binaries.procstat = %d AND binaries.groupID = %d AND binaries.fromname = %s GROUP BY binaries.ID ORDER BY NULL", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); foreach ($binlist as $rowbin) { if ($rowbin['num'] < $rowbin['totalParts']) { // Allow to binary to release if posted to usenet longer than four hours ago and we still don't have all the parts if (!(strtotime($currTime_ori['now']) - strtotime($rowbin['date']) > 14400)) { $incomplete = true; break; } } } } if (!$incomplete) { // // Right number of files, but see if the binary is a allfilled/reqid post, in which case it needs its name looked up // if ($row['reqID'] != '' && $page->site->reqidurl != "") { // // Try and get the name using the group // $binGroup = $db->queryOneRow(sprintf("SELECT name FROM groups WHERE ID = %d", $row["groupID"])); $newtitle = $this->getReleaseNameForReqId($page->site->reqidurl, $page->site->newznabID, $binGroup["name"], $row["reqID"]); // // if the feed/group wasnt supported by the scraper, then just use the release name as the title. // if ($newtitle == "no feed") { $newtitle = $row["relname"]; } // // Valid release with right number of files and title now, so move it on // if ($newtitle != "") { $db->exec(sprintf("update binaries set relname = %s, procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($newtitle), Releases::PROCSTAT_READYTORELEASE, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); } else { // // Item not found, if the binary was added to the index yages ago, then give up. // $maxaddeddate = $db->queryOneRow(sprintf("SELECT NOW() as now, MAX(dateadded) as dateadded FROM binaries WHERE relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); // // If added to the index over 48 hours ago, give up trying to determine the title // if (strtotime($maxaddeddate['now']) - strtotime($maxaddeddate['dateadded']) > 60 * 60 * 48) { $db->exec(sprintf("update binaries set procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", Releases::PROCSTAT_NOREQIDNAMELOOKUPFOUND, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); } } } else { $db->exec(sprintf("update binaries set procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", Releases::PROCSTAT_READYTORELEASE, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); } } } if ($retcount % 100 == 0) { echo "."; } } $retcount = 0; echo "\nStage 3 : Creating releases from complete binaries\n"; // // Get out all distinct relname, group from binaries of STAGE2 // $result = $db->queryDirect(sprintf("SELECT relname, groupID, g.name as group_name, fromname, max(categoryID) as categoryID, max(regexID) as regexID, max(reqID) as reqID, MAX(date) as date, count(binaries.ID) as parts, coalesce(sum(binaries.size),0) as size from binaries inner join groups g on g.ID = binaries.groupID where procstat = %d and relname is not null group by relname, g.name, groupID, fromname ORDER BY COUNT(binaries.ID) desc", Releases::PROCSTAT_READYTORELEASE)); while ($row = $db->getAssocArray($result)) { $relguid = md5(uniqid()); // // Get categoryID if one has been allocated to this // if ($row["categoryID"] != "") { $catId = $row["categoryID"]; } else { $catId = $cat->determineCategory($row["group_name"], $row["relname"]); } // // Determine if size matches permitted boundaries and discard here if not. // $gsize = $groupbasedminsizes[$row["groupID"]][0]["minsizetoformrelease"]; if ($gsize == "" || $gsize == 0) { $gsize = $row["size"]; } $ssize = $page->site->minsizetoformrelease; if ($ssize == "" || $ssize == 0) { $ssize = $row["size"]; } $csize = $catbasedsizes[$catId][0]["minsizetoformrelease"]; if ($csize == "" || $csize == 0) { $csize = $row["size"]; } $cpsize = $catbasedsizes[$catId][0]["parentminsizetoformrelease"]; if ($cpsize == "" || $cpsize == 0) { $cpsize = $row["size"]; } $cmaxsize = $catbasedsizes[$catId][0]["maxsizetoformrelease"]; if ($cmaxsize == "" || $cmaxsize == 0) { $cmaxsize = $row["size"]; } $cpmaxsize = $catbasedsizes[$catId][0]["parentmaxsizetoformrelease"]; if ($cpmaxsize == "" || $cpmaxsize == 0) { $cpmaxsize = $row["size"]; } $overallminsize = max($gsize, $ssize, $csize, $cpsize); $overallmaxsize = min($cmaxsize, $cpmaxsize); if ($row["size"] < $overallminsize || $row["size"] > $overallmaxsize) { echo sprintf("Stage 3 : Discarding - %s (Size %s outside permitted range of %s%s)\n", $row["relname"], formatBytes($row["size"]), $overallminsize != $row["size"] ? formatBytes($overallminsize) : "", $overallmaxsize != $row["size"] ? formatBytes($overallmaxsize) : ""); $db->exec(sprintf("DELETE parts, binaries FROM parts JOIN binaries ON binaries.ID = parts.binaryID WHERE relname=%s and groupID=%d and fromname=%s and procstat=%d", $db->escapeString($row["relname"]), $row["groupID"], $db->escapeString($row["fromname"]), Releases::PROCSTAT_READYTORELEASE)); } else { // Clean release name $cleanRelName = $this->cleanReleaseName($row['relname']); $relid = $this->insertRelease($cleanRelName, $row["parts"], $row["groupID"], $relguid, $catId, $row["regexID"], $row["date"], $row["fromname"], $row["reqID"], $page->site); // // Tag every binary for this release with its parent release id // $db->exec(sprintf("update binaries set procstat = %d, releaseID = %d where relname = %s and procstat = %d and groupID = %d and fromname=%s", Releases::PROCSTAT_RELEASED, $relid, $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"]))); // // Write the nzb to disk // $nzbfile = $nzb->getNZBPath($relguid, $page->site->nzbpath, true); $nzb->writeNZBforReleaseId($relid, $cleanRelName, $catId, $nzbfile); // // Remove used binaries // $db->exec(sprintf("DELETE parts, binaries FROM parts JOIN binaries ON binaries.ID = parts.binaryID WHERE releaseID = %d ", $relid)); // // If nzb successfully written, then load it and get size completion from it // $nzbInfo = new nzbInfo(); if (!$nzbInfo->loadFromFile($nzbfile)) { echo "Stage 3 : Failed to write nzb file (bad perms?) " . $nzbfile . "\n"; //copy($nzbfile, "./ERRORNZB_".$relguid); $this->delete($relid); } else { // Check if gid already exists $dupes = $db->queryOneRow(sprintf("SELECT EXISTS(SELECT 1 FROM releases WHERE gid = %s) as total", $db->escapeString($nzbInfo->gid))); if ($dupes['total'] > 0) { echo "Stage 3 : Duplicate - " . $cleanRelName . " -" . $nzbInfo->gid . "-\n"; $this->delete($relid); } else { $db->exec(sprintf("update releases set totalpart = %d, size = %s, completion = %d, GID=%s where ID = %d", $nzbInfo->filecount, $nzbInfo->filesize, $nzbInfo->completion, $db->escapeString($nzbInfo->gid), $relid)); echo "Stage 3 : Added release " . $cleanRelName . "\n"; //Increment new release count $retcount++; } } } } // // Delete any releases under the minimum completion percent. // if ($page->site->completionpercent != 0) { echo "Stage 4 : Deleting releases less than " . $page->site->completionpercent . " complete\n"; $result = $db->query(sprintf("select ID from releases where completion > 0 and completion < %d", $page->site->completionpercent)); foreach ($result as $row) { $this->delete($row["ID"]); } } /* *Potentially leave this in to mop up release when the cat sizes change. // // Delete releases whos minsize is less than the site or group minimum // $result = $db->query("select releases.ID from releases left outer join (SELECT g.ID, coalesce(g.minsizetoformrelease, s.minsizetoformrelease) as minsizetoformrelease FROM groups g inner join ( select value as minsizetoformrelease from site where setting = 'minsizetoformrelease' ) s ) x on x.ID = releases.groupID where minsizetoformrelease != 0 and releases.size < minsizetoformrelease"); if (count($result) > 0) { echo "Stage 4 : Deleting ".count($result)." release(s) where size is smaller than minsize for site/group\n"; foreach ($result as $row) $this->delete($row["ID"]); } $result = $db->query("select releases.ID, name, categoryID, size FROM releases JOIN ( select catc.ID, case when catc.minsizetoformrelease = 0 then catp.minsizetoformrelease else catc.minsizetoformrelease end as minsizetoformrelease, case when catc.maxsizetoformrelease = 0 then catp.maxsizetoformrelease else catc.maxsizetoformrelease end as maxsizetoformrelease from category catp join category catc on catc.parentID = catp.ID where (catc.minsizetoformrelease != 0 or catc.maxsizetoformrelease != 0) or (catp.minsizetoformrelease != 0 or catp.maxsizetoformrelease != 0) ) x on x.ID = releases.categoryID where (size < minsizetoformrelease and minsizetoformrelease != 0) or (size > maxsizetoformrelease and maxsizetoformrelease != 0)"); if(count($result) > 0) { echo "Stage 4 : Deleting release(s) not matching category min/max size ...\n"; foreach ($result as $r){ $this->delete($r['ID']); } } */ echo "Stage 5 : Post processing started\n"; $postprocess = new PostProcess(true); $postprocess->processAll(); // // aggregate the releasefiles upto the releases. // echo "Stage 6 : Aggregating Files\n"; $db->exec("update releases INNER JOIN (SELECT releaseID, COUNT(ID) AS num FROM releasefiles GROUP BY releaseID) b ON b.releaseID = releases.ID and releases.rarinnerfilecount = 0 SET rarinnerfilecount = b.num"); // Remove the binaries and parts used to form releases, or that are duplicates. // if ($page->site->partsdeletechunks > 0) { echo "Stage 7 : Chunk deleting unused binaries and parts"; $query = sprintf("SELECT parts.ID as partsID,binaries.ID as binariesID FROM parts\r\n\t\t\t\t\t\tLEFT JOIN binaries ON binaries.ID = parts.binaryID\r\n\t\t\t\t\t\tWHERE binaries.dateadded < %s - INTERVAL %d HOUR LIMIT 0,%d", $db->escapeString($currTime_ori["now"]), ceil($page->site->rawretentiondays * 24), $page->site->partsdeletechunks); $cc = 0; $done = false; while (!$done) { $dd = $cc; $result = $db->query($query); if (count($result) > 0) { $pID = array(); $bID = array(); foreach ($result as $row) { $pID[] = $row['partsID']; $bID[] = $row['binariesID']; } $pID = '(' . implode(',', $pID) . ')'; $bID = '(' . implode(',', $bID) . ')'; $fr = $db->exec("DELETE FROM parts WHERE ID IN {$pID}"); if ($fr > 0) { $cc += $fr; $cc += $db->exec("DELETE FROM binaries WHERE ID IN {$bID}"); } unset($pID); unset($bID); if ($cc == $dd) { $done = true; } echo $cc % 10000 ? '.' : ''; } else { $done = true; } } echo "\nStage 7 : Complete - " . $cc . " rows affected\n"; } else { echo "Stage 7 : Deleting unused binaries and parts\n"; $db->exec(sprintf("DELETE parts, binaries FROM parts JOIN binaries ON binaries.ID = parts.binaryID\r\n\t\t\tWHERE binaries.dateadded < %s - INTERVAL %d HOUR", $db->escapeString($currTime_ori["now"]), ceil($page->site->rawretentiondays * 24))); } // // User/Request housekeeping, should ideally move this to its own section, but it needs to be done automatically. // $users = new Users(); $users->pruneRequestHistory($page->site->userdownloadpurgedays); echo "Done : Added " . $retcount . " releases\n\n"; return $retcount; }