input->get("query"); $type = $this->input->get("type") ?? "movie"; $language = $this->input->get("language") ?? "en-US"; $url = "https://api.themoviedb.org/3/search/" . $type . "?api_key=" . $this->tmdb_api_key . "&query=" . urlencode($query) . "&language=" . urlencode($language); $this->fetchFromTmdb($url); } public function findTmdbID() { $id = $this->input->get("id"); if (!empty($id)) { $url = "https://api.themoviedb.org/3/find/" . urlencode($id) . "?api_key=" . $this->tmdb_api_key . "&external_source=imdb_id"; $this->fetchFromTmdb($url); } else { show_404(); } } public function fetchTmdbData() { $type = $this->input->get("type"); $id = $this->input->get("id"); $language = $this->input->get("language") ?? "en-US"; if (!empty($id)) { $url = "https://api.themoviedb.org/3/" . $type . "/" . urlencode($id) . "?api_key=" . $this->tmdb_api_key . "&language=" . urlencode($language); $this->fetchFromTmdb($url); } else { show_404(); } } public function fetchVideoData() { $id = $this->input->get("id"); $type = $this->input->get("type"); if (!(empty($id) || empty($type))) { $url = "https://api.themoviedb.org/3/" . $type . "/" . urlencode($id) . "/videos?api_key=" . $this->tmdb_api_key; $this->fetchFromTmdb($url); } else { show_404(); } } public function fetchAllSeasonData() { $id = $this->input->get("id"); $language = $this->input->get("language") ?? "en-US"; if (!empty($id)) { $url = "https://api.themoviedb.org/3/tv/" . urlencode($id) . "?api_key=" . $this->tmdb_api_key . "&language=" . urlencode($language) . "&append_to_response=seasons"; $this->fetchFromTmdb($url); } else { show_404(); } } public function fetchAllEpisodeData() { $id = $this->input->get("id"); $season_no = $this->input->get("season_no"); $language = $this->input->get("language") ?? "en-US"; if (!(empty($id) || empty($season_no))) { $url = "https://api.themoviedb.org/3/tv/" . urlencode($id) . "/season/" . urlencode($season_no) . "?api_key=" . $this->tmdb_api_key . "&language=" . urlencode($language); $this->fetchFromTmdb($url); } else { show_404(); } } private function fetchFromTmdb($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($ch); if (!curl_errno($ch)) { curl_close($ch); $this->output->set_content_type("application/json")->set_output($response); } else { $error = curl_error($ch); curl_close($ch); show_error("cURL Error: " . $error); } } }