2017 © Pedro Peláez
 

library tmdb

A PHP Wrapper for The Internet Movie Database API

image

vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API

  • Tuesday, April 24, 2018
  • by vfalies
  • Repository
  • 4 Watchers
  • 3 Stars
  • 78 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 28 Versions
  • 3 % Grown

The README.md

Tmdb - PHP Wrapper for The Movie Database API V3

Latest Stable Version Build Status Code Coverage Scrutinizer Code Quality License, (*1)

Packagist PHP Version Support Tested on PHP 7.1 to 8.0, (*2)

Tmdb is a PHP wrapper for The Movie Database API V3., (*3)

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 :, (*4)

  • 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, (*5)

$ composer require vfalies/tmdb

Basic Usage

<?php

require 'vendor/autoload.php';

use VfacTmdb\Factory;
use VfacTmdb\Search;
use VfacTmdb\Item;

// Initialize Wrapper
$tmdb = Factory::create()->getTmdb('your_api_key');

// Search a movie
$search    = new Search($tmdb);
$responses = $search->movie('star wars');

// Get all results
foreach ($responses as $response)
{
    echo $response->getTitle();
}

// Get movie information
$item  = new Item($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 : - a API key from The Movie DataBase website - a Psr\Log\LoggerInterface instance to write logs, (*6)

Using the Factory

It is the easiest way to load TMDB, (*7)

<?php
require 'vendor/autoload.php';

use VfacTmdb\Factory;

$tmdb = Factory::create()->getTmdb('your_api_key');

In a Slim application

If your application is built with Slim, you can add TMDB in your dependencies and inject Slim's Monolog instance into it. Just add this in dependencies.php, (*8)

$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 in settings.php, (*9)

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 inject Monolog configured to write logs on standards output., (*10)

<?php
require 'vendor/autoload.php';

use VfacTmdb\Tmdb;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('default', [new StreamHandler('php://stdout')])

$tmdb = Tmdb('your_api_key', $logger);

Movie

Search a movie

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

The search returns Generator object of Result\Movie object., (*11)

See demo, (*12)

Get a movie

$item  = new Item($tmdb);
$movie = $item->getMovie($movie_id);

echo $movie->getTitle();

The getter returns a Movie object., (*13)

See demo, (*14)

TV Show

Search a TV Show

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

The search returns Generator object of Result\TVShow object., (*15)

See demo, (*16)

Get a TV Show

$item   = new Item($tmdb);
$tvshow = $item->getTVShow($tvshow_id);

echo $tvshow->getTitle();

The getter returns a TVShow object., (*17)

See demo, (*18)

Get a TV Season

$item     = new Item($tmdb);
$tvseason = $item->getTVSeason($tvshow_id, $season_number);

echo $tvseason->getName();

The getter returns a TVSeason object., (*19)

Get a TV Episode

$item      = new Item($tmdb);
$tvepisode = $item->getTVEpisode($tvshow_id, $season_number, $episode_number);

echo $tvepisode->getName();

The getter returns a TVEpisode object., (*20)

Collection

Search a Collection

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

The search returns Generator object of Result\Collection object., (*21)

See demo, (*22)

Get a Collection

$item       = new Item($tmdb);
$collection = $item->getCollection($collection_id);

echo $collection->getName();

The getter returns a Collection object., (*23)

See demo, (*24)

People

Search a People

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

The search returns Generator object of Result\People object., (*25)

See demo, (*26)

Get a People

$item   = new Item($tmdb);
$people = $item->getPeople($people_id);

echo $people->getName();

The getter returns a People object., (*27)

See demo, (*28)

Company

Search a company

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

The search returns Generator object of Result\Company object., (*29)

See demo, (*30)

Get a Company

$item   = new Item($tmdb);
$company = $item->getCompany($company_id);

echo $company->getName();

The getter returns a Company object., (*31)

See demo, (*32)

Find by an external ID

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

The find method makes it easy to search for objects in TMDb database by an external id., (*33)

Each sources has his proper methods: imdb, tvdb, tvrage, facebook, twitter, instagram., (*34)

The find returns a Result\Find object. Each types of objects can be getted by a specific method. The returns is a Generator object of Result\[expected type] object., (*35)

$movies = $responses->getMovies();
$title  = $movies->current()->getTitle();
Object types Methods Generator of
movies getMovies() Result\Movie
peoples getPeoples() Result\People
TV shows getTVShows() Result\TVShow
TV episodes  getTVEpisodes() Result\TVEpisode
TV Seasons getTVSeasons() Result\TVSeason

The supported external sources for each object are as follows., (*36)

   Movies TV Shows TV Seasons TV Episodes People
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:, (*37)

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

Getting a request token

$tmdb = Factory::create()->getTmdb('your_api_key');

$Auth = new Auth($tmdb);
echo $Auth->getRequestToken();

Connect to TMDb website

$tmdb = Factory::create()->getTmdb('your_api_key');

$Auth = new Auth($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:, (*38)

$tmdb = Factory::create()->getTmdb('your_api_key');

$Auth = new Auth($tmdb);
$Auth->connect($_POST['request_token'], 'http://your_url');

Create a session

To use all account methods, we must use a valid session., (*39)

$tmdb = Factory::create()->getTmdb('62dfe9839b8937e595e325a4144702ad');

$Auth = new Auth($tmdb);
echo $Auth->createSession($_POST['request_token']);

Media Helper

All media informations delivered by the library are relative pathfile., (*40)

To get a valid media URL, use the Media class to generate the URL and check the media size, (*41)

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

The following type of media are supported : - Backdrop - Poster - Logo - Profile - Still, (*42)

Unit Testing

You can run the unit test suites using the following command in the library's source directory:, (*43)

$ make test

About

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub, (*44)

Author

Vincent Faliès - vincent@vfac.fr, (*45)

License

VfacTmdb is licensed under the MIT License - see the LICENSE file for details, (*46)

The Versions

24/04 2018

dev-master

9999999-dev https://vfac.fr/projects/tmdb

A PHP Wrapper for The Internet Movie Database API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

24/04 2018

dev-guzzlehttp/guzzle-6.3.3-#118.0.0

dev-guzzlehttp/guzzle-6.3.3-#118.0.0 https://vfac.fr/projects/tmdb

A PHP Wrapper for The Internet Movie Database API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

29/03 2018

dev-guzzlehttp/guzzle-6.3.2-#92.0.0

dev-guzzlehttp/guzzle-6.3.2-#92.0.0 https://vfac.fr/projects/tmdb

A PHP Wrapper for The Internet Movie Database API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

27/03 2018

1.6.4

1.6.4.0 https://vfac.fr/projects/tmdb

A PHP Wrapper for The Internet Movie Database API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

11/12 2017

v1.6.3

1.6.3.0 https://vfac.fr/projects/tmdb

A PHP Wrapper for The Internet Movie Database API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

20/10 2017

v1.6.2

1.6.2.0 https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

19/10 2017

v1.6.1

1.6.1.0 https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

19/10 2017

dev-development

dev-development https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

19/10 2017

v1.6.0

1.6.0.0 https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

18/10 2017

dev-docker

dev-docker https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

30/09 2017

dev-account

dev-account https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

22/09 2017

dev-auth

dev-auth https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

21/08 2017

dev-types

dev-types https://vfac.fr/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

18/07 2017

v1.5.0

1.5.0.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

17/07 2017

dev-similar

dev-similar https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

30/06 2017

v1.4.0

1.4.0.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

30/06 2017

dev-hotfix

dev-hotfix https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

23/06 2017

v1.3.3

1.3.3.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

22/06 2017

v1.3.2

1.3.2.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

21/06 2017

v1.3.1

1.3.1.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

20/06 2017

v1.3.0

1.3.0.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincent Faliès

12/06 2017

dev-people

dev-people https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès

12/06 2017

dev-tv_season

dev-tv_season https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès

09/06 2017

dev-generated_documentation

dev-generated_documentation https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès

08/06 2017

v1.2.0

1.2.0.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès

02/06 2017

v1.1.0

1.1.0.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès

02/06 2017

v1.0.1

1.0.1.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès

02/06 2017

v1.0.0

1.0.0.0 https://github.com/vfalies/tmdb

A PHP Wrapper for The Internet Movie Database API 3

  Sources   Download

MIT

The Requires

  • php > 7.1
  • ext-curl *

 

The Development Requires

by Vincent Faliès