PHP code example of duyplus / tmdbapi

1. Go to this page and download the library: Download duyplus/tmdbapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

duyplus / tmdbapi example snippets


use duyplus\tmdbapi\TMDB;
// if you have a $conf array - (See LIB_ROOT/configuration/default.php as an example)
$tmdb = new TMDB($conf);

use duyplus\tmdbapi\TMDB;
// if you have no $conf it uses the default config
$tmdb = new TMDB();
//Insert your API Key of TMDB
//Necessary if you use default conf
$tmdb->setAPIKey('YOUR_API_KEY');

//Title to search for
$title = 'back to the future';
$movies = $tmdb->searchMovie($title);
// returns an array of Movie Object
foreach ($movies as $movie) {
    echo $movie->getTitle() . '<br>';
}

$idMovie = 11;
$movie = $tmdb->getMovie($idMovie);
// returns a Movie Object
echo $movie->getTitle();

// Title to search for
$title = 'breaking bad';
$tvShows = $tmdb->searchTVShow($title);
foreach ($tvShows as $tvShow) {
    echo $tvShow->getName() . '<br>';
}

$idTVShow = 1396;
$tvShow = $tmdb->getTVShow($idTVShow);
// returns a TVShow Object
echo $tvShow->getName();

$idTVShow = 1396;
$numSeason = 2;
$season = $tmdb->getSeason($idTVShow, $numSeason);
// returns a Season Object
echo $season->getName();

$idTVShow = 1396;
$numSeason = 2;
$numEpisode = 8;
$episode = $tmdb->getEpisode($idTVShow, $numSeason, $numEpisode);
// returns a Episode Object
echo $episode->getName();

// Name to search for
$name = 'Johnny';
$persons = $tmdb->searchPerson($name);
foreach ($persons as $person) {
    echo $person->getName() . '<br>';
}

$idPerson = 85;
$person = $tmdb->getPerson($idPerson);
// returns a Person Object
echo $person->getName();

$movieRoles = $person->getMovieRoles();
foreach ($movieRoles as $movieRole) {
    echo $movieRole->getCharacter() . ' in ' . $movieRole->getMovieTitle() . '<br>';
}

$tvShowRoles = $person->getTVShow();
foreach ($tvShowRoles as $tvShowRole) {
    echo $tvShowRole->getCharacter() . ' in ' . $tvShowRole->getMovieName() . '<br>';
}

// Name to search for
$name = 'the hobbit';
$collections = $tmdb->searchCollection($name);
foreach ($collections as $collection) {
    echo $collection->getName() . '<br>';
}

$idCollection = 121938;
$collection = $tmdb->getCollection($idCollection);
// returns a Collection Object
echo $collection->getName();

// Name to search for
$name = 'Sony';
$companies = $tmdb->searchCompany($name);
foreach ($companies as $company) {
    echo $company->getName() . '<br>';
}

$idCompany = 34;
$company = $tmdb->getCompany($idCompany);
// returns a Company Object
echo $company->getName();