| .*v= # or /watch\\?v= ) # End path alternatives. ) # End host alternatives. ([\\w-]{10,12}) # Allow 10-12 for 11 char youtube id. ($|&).* # if additional parameters are also in query string after video id. $%x'; $result = preg_match($pattern, $url, $matches); // No ID match? Bad URL. if ($result === false) { $bigtree["errors"][] = array("field" => $field["title"], "error" => "The URL you entered is not a valid YouTube URL."); $field["ignore"] = true; // Got our YouTube ID } else { $video_id = $matches[1]; $youtube = new BigTreeYouTubeAPI(); $video = $youtube->getVideo($video_id); // Invalid YouTube video :( if (!$video) { $bigtree["errors"][] = array("field" => $field["title"], "error" => "The YouTube URL provided is invalid."); $field["ignore"] = true; } else { // Try for max resolution first, then high, then default $source_image = $video->Images->Maxres ? $video->Images->Maxres : $video->Images->High; $source_image = $source_image ? $source_image : $video->Images->Default; $field["output"] = array("service" => "youtube", "id" => $video_id, "height" => false, "width" => false, "duration" => $video->Duration->Hours * 3600 + $video->Duration->Minutes * 60 + $video->Duration->Seconds, "embed" => $video->Embed); } } // Vimeo } elseif (strpos($url, "vimeo.com") !== false) { $url_pieces = explode("/", $url); $video_id = end($url_pieces);