javascriptphpimdb

How to convert TMDB ID to IMDB ID


This API url: https://api.themoviedb.org/3/tv/1399?api_key=8d6d91941230817f7807d643736e8a49&append_to_response=external_ids outputs IMDB ID with a lot of things including this result:

{"imdb_id":"tt0944947","freebase_mid":"/m/0524b41","freebase_id":"/en/game_of_thrones","tvdb_id":121361,"tvrage_id":24493,"facebook_id":"GameOfThrones","instagram_id":"gameofthrones","twitter_id":"GameOfThrones"}}

I have this code on my file:

<?php
$values = info_movie_get_meta( 'ids' );



$seson = info_movie_get_meta( 'temporada' );
$epi = info_movie_get_meta( 'episodio' );

echo '<iframe src="https://videospider.in/getvideo?key=Ez99ULqORLkSi7LH&video_id='.$values.'&tmdb=1&tv=1&s='.$seson.'&e='.$epi.'"height="100%"allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" frameborder="0"></iframe>';
?>

Here, $values = TMDB ID (I have TMDB ID need IMDB), and on my provided API URL https://api.themoviedb.org/3/tv/1399?.... Here 1399 is TMDB ID,... So I will extract the IMDB ID from TMDB ID with this: https://api.themoviedb.org/3/tv/$values?.... Now, I have this code: echo '<iframe src="https://videospider.in/getvideo?key=Ez99ULqORLkSi7LH&video_id='.$values.'..... Here in the place of $values, I want to insert IMDB ID,.... I have the TMDB ID, API to Convert to TMDB to IMDB and I have IMDB ID in JS result, so how I will insert the only IMDB ID here: echo '<iframe src="https://videospider.in/getvideo?key=Ez99ULqORLkSi7LH&video_id=imdbID,......


Solution

  • It's quite easy. Just grab the link like file_get_contents or CURL, then use json_decode and you can have access to the IMDB ID as a variable.

    $showID     =1399;
    $url        ='https://api.themoviedb.org/3/tv/'.$showID.'?api_key=8d6d91941230817f7807d643736e8a49&append_to_response=external_ids';
    $content    =file_get_contents($url,false);
    $json       =json_decode($content,true);
    $imdbID     =$json['external_ids']['imdb_id'];
    $iframeURL  ='https://videospider.in/getvideo?key=Ez99ULqORLkSi7LH&video_id='.$imdbID.'&tv=1&s='.$seson.'&e='.$epi;