title || !$apiVideo->thumbnail_url) { return; } // Extract Youtube ID from Thumbnail URL // This code assumes that the Youtube ID is second in the thumbnail's // path. For example, http://i2.ytimg.com/vi/YOUTUBEID/thumbnail.ext $thumbnailPath = parse_url($apiVideo->thumbnail_url, PHP_URL_PATH); $thumbnailPathParts = explode('/', $thumbnailPath); $extractedID = $thumbnailPathParts[2]; // Validate Extracted Youtube ID /* FIXME: YouTube has discontinued this API: $handle = curl_init("http://gdata.youtube.com/feeds/api/videos/{$extractedID}"); curl_setopt($handle, CURLOPT_NOBODY , true); curl_exec($handle); $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); curl_close($handle); if ($statusCode != 200) { return; } */ $this->id = $extractedID; $this->title = $apiVideo->title; $this->thumbnailUrl = $apiVideo->thumbnail_url; } /************************************************************************** * Getters **************************************************************************/ /** * Indicates whether the URL points to a video * * @return boolean */ public function isValid() { return !is_null($this->id); } /** * Unique identifier generated by the video-sharing site * * @return string */ public function getID() { return $this->id; } /** * Title of the video * * @return string */ public function getTitle() { return $this->title; } /** * Thumbnail image address * * @return string */ public function getThumbnailUrl() { return $this->thumbnailUrl; } }