2020-06-03 16:26:30 +00:00
|
|
|
<?php
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Class TMDBMovie
|
|
|
|
* class to handle all interactions with the tmdb api
|
|
|
|
*/
|
|
|
|
class TMDBMovie {
|
|
|
|
public $picturebase = "https://image.tmdb.org/t/p/w500";
|
2020-06-03 16:26:30 +00:00
|
|
|
private $apikey = "9fd90530b11447f5646f8e6fb4733fb4";
|
|
|
|
private $baseurl = "https://api.themoviedb.org/3/";
|
|
|
|
|
2020-06-04 14:45:24 +00:00
|
|
|
/**
|
|
|
|
* search for a specific movie
|
|
|
|
*
|
|
|
|
* @param string $moviename moviename
|
|
|
|
* @return object movie object or null if not found
|
|
|
|
*/
|
2020-08-12 17:50:25 +00:00
|
|
|
public function searchMovie(string $moviename) {
|
2020-06-03 16:26:30 +00:00
|
|
|
$reply = json_decode(file_get_contents($this->baseurl . "search/movie?api_key=" . $this->apikey . "&query=" . urlencode($moviename)));
|
|
|
|
if ($reply->total_results == 0) {
|
|
|
|
// no results found
|
|
|
|
// todo maybe parse first pictures somehow
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return $reply->results[0];
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 14:45:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* query all available genres from tmdb
|
|
|
|
*
|
|
|
|
* @return array of all available genres
|
|
|
|
*/
|
2020-08-12 17:50:25 +00:00
|
|
|
public function getAllGenres() {
|
2020-06-04 14:45:24 +00:00
|
|
|
$reply = json_decode(file_get_contents($this->baseurl . "genre/movie/list?api_key=" . $this->apikey));
|
|
|
|
return $reply->genres;
|
|
|
|
}
|
2020-06-03 16:26:30 +00:00
|
|
|
}
|