apiurl = 'https://gdata.youtube.com/feeds/api/'; } public function get_video($url, $id) { // TODO See if it would make sense to specify the "key" parameter $request_url = $this->apiurl."videos?q={$url}&alt=json"; $ch = curl_init($request_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpcode == 200) { $json = json_decode($data); if (isset($json->feed->entry) && is_array($json->feed->entry) && sizeof($json->feed->entry)>0) { foreach ($json->feed->entry as $entry) { if (strrpos($entry->id->{'$t'}, $id) === strlen($entry->id->{'$t'})-strlen($id)) { return $entry; } } } return false; } return false; } }