Search code examples
phpapiitunespodcast

Get Podcast details from iTunes url


Is it possible to return the title, description, and image link for a Podcast on iTunes if you have the url?

For example, with the following url from iTunes:

https://itunes.apple.com/us/podcast/civil-beat-pod-squad/id902069464?mt=2

Can we get the Podcast details via an API call or something along those lines? Ideally we would like to use php to return the details.


Solution

  • You can use the iTunes Search API to fetch Podcast Information which will have the Track Title and Image.

    Using your URL as an example, you can strip out the id "90206964" and use CURL.

    function getID($url) {
         $id_pos = strpos($url, "/id") + 3;
         $length = strpos($url, "?", $id_pos) - $id_pos;
         return substr($url, $id_pos, $length);
    }
    
    function fetchFromiTunes($id) {
         $ch = curl_init("https://itunes.apple.com/lookup?id=" . $id);
         $options = array(
                 CURLOPT_RETURNTRANSFER => true,
                 CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
            );
         curl_setopt_array( $ch, $options );
    
         $results = curl_exec($ch);
         $results = json_decode($results,true);
    
         echo "[Podcast Title]" . $results["results"][0]["collectionName"] . "\n[Artwork]" . $results["results"][0]["artworkUrl600"] . "\n";
         curl_close($ch);
    }