Ejemplo n.º 1
0
 /**
  * Searches for tv shows based on show name
  *
  * @var string $showName the show name to search for
  * @access public
  * @return array An array of TV_Show objects matching the show name
  **/
 public static function search($showName)
 {
     $params = array('action' => 'search_tv_shows', 'show_name' => $showName);
     $data = TVRage::request($params);
     if ($data) {
         $xml = simplexml_load_string($data);
         $shows = array();
         foreach ($xml->show as $show) {
             $shows[] = new TV_Show($show);
         }
         return $shows;
     }
 }
Ejemplo n.º 2
0
 /**
  * Process all TV related releases which will assign their series/episode/rage data
  */
 public function processTv()
 {
     if ($this->pdo->getSetting('lookupanidb') == 1) {
         $anidb = new AniDB($this->echooutput);
         $anidb->animetitlesUpdate();
         $anidb->processAnimeReleases();
     }
     if ($this->pdo->getSetting('lookuptvrage') == 1) {
         $tvrage = new TVRage($this->echooutput);
         $tvrage->processTvReleases($this->pdo->getSetting('lookuptvrage') == 1);
     }
     if ($this->pdo->getSetting('lookupthetvdb') == 1) {
         $thetvdb = new TheTVDB($this->echooutput);
         $thetvdb->processReleases();
     }
 }
Ejemplo n.º 3
0
 public function update()
 {
     // update info + episodes from tvrage
     $tvrage = new TVRage();
     $tvrage->update($this);
     if ($this->tvdb_id == 0) {
         $this->findTVDB();
     }
     if ($this->tvdb_id != 0) {
         // get info from tvdb
         $tvdb = new TVDB();
         $tvdb->update($this);
     }
     // cache images
     $localStore = nzbVR::instance()->localStore;
     $shouldSave = false;
     if ($this->banner != null) {
         $localStore->storeImage("series/banners", TVDB::imageURL($this->banner));
         $shouldSave = true;
     }
     if ($this->poster != null) {
         $localStore->storeImage("series/poster", TVDB::imageURL($this->poster));
         $shouldSave = true;
     }
     if ($this->fanart != null) {
         $localStore->storeImage("series/fanart", TVDB::imageURL($this->fanart));
         $shouldSave = true;
     }
     if ($shouldSave) {
         $localStore->save();
     }
 }
Ejemplo n.º 4
0
<?php

//run this once per day
require "config.php";
require_once WWW_DIR . "/lib/tvrage.php";
$tvrage = new TVRage(true);
$tvrage->updateSchedule();
Ejemplo n.º 5
0
 function processReleases()
 {
     $db = new DB();
     $cat = new Category();
     $bin = new Binaries();
     $nzb = new Nzb();
     $s = new Sites();
     $relreg = new ReleaseRegex();
     $page = new Page();
     $nfo = new Nfo(true);
     $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;
     }
     $this->checkRegexesUptoDate($page->site->latestregexurl, $page->site->latestregexrevision, true);
     //
     // Get all regexes for all groups which are to be applied to new binaries
     // in order of how they should be applied
     //
     $regexrows = $relreg->get();
     foreach ($regexrows as $regexrow) {
         echo "Applying regex " . $regexrow["ID"] . " for group " . ($regexrow["groupname"] == "" ? "all" : $regexrow["groupname"]) . "\n";
         $groupmatch = "";
         //
         // Groups ending in * need to be like matched when getting out binaries for groups and children
         //
         if (preg_match("/\\*\$/i", $regexrow["groupname"])) {
             $groupname = substr($regexrow["groupname"], 0, -1);
             $resgrps = $db->query(sprintf("select ID from groups where name like %s ", $db->escapeString($groupname . "%")));
             foreach ($resgrps as $resgrp) {
                 $groupmatch .= " groupID = " . $resgrp["ID"] . " or ";
             }
             $groupmatch .= " 1=2 ";
         } elseif ($regexrow["groupname"] != "") {
             $resgrp = $db->queryOneRow(sprintf("select ID from groups where name = %s ", $db->escapeString($regexrow["groupname"])));
             //
             // if group not found, its a regex for a group we arent indexing.
             //
             if ($resgrp) {
                 $groupmatch = " groupID = " . $resgrp["ID"];
             } else {
                 $groupmatch = " 1=2 ";
             }
         } else {
             $groupmatch = " 1=1 ";
         }
         // Get current mysql time for date comparison checks in case php is in a different time zone
         $currTime = $db->queryOneRow("SELECT NOW() as now");
         // Get out all binaries of STAGE0 for current group
         $arrNoPartBinaries = array();
         $resbin = $db->queryDirect(sprintf("SELECT binaries.ID, binaries.name, binaries.date, binaries.totalParts from binaries where (%s) and procstat = %d order by binaries.date asc", $groupmatch, Releases::PROCSTAT_NEW));
         while ($rowbin = mysql_fetch_assoc($resbin)) {
             if (preg_match($regexrow["regex"], $rowbin["name"], $matches)) {
                 $matches = array_map("trim", $matches);
                 if (isset($matches['reqid']) && ctype_digit($matches['reqid']) && (!isset($matches['name']) || empty($matches['name']))) {
                     $matches['name'] = $matches['reqid'];
                 }
                 // Check that the regex provided the correct parameters
                 if (!isset($matches['name']) || empty($matches['name'])) {
                     echo "regex applied which didnt return right number of capture groups - " . $regexrow["regex"] . "\n";
                     print_r($matches);
                     continue;
                 }
                 // If theres no number of files data in the subject, put it into a release if it was posted to usenet longer than five hours ago.
                 if (!isset($matches['parts']) && strtotime($currTime['now']) - strtotime($rowbin['date']) > 18000 || isset($arrNoPartBinaries[$matches['name']])) {
                     //
                     // Take a copy of the name of this no-part release found. This can be used
                     // next time round the loop to find parts of this set, but which have not yet reached 3 hours.
                     //
                     $arrNoPartBinaries[$matches['name']] = "1";
                     $matches['parts'] = "01/01";
                 }
                 if (isset($matches['name']) && isset($matches['parts'])) {
                     if (strpos($matches['parts'], '/') === false) {
                         $matches['parts'] = str_replace(array('-', '~', ' of '), '/', $matches['parts']);
                     }
                     $regcatid = "null ";
                     if ($regexrow["categoryID"] != "") {
                         $regcatid = $regexrow["categoryID"];
                     }
                     $reqid = " null ";
                     if (isset($matches['reqid'])) {
                         $reqid = $matches['reqid'];
                     }
                     //check if post is repost
                     if (preg_match('/(repost\\d?|re\\-?up)/i', $rowbin['name'], $repost) && !preg_match('/repost|re\\-?up/i', $matches['name'])) {
                         $matches['name'] .= ' ' . $repost[1];
                     }
                     $relparts = explode("/", $matches['parts']);
                     $db->query(sprintf("update binaries set relname = replace(%s, '_', ' '), relpart = %d, reltotalpart = %d, procstat=%d, categoryID=%s, regexID=%d, reqID=%s where ID = %d", $db->escapeString($matches['name']), $relparts[0], $relparts[1], Releases::PROCSTAT_TITLEMATCHED, $regcatid, $regexrow["ID"], $reqid, $rowbin["ID"]));
                 }
             }
         }
     }
     //
     // Move all binaries from releases which have the correct number of files on to the next stage.
     //
     echo "Stage 2\n";
     $result = $db->queryDirect(sprintf("SELECT relname, 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, COUNT(ID) AS num FROM binaries     WHERE procstat = %s     GROUP BY relname, reltotalpart, groupID, reqID, fromname    ) 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", Releases::PROCSTAT_TITLEMATCHED));
     while ($row = mysql_fetch_assoc($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->query(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"]) {
             // Check that the binary is complete
             $binlist = $db->query(sprintf("SELECT ID, totalParts, date 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"])));
             $incomplete = false;
             foreach ($binlist as $rowbin) {
                 $binParts = $db->queryOneRow(sprintf("SELECT COUNT(ID) AS num FROM parts WHERE binaryID = %d", $rowbin['ID']));
                 if ($binParts['num'] < $rowbin['totalParts']) {
                     echo "binary " . $rowbin['ID'] . " from " . $row['relname'] . " has missing parts - " . $binParts['num'] . "/" . $rowbin['totalParts'] . " (" . number_format($binParts['num'] / $rowbin['totalParts'] * 100, 1) . "% complete)\n";
                     // 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['now']) - strtotime($rowbin['date']) > 14400) {
                         echo "allowing incomplete binary " . $rowbin['ID'] . "\n";
                     } else {
                         $incomplete = true;
                     }
                 }
             }
             if ($incomplete) {
                 echo "Incorrect number of parts " . $row["relname"] . "-" . $row["num"] . "-" . $row["reltotalpart"] . "\n";
                 $db->query(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['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"]));
                 echo "Looking up " . $row['reqID'] . " in " . $binGroup['name'] . "... ";
                 $newtitle = $this->getReleaseNameForReqId($page->site->reqidurl, $binGroup["name"], $row["reqID"], true);
                 //
                 // 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"];
                     echo "Group not supported\n";
                 }
                 //
                 // Valid release with right number of files and title now, so move it on
                 //
                 if ($newtitle != "") {
                     $db->query(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->query(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"])));
                         echo "Not found in 48 hours\n";
                     }
                 }
             } else {
                 $db->query(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"])));
             }
         } else {
             echo "Incorrect number of files for " . $row["relname"] . " (" . $row["num"] . "/" . $row["reltotalpart"] . ")\n";
             $db->query(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"])));
         }
         if ($retcount % 10 == 0) {
             echo "-processed " . $retcount . " binaries stage two\n";
         }
     }
     $retcount = $nfocount = 0;
     echo "Stage 3\n";
     //
     // Get out all distinct relname, group from binaries of STAGE2
     //
     $result = $db->queryDirect(sprintf("SELECT relname, groupID, g.name as group_name, fromname, count(binaries.ID) as parts 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 = mysql_fetch_assoc($result)) {
         $retcount++;
         //
         // Get the last post date and the poster name from the binary
         //
         $bindata = $db->queryOneRow(sprintf("select fromname, MAX(date) as date from binaries where relname = %s and procstat = %d and groupID = %d and fromname = %s group by fromname", $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
         //
         // Get all releases with the same name with a usenet posted date in a +1-1 date range.
         //
         $relDupes = $db->query(sprintf("select ID from releases where searchname = %s and (%s - INTERVAL 1 DAY < postdate AND %s + INTERVAL 1 DAY > postdate)", $db->escapeString($row["relname"]), $db->escapeString($bindata["date"]), $db->escapeString($bindata["date"])));
         if (count($relDupes) > 0) {
             $db->query(sprintf("update binaries set procstat = %d where relname = %s and procstat = %d and groupID = %d and fromname=%s ", Releases::PROCSTAT_DUPLICATE, $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
             continue;
         }
         //
         // Get total size of this release
         // Done in a big OR statement, not an IN as the mysql binaryID index on parts table
         // was not being used.
         //
         $totalSize = "0";
         $regexAppliedCategoryID = "";
         $regexIDused = "";
         $reqIDused = "";
         $relTotalParts = 0;
         $relCompletion = 0;
         $binariesForSize = $db->query(sprintf("select ID, categoryID, regexID, reqID, totalParts from binaries use index (ix_binary_relname) where relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"])));
         if (count($binariesForSize) > 0) {
             $sizeSql = "select sum(size) as totalSize, count(ID) as relParts from parts where (";
             foreach ($binariesForSize as $binSizeId) {
                 $sizeSql .= " binaryID = " . $binSizeId["ID"] . " or ";
                 //
                 // Get categoryID if one has been allocated to this
                 //
                 if ($binSizeId["categoryID"] != "" && $regexAppliedCategoryID == "") {
                     $regexAppliedCategoryID = $binSizeId["categoryID"];
                 }
                 //
                 // Get RegexID if one has been allocated to this
                 //
                 if ($binSizeId["regexID"] != "" && $regexIDused == "") {
                     $regexIDused = $binSizeId["regexID"];
                 }
                 //
                 // Get requestID if one has been allocated to this
                 //
                 if ($binSizeId["reqID"] != "" && $reqIDused == "") {
                     $reqIDused = $binSizeId["reqID"];
                 }
                 //
                 // Get number of expected parts
                 //
                 $relTotalParts += $binSizeId["totalParts"];
             }
             $sizeSql .= " 1=2) ";
             $temp = $db->queryOneRow($sizeSql);
             $totalSize = $temp["totalSize"] + 0 . "";
             $relCompletion = number_format($temp["relParts"] / $relTotalParts * 100, 1, '.', '');
         }
         //
         // Insert the release
         //
         $relguid = md5(uniqid());
         if ($regexAppliedCategoryID == "") {
             $catId = $cat->determineCategory($row["group_name"], $row["relname"]);
         } else {
             $catId = $regexAppliedCategoryID;
         }
         if ($regexIDused == "") {
             $regexID = " null ";
         } else {
             $regexID = $regexIDused;
         }
         if ($reqIDused == "") {
             $reqID = " null ";
         } else {
             $reqID = $reqIDused;
         }
         //Clean release name
         $cleanArr = array('#', '@', '$', '%', '^', '§', '¨', '©', 'Ö');
         $cleanRelName = str_replace($cleanArr, '', $row['relname']);
         $relid = $db->queryInsert(sprintf("insert into releases (name, searchname, totalpart, groupID, adddate, guid, categoryID, regexID, rageID, postdate, fromname, size, reqID, passwordstatus, completion) values (%s, %s, %d, %d, now(), %s, %d, %d, -1, %s, %s, %s, %s, %d, %f)", $db->escapeString($cleanRelName), $db->escapeString($cleanRelName), $row["parts"], $row["groupID"], $db->escapeString($relguid), $catId, $regexID, $db->escapeString($bindata["date"]), $db->escapeString($bindata["fromname"]), $totalSize, $reqID, $page->site->checkpasswordedrar == "1" ? -1 : 0, $relCompletion > 100 ? 100 : $relCompletion));
         echo "Added release " . $cleanRelName . "\n";
         //
         // Tag every binary for this release with its parent release id
         // remove the release name from the binary as its no longer required
         //
         $db->query(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"])));
         //
         // Find an .nfo in the release
         //
         $relnfo = $nfo->determineReleaseNfo($relid);
         if ($relnfo !== false) {
             $nfo->addReleaseNfo($relid, $relnfo['ID']);
             $nfocount++;
         }
         //
         // Write the nzb to disk
         //
         $nzb->writeNZBforReleaseId($relid, $relguid, $cleanRelName, $catId, $nzb->getNZBPath($relguid, $page->site->nzbpath, true));
         if ($retcount % 5 == 0) {
             echo "-processed " . $retcount . " releases stage three\n";
         }
     }
     echo "Found " . $nfocount . " nfos in " . $retcount . " releases\n";
     //
     // Process nfo files
     //
     if ($page->site->lookupnfo != "1") {
         echo "Site config (site.lookupnfo) prevented retrieving nfos\n";
     } else {
         $nfo->processNfoFiles($page->site->lookupimdb, $page->site->lookuptvrage == "1");
     }
     //
     // Lookup imdb if enabled
     //
     if ($page->site->lookupimdb == 1) {
         $movie = new Movie(true);
         $movie->processMovieReleases();
     }
     //
     // Lookup music if enabled
     //
     if ($page->site->lookupmusic == 1) {
         $music = new Music(true);
         $music->processMusicReleases();
     }
     //
     // Lookup games if enabled
     //
     if ($page->site->lookupgames == 1) {
         $console = new Console(true);
         $console->processConsoleReleases();
     }
     //
     // Check for passworded releases
     //
     if ($page->site->checkpasswordedrar != "1") {
         echo "Site config (site.checkpasswordedrar) prevented checking releases are passworded\n";
     } else {
         $this->processPasswordedReleases(true);
     }
     //
     // Process all TV related releases which will assign their series/episode/rage data
     //
     $tvrage = new TVRage(true);
     $tvrage->processTvReleases($page->site->lookuptvrage == "1");
     //
     // Get the current datetime again, as using now() in the housekeeping queries prevents the index being used.
     //
     $currTime = $db->queryOneRow("SELECT NOW() as now");
     //
     // Tidy away any binaries which have been attempted to be grouped into
     // a release more than x times
     //
     echo "Tidying away binaries which cant be grouped after " . $page->site->attemptgroupbindays . " days\n";
     $db->query(sprintf("update binaries set procstat = %d where procstat = %d and dateadded < %s - interval %d day ", Releases::PROCSTAT_WRONGPARTS, Releases::PROCSTAT_NEW, $db->escapeString($currTime["now"]), $page->site->attemptgroupbindays));
     //
     // Delete any parts and binaries which are older than the site's retention days
     //
     echo "Deleting parts which are older than " . $page->site->rawretentiondays . " days\n";
     $db->query(sprintf("delete from parts where dateadded < %s - interval %d day", $db->escapeString($currTime["now"]), $page->site->rawretentiondays));
     echo "Deleting binaries which are older than " . $page->site->rawretentiondays . " days\n";
     $db->query(sprintf("delete from binaries where dateadded < %s - interval %d day", $db->escapeString($currTime["now"]), $page->site->rawretentiondays));
     //
     // Delete any releases which are older than site's release retention days
     //
     if ($page->site->releaseretentiondays != 0) {
         echo "Determining any releases past retention to be deleted.\n\n";
         $result = $db->query(sprintf("select ID from releases where postdate < %s - interval %d day", $db->escapeString($currTime["now"]), $page->site->releaseretentiondays));
         foreach ($result as $row) {
             $this->delete($row["ID"]);
         }
     }
     echo "Processed " . $retcount . " releases\n\n";
     return $retcount;
 }
Ejemplo n.º 6
0
 public function processTv()
 {
     if ($this->site->lookuptvrage == 1) {
         $tvrage = new TVRage($this->echooutput);
         $tvrage->processTvReleases($this->site->lookuptvrage == 1);
     }
 }
Ejemplo n.º 7
0
 /**
  * Get a specific episode by season and episode number
  *
  * @var int $season required the season number
  * @var int $episode required the episode number
  * @return TV_Episode
  **/
 public function getEpisode($season, $episode)
 {
     $params = array('action' => 'get_episode', 'season' => (int) $season, 'episode' => (int) $episode, 'show_id' => $this->showId);
     $data = TVRage::request($params);
     if ($data) {
         $xml = simplexml_load_string($data);
         return new TV_Episode($xml->episode);
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 public function search()
 {
     $name = urldecode($this->route()->getSegment(0));
     $tvrage = new TVRage();
     $results = $tvrage->search($name);
     $this->series = $results;
 }