Ejemplo n.º 1
0
 /**
  * Get a URL or file image and convert it to string.
  *
  * @param string $imgLoc URL or file location.
  *
  * @return bool|mixed|string
  */
 protected function fetchImage($imgLoc)
 {
     $img = false;
     if (strpos(strtolower($imgLoc), 'http:') === 0 || strpos(strtolower($imgLoc), 'https:') === 0) {
         $img = Utility::getUrl(['url' => $imgLoc]);
     } else {
         if (is_file($imgLoc)) {
             $img = @file_get_contents($imgLoc);
         }
     }
     if ($img !== false) {
         $im = @imagecreatefromstring($img);
         if ($im !== false) {
             imagedestroy($im);
             return $img;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Download JSON from Trakt, convert to array.
  *
  * @param string $URI URI to download.
  * @param string $extended Extended info from trakt tv.
  *                         Valid values:
  *                         'min'         Returns enough info to match locally. (Default)
  *                         'images'      Minimal info and all images.
  *                         'full'        Complete info for an item.
  *                         'full,images' Complete info and all images.
  *
  * @return bool|mixed
  */
 private function getJsonArray($URI, $extended = 'min')
 {
     if (!empty($this->clientID)) {
         $json = Utility::getUrl(['url' => $URI . "?extended={$extended}", 'requestheaders' => $this->requestHeaders]);
         if ($json !== false) {
             $json = json_decode($json, true);
             if (!is_array($json) || isset($json['status']) && $json['status'] === 'failure') {
                 return false;
             }
             return $json;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * @param $seriesid
  * @param $seriesName
  *
  * @return array|bool
  */
 public function TheTVDBAPI($seriesid, $seriesName)
 {
     $apiresponse = Utility::getUrl([$this->MIRROR . '/api/' . self::APIKEY . '/series/' . $seriesid . '/all/en.xml']);
     //.zip?
     if (!$apiresponse) {
         return false;
     }
     $TheTVDBAPIXML = @simplexml_load_string($apiresponse);
     if (!$TheTVDBAPIXML) {
         return false;
     }
     foreach ($TheTVDBAPIXML->Episode as $episode) {
         $episodetvdbIDArray[] = (int) $episode->id;
         $episodenumberArray[] = (int) $episode->Combined_episodenumber;
         $episodeseasonArray[] = (int) $episode->Combined_season;
         $episodedirectorArray[] = preg_replace('/^\\||\\|$/', '', (string) $episode->Director);
         $episodenameArray[] = preg_replace('/^\\||\\|$/', '', (string) $episode->EpisodeName);
         $episodefirstairedArray[] = (string) $episode->FirstAired;
         $episodegueststarsArray[] = preg_replace('/^\\||\\|$/', '', (string) $episode->GuestStars);
         $episodeimdbID[] = str_replace('tt', '', (string) $episode->IMDB_ID);
         $episodeoverviewArray[] = preg_replace('/^\\||\\|$/', '', (string) $episode->Overview);
         $episoderatingArray[] = preg_replace('/^\\||\\|$/', '', (string) $episode->Rating);
         $episodewriterArray[] = preg_replace('/^\\||\\|$/', '', (string) $episode->Writer);
         $episodeabsolutenumberArray[] = (int) $episode->absolute_number;
     }
     $TheTVDBAPIArray = array('tvdbid' => $seriesid, 'actors' => preg_replace('/^\\||\\|$/', '', (string) $TheTVDBAPIXML->Series->Actors), 'airsday' => preg_replace('/^\\||\\|$/', '', (string) $TheTVDBAPIXML->Series->Airs_DayOfWeek), 'airstime' => preg_replace('/^\\||\\|$/', '', (string) $TheTVDBAPIXML->Series->Airs_Time), 'contentrating' => (string) $TheTVDBAPIXML->Series->ContentRating, 'firstaired' => (string) $TheTVDBAPIXML->Series->FirstAired, 'genre' => preg_replace('/^\\||\\|$/', '', (string) $TheTVDBAPIXML->Series->Genre), 'imdbid' => (int) preg_replace('/^[^\\d]+/', '', (string) $TheTVDBAPIXML->Series->IMDB_ID), 'network' => (string) $TheTVDBAPIXML->Series->Network, 'overview' => (string) $TheTVDBAPIXML->Series->Overview, 'rating' => (double) $TheTVDBAPIXML->Series->Rating, 'ratingcount' => (int) $TheTVDBAPIXML->Series->RatingCount, 'runtime' => (int) $TheTVDBAPIXML->Series->Runtime, 'seriesname' => $seriesName, 'status' => (string) $TheTVDBAPIXML->Series->Status, 'episodetvdbID' => isset($episodetvdbIDArray) ? $episodetvdbIDArray : [], 'episodenumber' => isset($episodenumberArray) ? $episodenumberArray : [], 'episodeseason' => isset($episodeseasonArray) ? $episodeseasonArray : [], 'episodedirector' => isset($episodedirectorArray) ? $episodedirectorArray : [], 'episodename' => isset($episodenameArray) ? $episodenameArray : [], 'episodefirstaired' => isset($episodefirstairedArray) ? $episodefirstairedArray : [], 'episodegueststars' => isset($episodegueststarsArray) ? $episodegueststarsArray : [], 'episodeimdbID' => isset($episodeimdbID) ? $episodeimdbID : [], 'episodeoverview' => isset($episodeoverviewArray) ? $episodeoverviewArray : [], 'episoderating' => isset($episoderatingArray) ? $episoderatingArray : [], 'episodewriter' => isset($episodewriterArray) ? $episodewriterArray : [], 'episodeabsolutenumber' => isset($episodeabsolutenumberArray) ? $episodeabsolutenumberArray : []);
     return $TheTVDBAPIArray;
 }
Ejemplo n.º 4
0
 /**
  * @param $url
  * @param $nnid
  * @param $groupname
  * @param $reqid
  *
  * @return string
  */
 public function getReleaseNameForReqId($url, $nnid, $groupname, $reqid)
 {
     if ($reqid == " null " || $reqid == "0" || $reqid == "") {
         return "";
     }
     $url = str_ireplace("[GROUP]", urlencode($groupname), $url);
     $url = str_ireplace("[REQID]", urlencode($reqid), $url);
     if ($nnid != "") {
         $url = $url . "&newznabID=" . $nnid;
     }
     $xml = Utility::getUrl([$url]);
     if ($xml === false || preg_match('/no feed/i', $xml)) {
         return "no feed";
     } else {
         if ($xml != "") {
             $xmlObj = @simplexml_load_string($xml);
             $arrXml = objectsIntoArray($xmlObj);
             if (isset($arrXml["item"]) && is_array($arrXml["item"])) {
                 foreach ($arrXml["item"] as $item) {
                     $title = array_key_exists("@attributes", $item) ? $item["@attributes"]["title"] : $item["title"];
                     return $title;
                 }
             }
         }
     }
     return "";
 }
Ejemplo n.º 5
0
 /**
  * Request for current status (summary) information. Parts of informations returned by this method can be printed by command "nzbget -L".
  *
  * @return array The status.
  *
  * @access public
  */
 public function status()
 {
     $data = Utility::getUrl(['url' => $this->fullURL . 'status', 'verifycert' => false]);
     $retVal = false;
     if ($data) {
         $xml = simplexml_load_string($data);
         if ($xml) {
             foreach ($xml->params->param->value->struct->member as $member) {
                 $value = (array) $member->value;
                 $value = array_shift($value);
                 if (!is_object($value)) {
                     $retVal[(string) $member->name] = $value;
                 }
             }
         }
     }
     return $retVal;
 }
Ejemplo n.º 6
0
 /**
  * Make a request to RT.
  *
  * @param string  $function The type of request.
  * @param array   $params   Extra HTTP parameters.
  *
  * @return string JSON data from RT.
  */
 private function _makeCall($function, $params = [])
 {
     return trim(Utility::getUrl(['url' => RottenTomato::API_URL . $function . '?limit=' . mt_rand(15, 20) . '&apikey=' . $this->_apikey . (!empty($params) ? '&' . http_build_query($params) : '')]));
 }
Ejemplo n.º 7
0
 /**
  * Fetches an embeddable video to a IMDB trailer from http://www.traileraddict.com
  *
  * @param $imdbID
  *
  * @return string
  */
 public static function imdb_trailers($imdbID)
 {
     $xml = Utility::getUrl(['http://api.traileraddict.com/?imdb=' . $imdbID]);
     if ($xml !== false) {
         if (preg_match('/(<iframe.+?<\\/iframe>)/i', $xml, $html)) {
             return $html[1];
         }
     }
     return '';
 }
Ejemplo n.º 8
0
 /**
  * Resume all NZB's in the SAB queue.
  *
  * @return bool|mixed
  */
 public function resumeAll()
 {
     return Utility::getUrl([$this->url . "api?mode=resume" . "&apikey=" . $this->apikey, 'verifypeer' => false]);
 }
Ejemplo n.º 9
0
 /**
  * Fetches an embeddable video to a IMDB trailer from http://www.traileraddict.com
  *
  * @param $imdbID
  *
  * @return string
  */
 public static function imdb_trailers($imdbID)
 {
     $xml = Utility::getUrl(['url' => 'http://api.traileraddict.com/?imdb=' . $imdbID]);
     if ($xml !== false) {
         if (preg_match('#(v\\.traileraddict\\.com/\\d+)#i', $xml, $html)) {
             return 'https://' . $html[1];
         }
     }
     return '';
 }
Ejemplo n.º 10
0
 /**
  * Process releases for requestid's.
  *
  * @return int How many did we rename?
  */
 protected function _processReleases()
 {
     // Array to store results.
     $requestArray = [];
     if ($this->_releases instanceof \Traversable) {
         // Loop all the results.
         foreach ($this->_releases as $release) {
             $this->_release['name'] = $release['name'];
             // Try to find a request id for the release.
             $requestId = $this->_siftReqId();
             // If there's none, update the release and continue.
             if ($requestId === self::REQID_ZERO) {
                 $this->_requestIdNotFound($release['id'], self::REQID_NONE);
                 if ($this->echoOutput) {
                     echo '-';
                 }
                 continue;
             }
             // Change etc to teevee.
             if ($release['groupname'] === 'alt.binaries.etc') {
                 $release['groupname'] = 'alt.binaries.teevee';
             }
             // Send the release id so we can track the return data.
             $requestArray[$release['id']] = array('reqid' => $requestId, 'ident' => $release['id'], 'group' => $release['groupname'], 'sname' => $release['searchname']);
         }
     }
     // Check if we requests to send to the web.
     if (count($requestArray) < 1) {
         return 0;
     }
     // Mock array for isset check on server.
     $requestArray[0] = ['ident' => 0, 'group' => 'none', 'reqid' => 0];
     // Do a web lookup.
     $returnXml = Utility::getUrl(['url' => $this->pdo->getSetting('request_url'), 'method' => 'post', 'postdata' => 'data=' . serialize($requestArray), 'verifycert' => false]);
     $renamed = 0;
     // Change the release titles and insert the PRE's if they don't exist.
     if ($returnXml !== false) {
         $returnXml = @simplexml_load_string($returnXml);
         if ($returnXml !== false) {
             // Store the returned identifiers so we can check which releases we didn't find a request id.
             $returnedIdentifiers = [];
             $groupIDArray = [];
             foreach ($returnXml->request as $result) {
                 if (isset($result['name']) && isset($result['ident']) && (int) $result['ident'] > 0) {
                     $this->_newTitle['title'] = (string) $result['name'];
                     $this->_requestID = (int) $result['reqid'];
                     $this->_release['id'] = (int) $result['ident'];
                     // Buffer groupid queries.
                     $this->_release['groupname'] = $requestArray[(int) $result['ident']]['group'];
                     if (isset($groupIDarray[$this->_release['groupname']])) {
                         $this->_release['groupid'] = $groupIDArray[$this->_release['groupname']];
                     } else {
                         $this->_release['groupid'] = $this->groups->getIDByName($this->_release['groupname']);
                         $groupIDArray[$this->_release['groupname']] = $this->_release['groupid'];
                     }
                     $this->_release['gid'] = $this->_release['groupid'];
                     $this->_release['searchname'] = $requestArray[(int) $result['ident']]['sname'];
                     $this->_insertIntoPreDB();
                     if ($this->_preDbID === false) {
                         $this->_preDbID = 0;
                     }
                     $this->_newTitle['id'] = $this->_preDbID;
                     $this->_updateRelease();
                     $renamed++;
                     if ($this->echoOutput) {
                         echo '+';
                     }
                     $returnedIdentifiers[] = (string) $result['ident'];
                 }
             }
             // Check if the WEB didn't send back some titles, update the release.
             if (count($returnedIdentifiers) > 0) {
                 foreach ($returnedIdentifiers as $identifier) {
                     if (array_key_exists($identifier, $requestArray)) {
                         unset($requestArray[$identifier]);
                     }
                 }
             }
             unset($requestArray[0]);
             foreach ($requestArray as $request) {
                 $addDate = $this->pdo->queryOneRow(sprintf('SELECT UNIX_TIMESTAMP(adddate) AS adddate FROM releases WHERE id = %d', $request['ident']));
                 $status = self::REQID_NONE;
                 if ($addDate !== false && !empty($addDate['adddate'])) {
                     if ((bool) (intval((time() - (int) $addDate['adddate']) / 3600) > $this->_request_hours)) {
                         $status = self::REQID_OLD;
                     }
                 } else {
                     $status = self::REQID_OLD;
                 }
                 $this->_requestIdNotFound($request['ident'], $status);
                 if ($this->echoOutput) {
                     echo '-';
                 }
             }
         }
     }
     return $renamed;
 }
Ejemplo n.º 11
0
 /**
  * Process all untagged movies to link them to a movieinfo row.
  */
 public function processMovieReleases()
 {
     $ret = 0;
     $nfo = new Nfo();
     $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where imdbid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_MOVIE));
     if ($this->pdo->getNumRows($res) > 0) {
         if ($this->echooutput) {
             echo "MovProc : Processing " . $this->pdo->getNumRows($res) . " movie releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($res)) {
             $imdbID = false;
             /* Preliminary IMDB id Detection from NFO file */
             $rawnfo = '';
             if ($nfo->getNfo($arr['id'], $rawnfo)) {
                 $imdbID = $this->parseImdbFromNfo($rawnfo);
             }
             if ($imdbID !== false) {
                 // Set IMDB (if found in nfo) and move along
                 $this->pdo->queryExec(sprintf("update releases set imdbid = %s where id = %d", $this->pdo->escapeString($imdbID), $arr["id"]));
                 //check for existing movie entry
                 $movCheck = $this->getMovieInfo($imdbID);
                 if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) {
                     $movieId = $this->updateMovieInfo($imdbID);
                 }
                 continue;
             }
             $moviename = $this->parseMovieName($arr['searchname']);
             if ($moviename !== false) {
                 if ($this->echooutput) {
                     echo 'MovProc : ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n";
                 }
                 //$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com'));
                 $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]);
                 // make sure we got some data
                 if ($buffer !== false && strlen($buffer)) {
                     $imdbId = $this->parseImdbFromNfo($buffer);
                     if ($imdbId !== false) {
                         //update release with imdb id
                         $this->pdo->queryExec(sprintf("update releases SET imdbid = %s WHERE id = %d", $this->pdo->escapeString($imdbId), $arr["id"]));
                         //check for existing movie entry
                         $movCheck = $this->getMovieInfo($imdbId);
                         if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) {
                             $movieId = $this->updateMovieInfo($imdbId);
                         }
                     } else {
                         //no imdb id found, set to all zeros so we dont process again
                         $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"]));
                     }
                 } else {
                     //url fetch failed, will try next run
                 }
             } else {
                 //no valid movie name found, set to all zeros so we dont process again
                 $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"]));
             }
         }
     }
 }
Ejemplo n.º 12
0
<?php

// search tmdb or web for movie from a given name
require_once dirname(__FILE__) . '/../../www/config.php';
$moviename = "Africa Screams";
$movie = new Movie();
// #1 tmdb
//
//print_r($movie->searchTmdb($moviename));
// #2 search engine (google/bing)
//$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com'));
$buffer = \newznab\utility\Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]);
if ($buffer !== false && strlen($buffer)) {
    $imdb = $movie->parseImdbFromNfo($buffer);
    echo sprintf("imdbid : %s\n", $imdb);
    print_r($movie->fetchImdbProperties($imdb));
}
Ejemplo n.º 13
0
 public function getRageMatch($showInfo)
 {
     $title = $showInfo['cleanname'];
     // Full search gives us the akas.
     $xml = Utility::getUrl(['url' => $this->xmlFullSearchUrl . urlencode(strtolower($title))]);
     if ($xml !== false) {
         $arrXml = @Utility::objectsIntoArray(simplexml_load_string($xml));
         if (isset($arrXml['show']) && is_array($arrXml)) {
             // We got a valid xml response
             $titleMatches = $urlMatches = $akaMatches = [];
             if (isset($arrXml['show']['showid'])) {
                 // We got exactly 1 match so lets convert it to an array so we can use it in the logic below.
                 $newArr = [];
                 $newArr[] = $arrXml['show'];
                 unset($arrXml);
                 $arrXml['show'] = $newArr;
             }
             foreach ($arrXml['show'] as $arr) {
                 $tvrlink = '';
                 // Get a match percentage based on our name and the name returned from tvr.
                 $titlepct = $this->checkMatch($title, $arr['name']);
                 if ($titlepct !== false) {
                     $titleMatches[$titlepct][] = ['title' => $arr['name'], 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr];
                 }
                 // Get a match percentage based on our name and the url returned from tvr.
                 if (isset($arr['link']) && preg_match('/tvrage\\.com\\/((?!shows)[^\\/]*)$/i', $arr['link'], $tvrlink)) {
                     $urltitle = str_replace('_', ' ', $tvrlink[1]);
                     $urlpct = $this->checkMatch($title, $urltitle);
                     if ($urlpct !== false) {
                         $urlMatches[$urlpct][] = ['title' => $urltitle, 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr];
                     }
                 }
                 // Check if there are any akas for this result and get a match percentage for them too.
                 if (isset($arr['akas']['aka'])) {
                     if (is_array($arr['akas']['aka'])) {
                         // Multuple akas.
                         foreach ($arr['akas']['aka'] as $aka) {
                             $akapct = $this->checkMatch($title, $aka);
                             if ($akapct !== false) {
                                 $akaMatches[$akapct][] = ['title' => $aka, 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr];
                             }
                         }
                     } else {
                         // One aka.
                         $akapct = $this->checkMatch($title, $arr['akas']['aka']);
                         if ($akapct !== false) {
                             $akaMatches[$akapct][] = ['title' => $arr['akas']['aka'], 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr];
                         }
                     }
                 }
             }
             // Reverse sort our matches so highest matches are first.
             krsort($titleMatches);
             krsort($urlMatches);
             krsort($akaMatches);
             // Look for 100% title matches first.
             if (isset($titleMatches[100])) {
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found 100% match: "' . $titleMatches[100][0]['title'] . '"');
                 }
                 return $titleMatches[100][0];
             }
             // Look for 100% url matches next.
             if (isset($urlMatches[100])) {
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found 100% url match: "' . $urlMatches[100][0]['title'] . '"');
                 }
                 return $urlMatches[100][0];
             }
             // Look for 100% aka matches next.
             if (isset($akaMatches[100])) {
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found 100% aka match: "' . $akaMatches[100][0]['title'] . '"');
                 }
                 return $akaMatches[100][0];
             }
             // No 100% matches, loop through what we got and if our next closest match is more than TvRage::MATCH_PROBABILITY % of the title lets take it.
             foreach ($titleMatches as $mk => $mv) {
                 // Since its not 100 match if we have country info lets use that to make sure we get the right show.
                 if (isset($showInfo['country']) && !empty($showInfo['country']) && !empty($mv[0]['country'])) {
                     if (strtolower($showInfo['country']) != strtolower($mv[0]['country'])) {
                         continue;
                     }
                 }
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found ' . $mk . '% match: "' . $titleMatches[$mk][0]['title'] . '"');
                 }
                 return $titleMatches[$mk][0];
             }
             // Same as above but for akas.
             foreach ($akaMatches as $ak => $av) {
                 if (isset($showInfo['country']) && !empty($showInfo['country']) && !empty($av[0]['country'])) {
                     if (strtolower($showInfo['country']) != strtolower($av[0]['country'])) {
                         continue;
                     }
                 }
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found ' . $ak . '% aka match: "' . $akaMatches[$ak][0]['title'] . '"');
                 }
                 return $akaMatches[$ak][0];
             }
             if ($this->echooutput) {
                 echo $this->pdo->log->primary('No match found on TVRage trying Trakt.');
             }
             return false;
         } else {
             if ($this->echooutput) {
                 echo $this->pdo->log->primary('Nothing returned from tvrage.');
             }
             return false;
         }
     } else {
         return -1;
     }
 }
Ejemplo n.º 14
0
 /**
  * Try to find a IMDB id on yahoo.com
  *
  * @return bool
  */
 protected function yahooSearch()
 {
     $buffer = Utility::getUrl(['url' => "http://search.yahoo.com/search?n=10&ei=UTF-8&va_vt=title&vo_vt=any&ve_vt=any&vp_vt=any&vf=all&vm=p&fl=0&fr=fp-top&p=intitle:" . urlencode('intitle:' . implode(' intitle:', explode(' ', preg_replace('/\\s+/', ' ', preg_replace('/\\W/', ' ', $this->currentTitle)))) . ' intitle:' . $this->currentYear) . '&vs=' . urlencode('www.imdb.com/title/')]);
     if ($buffer !== false) {
         $this->yahooLimit++;
         if ($this->doMovieUpdate($buffer, 'Yahoo.com', $this->currentRelID) !== false) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 15
0
     } else {
         $genre = $tvrShow['genres']['genre'];
     }
 }
 $country = '';
 if (isset($tvrShow['country']) && !empty($tvrShow['country'])) {
     $country = $tvrage->countryCode($tvrShow['country']);
 }
 $rInfo = $tvrage->getRageInfoFromPage($rageid);
 $desc = '';
 if (isset($rInfo['desc']) && !empty($rInfo['desc'])) {
     $desc = $rInfo['desc'];
 }
 $imgbytes = '';
 if (isset($rInfo['imgurl']) && !empty($rInfo['imgurl'])) {
     $img = Utility::getUrl(['url' => $rInfo['imgurl']]);
     if ($img !== false) {
         $im = @imagecreatefromstring($img);
         if ($im !== false) {
             $imgbytes = $img;
         }
     }
 }
 $pdo->queryDirect(sprintf("UPDATE tvrage SET description = %s, genre = %s, country = %s, imgdata = %s WHERE rageid = %d", $pdo->escapeString(substr($desc, 0, 10000)), $pdo->escapeString(substr($genre, 0, 64)), $pdo->escapeString($country), $pdo->escapeString($imgbytes), $rageid));
 $name = $pdo->query("Select releasetitle from tvrage where rageid = " . $rageid);
 echo $pdo->log->primary("Updated: " . $name[0]['releasetitle']);
 $diff = floor((microtime(true) - $starttime) * 1000000);
 if (1000000 - $diff > 0) {
     echo $pdo->log->alternate("Sleeping");
     usleep(1000000 - $diff);
 }
 // different between individual databases
 $pdo->queryExec('ALTER TABLE tmp_pre ADD COLUMN groupname VARCHAR (255)');
 // Drop indexes on tmp_pre
 $pdo->queryExec('ALTER TABLE tmp_pre DROP INDEX `ix_prehash_nfo`, DROP INDEX `ix_prehash_predate`, DROP INDEX `ix_prehash_source`, DROP INDEX `ix_prehash_title`, DROP INDEX `ix_prehash_requestid`');
 foreach ($all_matches as $matches) {
     if (preg_match('#^(.+)/(\\d+)_#', $matches, $match)) {
         $timematch = -1 + $progress['last'];
         // Skip patches the user does not want.
         if ($match[2] < $timematch) {
             echo 'Skipping dump ' . $match[2] . ', as your minimum unix time argument is ' . $timematch . PHP_EOL;
             --$total;
             continue;
         }
         // Download the dump.
         $file['url'] = $baseUrl . '/' . $match[1] . '/' . $match[2] . $fileName . '?dl=1';
         $dump = Utility::getUrl($file);
         if (!$dump) {
             echo 'Error downloading dump ' . $match[2] . ' you can try manually importing it.' . PHP_EOL;
             continue;
         }
         // Make sure we didn't get a HTML page.
         if (strlen($dump) < 5000 && strpos($dump, '<!DOCTYPE html>') !== false) {
             echo 'The dump file ' . $match[2] . ' might be missing from dropbox.' . PHP_EOL;
             continue;
         }
         // Decompress.
         $dump = gzdecode($dump);
         if (!$dump) {
             echo 'Error decompressing dump ' . $match[2] . '.' . PHP_EOL;
             continue;
         }
Ejemplo n.º 17
0
 public function getRageMatch($showInfo)
 {
     $title = $showInfo['cleanname'];
     $lookupUrl = $this->xmlFullSearchUrl . urlencode(strtolower($title));
     $xml = $this->fetchCache($lookupUrl);
     if ($xml === false) {
         $xml = Utility::getUrl(['url' => $lookupUrl, 'verifycert' => false]);
     }
     if ($xml !== false) {
         $this->storeCache($lookupUrl, $xml);
         $xml = str_replace('<genre></genre>', '', $xml);
         $xmlObj = @simplexml_load_string($xml);
         $arrXml = Utility::objectsIntoArray($xmlObj);
         if (isset($arrXml['show']) && is_array($arrXml['show'])) {
             // we got a valid xml response
             $titleMatches = array();
             $urlMatches = array();
             $akaMatches = array();
             if (isset($arrXml['show']['showid'])) {
                 // we got exactly 1 match so lets convert it to an array so we can use it in the logic below
                 $newArr = array();
                 $newArr[] = $arrXml['show'];
                 unset($arrXml);
                 $arrXml['show'] = $newArr;
             }
             foreach ($arrXml['show'] as $arr) {
                 $titlepct = $urlpct = $akapct = 0;
                 // get a match percentage based on our name and the name returned from tvr
                 $titlepct = $this->checkMatch($title, $arr['name']);
                 if ($titlepct !== false) {
                     $titleMatches[$titlepct][] = array('title' => $arr['name'], 'showid' => $arr['showid'], 'country' => $arr['country'], 'genres' => $arr['genres'], 'tvr' => $arr);
                 }
                 // get a match percentage based on our name and the url returned from tvr
                 if (isset($arr['link']) && preg_match('/tvrage\\.com\\/((?!shows)[^\\/]*)$/i', $arr['link'], $tvrlink)) {
                     $urltitle = str_replace('_', ' ', $tvrlink[1]);
                     $urlpct = $this->checkMatch($title, $urltitle);
                     if ($urlpct !== false) {
                         $urlMatches[$urlpct][] = array('title' => $urltitle, 'showid' => $arr['showid'], 'country' => $arr['country'], 'genres' => $arr['genres'], 'tvr' => $arr);
                     }
                 }
                 // check if there are any akas for this result and get a match percentage for them too
                 if (isset($arr['akas'])) {
                     if (is_array($arr['akas']['aka'])) {
                         // multuple akas
                         foreach ($arr['akas']['aka'] as $aka) {
                             $akapct = $this->checkMatch($title, $aka);
                             if ($akapct !== false) {
                                 $akaMatches[$akapct][] = array('title' => $aka, 'showid' => $arr['showid'], 'country' => $arr['country'], 'genres' => $arr['genres'], 'tvr' => $arr);
                             }
                         }
                     } else {
                         // one aka
                         $akapct = $this->checkMatch($title, $arr['akas']['aka']);
                         if ($akapct !== false) {
                             $akaMatches[$akapct][] = array('title' => $arr['akas']['aka'], 'showid' => $arr['showid'], 'country' => $arr['country'], 'genres' => $arr['genres'], 'tvr' => $arr);
                         }
                     }
                 }
             }
             // reverse sort our matches so highest matches are first
             krsort($titleMatches);
             krsort($urlMatches);
             krsort($akaMatches);
             // look for 100% title matches first
             if (isset($titleMatches[100])) {
                 if ($this->echooutput) {
                     echo 'TVRage  : Found 100% match: "' . $titleMatches[100][0]['title'] . '"' . "\n";
                 }
                 return $titleMatches[100][0];
             }
             // look for 100% url matches next
             if (isset($urlMatches[100])) {
                 if ($this->echooutput) {
                     echo 'TVRage  : Found 100% url match: "' . $urlMatches[100][0]['title'] . '"' . "\n";
                 }
                 return $urlMatches[100][0];
             }
             // look for 100% aka matches next
             if (isset($akaMatches[100])) {
                 if ($this->echooutput) {
                     echo 'TVRage  : Found 100% aka match: "' . $akaMatches[100][0]['title'] . '"' . "\n";
                 }
                 return $akaMatches[100][0];
             }
             // no 100% matches, loop through what we got and if our next closest match is more than TvRage::MATCH_PROBABILITY % of the title lets take it
             foreach ($titleMatches as $mk => $mv) {
                 // since its not 100 match if we have country info lets use that to make sure we get the right show
                 if (isset($showInfo['country']) && !empty($showInfo['country']) && !empty($mv[0]['country'])) {
                     if (strtolower($showInfo['country']) != strtolower($mv[0]['country'])) {
                         continue;
                     }
                 }
                 if ($this->echooutput) {
                     echo 'TVRage  : Found ' . $mk . '% match: "' . $titleMatches[$mk][0]['title'] . '"' . "\n";
                 }
                 return $titleMatches[$mk][0];
             }
             // same as above but for akas
             foreach ($akaMatches as $ak => $av) {
                 if (isset($showInfo['country']) && !empty($showInfo['country']) && !empty($av[0]['country'])) {
                     if (strtolower($showInfo['country']) != strtolower($av[0]['country'])) {
                         continue;
                     }
                 }
                 if ($this->echooutput) {
                     echo 'TVRage  : Found ' . $ak . '% aka match: "' . $akaMatches[$ak][0]['title'] . '"' . "\n";
                 }
                 return $akaMatches[$ak][0];
             }
             return false;
         } else {
             return false;
         }
     } else {
         if ($this->echooutput) {
             echo 'TVRage  : Error connecting to tvrage' . "\n";
         }
         return -1;
     }
     if ($this->echooutput) {
         echo 'TVRage  : No match found online' . "\n";
     }
     return false;
 }