Beispiel #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 = Utility::getUrl(['url' => 'http://api.trakt.tv/movie/summary.json/' . $this->APIKEY . '/' . str_replace([' ', '_', '.'], '-', str_replace(['(', ')'], '', $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;
 }
Beispiel #2
0
 /**
  * Resume all NZB's in the SAB queue.
  *
  * @return bool|mixed
  */
 public function resumeAll()
 {
     return Utility::getUrl(['url' => $this->url . "api?mode=resume" . "&apikey=" . $this->apikey, 'verifycert' => false]);
 }
Beispiel #3
0
 /**
  * @param string $pathname full path to file for saving. Will be overwritten.
  *
  * @return bool|int
  */
 protected function saveSourceFile($pathname)
 {
     $result = false;
     $file = Utility::getUrl(['url' => $this->sourceURL]);
     if ($file !== false) {
         $result = file_put_contents($pathname, $file);
     }
     return $result;
 }
Beispiel #4
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;
 }
Beispiel #5
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 = 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;
 }
Beispiel #6
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;
     }
 }
Beispiel #7
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_titles 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_titles 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);
 }
Beispiel #8
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('/(<iframe.+?<\\/iframe>)/i', $xml, $html)) {
             return $html[1];
         }
     }
     return '';
 }
Beispiel #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 = [])
 {
     return trim(Utility::getUrl(['url' => RottenTomato::API_URL . $function . '?limit=' . mt_rand(15, 20) . '&apikey=' . $this->_apikey . (!empty($params) ? '&' . http_build_query($params) : '')]));
 }
 $progress = $predb->progress(settings_array());
 if ($argv[1] != 'progress') {
     $progress['last'] = !is_numeric($argv[1]) ? time() : $argv[1];
 }
 $predb->executeTruncate();
 foreach ($links as $link) {
     if (preg_match('#^(.+)/(\\d+)_#', $link, $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.
         $dump = Utility::getUrl(['url' => "{$baseUrl}/{$match[1]}/{$match[2]}{$fileName}?dl=1"]);
         if (!$dump) {
             echo "Error downloading dump {$match[2]} you can try manually importing it." . PHP_EOL;
             continue;
         }
         // Make sure we didn't get an 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;
         }
Beispiel #11
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;
 }
Beispiel #12
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']] = ['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['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;
 }