Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/tmdbPublic
forked fromvfalies/tmdb

PHP Wrapper for TMDB (The Movie DataBase) API V3

License

NotificationsYou must be signed in to change notification settings

biroa/tmdb

 
 

Repository files navigation

Latest Stable VersionBuild StatusCode CoverageScrutinizer Code QualityLicense

Packagist PHP Version SupportTested on PHP 7.1 to 8.0

Tmdb is a PHP wrapper forThe Movie Database APIV3.

Table of contents

  1. Features
  2. Installation
  3. Basic usage
  4. Usage
    1. Getting a TMDB instance
    2. Movie
    3. TV Show
    4. Collection
    5. People
    6. Company
    7. Find by an external ID
    8. Authentication
    9. Media Helper
  5. Unit tests
  6. About

Features

Features actualy supported :

  • Search
    • Movie
    • TV Show
    • Collection
    • Company
  • Getting informations
    • Movie
    • TV Show
    • Collection
    • Company
    • Genres
    • TV Network
  • Account
    • Authentification
    • Movies / TV Shows rating
    • Movies / TV Shows favorites
    • Movies / TV Shows watchlist
  • Media
  • Genres
  • Jobs
  • Find
    • IMDb
    • TheTVDb
    • TVRage
    • Facebook
    • Twitter
    • Instagram

Installation

Requirements

  • Tmdb works with PHP 7.1 and higher
  • TheMovieDatabase API key

Composer

Install the lastest version with

$ composer require vfalies/tmdb

Basic Usage

<?phprequire'vendor/autoload.php';useVfacTmdb\Factory;useVfacTmdb\Search;useVfacTmdb\Item;// Initialize Wrapper$tmdb = Factory::create()->getTmdb('your_api_key');// Search a movie$search    =newSearch($tmdb);$responses =$search->movie('star wars');// Get all resultsforeach ($responsesas$response){echo$response->getTitle();}// Get movie information$item  =newItem($tmdb);$infos =$item->getMovie(11,array('language' =>'fr-FR'));echo$infos->getTitle();

Usage

Getting a TMDB instance

TMDB is the main class of the library.It has two dependencies :

Using the Factory

It is the easiest way to load TMDB

<?phprequire'vendor/autoload.php';useVfacTmdb\Factory;$tmdb = Factory::create()->getTmdb('your_api_key');

In a Slim application

If your application is built withSlim, you can add TMDB in your dependencies and inject Slim'sMonolog instance into it.Just add this independencies.php

$container['tmdb'] =function ($c) {$api_key =$c->get('settings')['tmdb']['api_key'];$tmdb =new \vfalies\tmdb\Tmdb($api_key,$c->logger);}

In this example, API key is declared insettings.php

return ['settings' = ['tmdb' = ['api_key' = 'your_api_key';        ]    ]];

Do it yourself

Convenient if you need too inject your own dependencies. In the example below, we injectMonolog configured to write logs on standards output.

<?phprequire'vendor/autoload.php';useVfacTmdb\Tmdb;useMonolog\Logger;useMonolog\Handler\StreamHandler;$logger =new Logger('default', [newStreamHandler('php://stdout')])$tmdb =Tmdb('your_api_key',$logger);

Movie

Search a movie

$search    =newSearch($tmdb);$responses =$search->movie('star wars');

The search returnsGenerator object ofResult\Movie object.

See demo

Get a movie

$item  =newItem($tmdb);$movie =$item->getMovie($movie_id);echo$movie->getTitle();

The getter returns aMovie object.

See demo

TV Show

Search a TV Show

$search    =newSearch($tmdb);$responses =$search->tvshow('game of thrones');

The search returnsGenerator object ofResult\TVShow object.

See demo

Get a TV Show

$item   =newItem($tmdb);$tvshow =$item->getTVShow($tvshow_id);echo$tvshow->getTitle();

The getter returns aTVShow object.

See demo

Get a TV Season

$item     =newItem($tmdb);$tvseason =$item->getTVSeason($tvshow_id,$season_number);echo$tvseason->getName();

The getter returns aTVSeason object.

Get a TV Episode

$item      =newItem($tmdb);$tvepisode =$item->getTVEpisode($tvshow_id,$season_number,$episode_number);echo$tvepisode->getName();

The getter returns aTVEpisode object.

Collection

Search a Collection

$search    =newSearch($tmdb);$responses =$search->collection('alien');

The search returnsGenerator object ofResult\Collection object.

See demo

Get a Collection

$item       =newItem($tmdb);$collection =$item->getCollection($collection_id);echo$collection->getName();

The getter returns aCollection object.

See demo

People

Search a People

$search    =newSearch($tmdb);$responses =$search->people('alec baldwin');

The search returnsGenerator object ofResult\People object.

See demo

Get a People

$item   =newItem($tmdb);$people =$item->getPeople($people_id);echo$people->getName();

The getter returns aPeople object.

See demo

Company

Search a company

$search    =newSearch($tmdb);$responses =$search->company('lucasfilms');

The search returnsGenerator object ofResult\Company object.

See demo

Get a Company

$item   =newItem($tmdb);$company =$item->getCompany($company_id);echo$company->getName();

The getter returns aCompany object.

See demo

Find by an external ID

$find =newFind($tmdb);$responses =$find->imdb('tt0076759');

The find method makes it easy to search for objects in TMDb database by an external id.

Each sources has his proper methods:imdb,tvdb,tvrage,facebook,twitter,instagram.

The find returns aResult\Find object. Each types of objects can be getted by a specific method. The returns is aGenerator object ofResult\[expected type] object.

$movies =$responses->getMovies();$title  =$movies->current()->getTitle();
Object typesMethodsGenerator of
moviesgetMovies()Result\Movie
peoplesgetPeoples()Result\People
TV showsgetTVShows()Result\TVShow
TV episodes getTVEpisodes()Result\TVEpisode
TV SeasonsgetTVSeasons()Result\TVSeason

The supported external sources for each object are as follows.

  MoviesTV ShowsTV SeasonsTV EpisodesPeople
IMDb ID✓ ✓ ✕ ✓ 
TVDb ID ✓  ✓ ✓✕ 
Freebase MID not implemented    
Freebase ID not implemented    
TVRage✕ ✓ ✓ ✓ ✓ 
Facebook✓ ✓  ✕ ✕  ✓
Twitter✓ ✓ ✕ ✕ ✓ 
Instagram✓ ✓ ✕ ✕ ✓ 

Authentication

The connection to your account is in 3 steps:

  • Getting a request token
  • Connection to TMDb website
  • Create a session

Getting a request token

$tmdb = Factory::create()->getTmdb('your_api_key');$Auth =newAuth($tmdb);echo$Auth->getRequestToken();

Connect to TMDb website

$tmdb = Factory::create()->getTmdb('your_api_key');$Auth =newAuth($tmdb);$Auth->connect($_POST['request_token']);

This call redirect the page to TMDb website login page for identification and authorisations. By default, after the connection, the user stay on TMDb website. To redirect to your website after the connection, use the following code:

$tmdb = Factory::create()->getTmdb('your_api_key');$Auth =newAuth($tmdb);$Auth->connect($_POST['request_token'],'http://your_url');

Create a session

To use all account methods, we must use a valid session.

$tmdb = Factory::create()->getTmdb('62dfe9839b8937e595e325a4144702ad');$Auth =newAuth($tmdb);echo$Auth->createSession($_POST['request_token']);

Media Helper

All media informations delivered by the library are relative pathfile.

To get a valid media URL, use theMedia class to generate the URL and check the media size

$media =newMedia($tmdb);$url =$media->getPosterUrl('/AbJBXaVPrdXROwb8KmgWUPU2XJX.jpg');

The following type of media are supported :

  • Backdrop
  • Poster
  • Logo
  • Profile
  • Still

Unit Testing

You can run the unit test suites using the following command in the library's source directory:

$ make test

About

Submitting bugs and feature requests

Bugs and feature request are tracked onGitHub

Author

Vincent Faliès -vincent@vfac.fr

License

VfacTmdb is licensed under the MIT License - see theLICENSE file for details

About

PHP Wrapper for TMDB (The Movie DataBase) API V3

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP100.0%

[8]ページ先頭

©2009-2025 Movatter.jp