Esempio n. 1
0
 /**
  * Fetches summary from trakt.tv for the movie.
  * Accept a title (the-big-lebowski-1998), a IMDB id, or a TMDB id.
  *
  * @param string $movie Title or IMDB id.
  * @param bool $array   Return the full array or just the IMDB id.
  *
  * @return bool|mixed
  *
  * @access public
  */
 public function traktMoviesummary($movie = '', $array = false)
 {
     if (!empty($this->APIKEY)) {
         $MovieJson = nzedb\utility\getUrl('http://api.trakt.tv/movie/summary.json/' . $this->APIKEY . '/' . str_replace(array(' ', '_', '.'), '-', str_replace(array('(', ')'), '', $movie)));
         if ($MovieJson !== false) {
             $MovieJson = json_decode($MovieJson, true);
             if (isset($MovieJson['status']) && $MovieJson['status'] === 'failure') {
                 return false;
             }
             if ($array) {
                 return $MovieJson;
             } elseif (isset($MovieJson["imdb_id"])) {
                 return $MovieJson["imdb_id"];
             }
         }
     }
     return false;
 }
Esempio n. 2
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) {
         $img = nzedb\utility\getUrl($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;
 }
Esempio n. 3
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 = nzedb\utility\getUrl($this->fullURL . 'status');
     $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;
 }
Esempio n. 4
0
 public function getRageMatch($showInfo)
 {
     $title = $showInfo['cleanname'];
     // Full search gives us the akas.
     $xml = nzedb\utility\getUrl($this->xmlFullSearchUrl . urlencode(strtolower($title)));
     if ($xml !== false) {
         $arrXml = @nzedb\utility\objectsIntoArray(simplexml_load_string($xml));
         if (isset($arrXml['show']) && is_array($arrXml)) {
             // We got a valid xml response
             $titleMatches = $urlMatches = $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) {
                 $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][] = array('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][] = array('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][] = array('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][] = array('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;
     }
 }
Esempio n. 5
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 = nzedb\utility\getUrl($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);
 }
Esempio n. 6
0
 /**
  * Resume all NZB's in the SAB queue.
  *
  * @return bool|mixed
  */
 public function resumeAll()
 {
     return nzedb\utility\getUrl($this->url . "api?mode=resume" . "&apikey=" . $this->apikey);
 }
Esempio n. 7
0
 /**
  * Process releases for requestID's.
  *
  * @return int How many did we rename?
  */
 protected function _processReleases()
 {
     // Array to store results.
     $requestArray = array();
     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] = array('ident' => 0, 'group' => 'none', 'reqid' => 0);
     // Do a web lookup.
     $returnXml = nzedb\utility\getUrl($this->pdo->getSetting('request_url'), 'post', 'data=' . serialize($requestArray));
     $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 = array();
             $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['group_id'] = $groupIDArray[$this->_release['groupname']];
                     } else {
                         $this->_release['group_id'] = $this->groups->getIDByName($this->_release['groupname']);
                         $groupIDArray[$this->_release['groupname']] = $this->_release['group_id'];
                     }
                     $this->_release['gid'] = $this->_release['group_id'];
                     $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;
 }
Esempio n. 8
0
 /**
  * Try to find a IMDB id on yahoo.com
  *
  * @return bool
  */
 protected function yahooSearch()
 {
     $buffer = nzedb\utility\getUrl("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;
 }
Esempio n. 9
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 = array())
 {
     return trim(nzedb\utility\getUrl(RottenTomato::API_URL . $function . '?limit=' . mt_rand(15, 20) . '&apikey=' . $this->_apikey . (!empty($params) ? '&' . http_build_query($params) : '')));
 }