示例#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 = Misc::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;
 }
示例#2
0
文件: SABnzbd.php 项目: kaibosh/nZEDb
 /**
  * Resume all NZB's in the SAB queue.
  *
  * @return bool|mixed
  */
 public function resumeAll()
 {
     return Misc::getUrl(['url' => $this->url . "api?mode=resume" . "&apikey=" . $this->apikey, 'verifycert' => false]);
 }
示例#3
0
 /**
  * Try to find a IMDB id on yahoo.com
  *
  * @return bool
  */
 protected function yahooSearch()
 {
     $buffer = Misc::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;
 }
示例#4
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 = Misc::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;
 }
示例#5
0
文件: TvRage.php 项目: zetas/nZEDb
 /**
  * Main function for matching a releae searchname to a TvRage title
  * Returns basic show information array or -1 int if no match
  *
  * @param $showInfo
  *
  * @return array|int
  */
 public function getShowInfo($showInfo)
 {
     $matchedTitle = -1;
     $title = $showInfo['cleanname'];
     // Full search gives us the akas.
     $xml = Misc::getUrl(['url' => $this->xmlFullSearchUrl . urlencode(strtolower($title))]);
     if ($xml !== false) {
         $arrXml = @Misc::objectsIntoArray(simplexml_load_string($xml));
         // CheckXML Response is valid before processing
         if (isset($arrXml['show']) && is_array($arrXml)) {
             // We got exactly 1 match so lets convert it to an array so we can use it in the logic below.
             if (isset($arrXml['show']['showid'])) {
                 $newArr[] = $arrXml['show'];
                 unset($arrXml);
                 $arrXml['show'] = $newArr;
             }
             $highestPercent = 0;
             foreach ($arrXml['show'] as $show) {
                 if ($title == $show['name']) {
                     $matchedTitle = $show;
                     break;
                 }
                 // Get a match percentage based on our name and the name returned from tvr.
                 $matchPercent = $this->checkMatch($title, $show['name'], self::MATCH_PROBABILITY);
                 if ($matchPercent > $highestPercent) {
                     $matchedTitle = $show;
                     $highestPercent = $matchPercent;
                 }
                 // Check if there are any akas for this result and get a match percentage for them too.
                 if (isset($show['akas']['aka'])) {
                     if (is_array($show['akas']['aka'])) {
                         // Multiple akas.
                         foreach ($show['akas']['aka'] as $aka) {
                             $matchPercent = $this->checkMatch($title, $aka, self::MATCH_PROBABILITY);
                             if ($matchPercent > $highestPercent) {
                                 $matchedTitle = $show;
                                 $highestPercent = $matchPercent;
                             }
                         }
                     } else {
                         // One aka.
                         $matchPercent = $this->checkMatch($title, $show['akas']['aka'], self::MATCH_PROBABILITY);
                         if ($matchPercent > $highestPercent) {
                             $show['akas']['aka'][] = $show['akas']['aka'];
                             $matchedTitle = $show;
                             $highestPercent = $matchPercent;
                         }
                     }
                 }
             }
         } else {
             if ($this->echooutput) {
                 echo $this->pdo->log->primary('Nothing returned from tvrage.');
             }
         }
     }
     return $this->formatShowInfo($matchedTitle);
 }
示例#6
0
}
$total = count($data);
$predb = new PreDb();
$progress = $predb->progress(settings_array());
foreach ($data as $file) {
    if (preg_match("#^https://raw\\.githubusercontent\\.com/nZEDb/nZEDbPre_Dumps/master/dumps/{$filePattern}\$#", $file['download_url'])) {
        if (preg_match("#^{$filePattern}\$#", $file['name'], $match)) {
            $timematch = $progress['last'];
            // Skip patches the user does not want.
            if ($match[1] < $timematch) {
                echo 'Skipping dump ' . $match[2] . ', as your minimum unix time argument is ' . $timematch . PHP_EOL;
                --$total;
                continue;
            }
            // Download the dump.
            $dump = Misc::getUrl(['url' => $file['download_url']]);
            echo "Downloading: {$file['download_url']}\n";
            if (!$dump) {
                echo "Error downloading dump {$match[2]} you can try manually importing it." . PHP_EOL;
                continue;
            } else {
                if (nZEDb_DEBUG) {
                    echo "Dump {$match[2]} downloaded\n";
                }
            }
            // Make sure we didn't get an HTML page.
            if (strpos($dump, '<!DOCTYPE html>') !== false) {
                echo "The dump file {$match[2]} might be missing from GitHub." . PHP_EOL;
                continue;
            }
            // Decompress.
示例#7
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 = Misc::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;
 }
示例#8
0
文件: NZBGet.php 项目: kaibosh/nZEDb
 /**
  * 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 = Misc::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;
 }
示例#9
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 = Misc::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);
 }
示例#10
0
文件: Misc.php 项目: EeGgSs/nZEDb
 /**
  * Fetches an embeddable video to a IMDB trailer from http://www.traileraddict.com
  *
  * @param $imdbID
  *
  * @return string
  */
 public static function imdb_trailers($imdbID)
 {
     $xml = Misc::getUrl(['url' => 'http://api.traileraddict.com/?imdb=' . $imdbID]);
     if ($xml !== false) {
         if (preg_match('/(<iframe.+?<\\/iframe>)/i', $xml, $html)) {
             return $html[1];
         }
     }
     return '';
 }
示例#11
0
 public function getRageMatch($showInfo)
 {
     $title = $showInfo['cleanname'];
     // Full search gives us the akas.
     $xml = Misc::getUrl(['url' => $this->xmlFullSearchUrl . urlencode(strtolower($title))]);
     if ($xml !== false) {
         $arrXml = @Misc::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;
     }
 }
示例#12
0
 $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 = $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 = Misc::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;
         }
示例#13
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(Misc::getUrl(['url' => RottenTomato::API_URL . $function . '?limit=' . mt_rand(15, 20) . '&apikey=' . $this->_apikey . (!empty($params) ? '&' . http_build_query($params) : '')]));
 }
示例#14
0
 /**
  * @param string $pathname full path to file for saving. Will be overwritten.
  *
  * @return bool|int
  */
 protected function saveSourceFile($pathname)
 {
     $result = false;
     $file = Misc::getUrl(['url' => $this->sourceURL]);
     if ($file !== false) {
         $result = file_put_contents($pathname, $file);
     }
     return $result;
 }