Advertisement
s4m33r789

ContentApi.php

Mar 18th, 2025 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.36 KB | Source Code | 0 0
  1. <?php
  2.  
  3. //https://t.me/syndic4te
  4. class ContentApi extends CI_Controller {
  5.     private $tmdb_api_key = "1bfdbff05c2698dc917dd28c08d41096";
  6.  
  7.     public function searchContentData() {
  8.         $query = $this->input->get("query");
  9.         $type = $this->input->get("type") ?? "movie";
  10.         $language = $this->input->get("language") ?? "en-US";
  11.  
  12.         $url = "https://api.themoviedb.org/3/search/" . $type . "?api_key=" . $this->tmdb_api_key . "&query=" . urlencode($query) . "&language=" . urlencode($language);
  13.  
  14.         $this->fetchFromTmdb($url);
  15.     }
  16.  
  17.     public function findTmdbID() {
  18.         $id = $this->input->get("id");
  19.         if (!empty($id)) {
  20.             $url = "https://api.themoviedb.org/3/find/" . urlencode($id) . "?api_key=" . $this->tmdb_api_key . "&external_source=imdb_id";
  21.             $this->fetchFromTmdb($url);
  22.         } else {
  23.             show_404();
  24.         }
  25.     }
  26.  
  27.     public function fetchTmdbData() {
  28.         $type = $this->input->get("type");
  29.         $id = $this->input->get("id");
  30.         $language = $this->input->get("language") ?? "en-US";
  31.  
  32.         if (!empty($id)) {
  33.             $url = "https://api.themoviedb.org/3/" . $type . "/" . urlencode($id) . "?api_key=" . $this->tmdb_api_key . "&language=" . urlencode($language);
  34.             $this->fetchFromTmdb($url);
  35.         } else {
  36.             show_404();
  37.         }
  38.     }
  39.  
  40.     public function fetchVideoData() {
  41.         $id = $this->input->get("id");
  42.         $type = $this->input->get("type");
  43.  
  44.         if (!(empty($id) || empty($type))) {
  45.             $url = "https://api.themoviedb.org/3/" . $type . "/" . urlencode($id) . "/videos?api_key=" . $this->tmdb_api_key;
  46.             $this->fetchFromTmdb($url);
  47.         } else {
  48.             show_404();
  49.         }
  50.     }
  51.  
  52.     public function fetchAllSeasonData() {
  53.         $id = $this->input->get("id");
  54.         $language = $this->input->get("language") ?? "en-US";
  55.  
  56.         if (!empty($id)) {
  57.             $url = "https://api.themoviedb.org/3/tv/" . urlencode($id) . "?api_key=" . $this->tmdb_api_key . "&language=" . urlencode($language) . "&append_to_response=seasons";
  58.             $this->fetchFromTmdb($url);
  59.         } else {
  60.             show_404();
  61.         }
  62.     }
  63.  
  64.     public function fetchAllEpisodeData() {
  65.         $id = $this->input->get("id");
  66.         $season_no = $this->input->get("season_no");
  67.         $language = $this->input->get("language") ?? "en-US";
  68.  
  69.         if (!(empty($id) || empty($season_no))) {
  70.             $url = "https://api.themoviedb.org/3/tv/" . urlencode($id) . "/season/" . urlencode($season_no) . "?api_key=" . $this->tmdb_api_key . "&language=" . urlencode($language);
  71.             $this->fetchFromTmdb($url);
  72.         } else {
  73.             show_404();
  74.         }
  75.     }
  76.  
  77.     private function fetchFromTmdb($url) {
  78.         $ch = curl_init();
  79.         curl_setopt($ch, CURLOPT_URL, $url);
  80.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  81.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  82.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  83.  
  84.         $response = curl_exec($ch);
  85.         if (!curl_errno($ch)) {
  86.             curl_close($ch);
  87.             $this->output->set_content_type("application/json")->set_output($response);
  88.         } else {
  89.             $error = curl_error($ch);
  90.             curl_close($ch);
  91.             show_error("cURL Error: " . $error);
  92.         }
  93.     }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement