public function validateVideoUrl($value, ExecutionContextInterface $context) { $this->currentVideo = null; // vimeo preg_match(Video::RE_VIMEO, $value, $m); if (sizeof($m) !== 0) { $v = new Video(); $v->setType(Video::TYPE_VIMEO); $v->setOriginalUrl($value); $v->setVideoId($m[1]); $v->setEmbedUrl("http://player.vimeo.com/video/{$m[1]}?api=1&player_id=player"); // try obtain thumbnail url try { $json = file_get_contents("http://vimeo.com/api/v2/video/{$m[1]}.json"); $desc = json_decode($json, true); $v->setThumbnailUrl($desc[0]['thumbnail_small']); } catch (Exception $e) { $msg = sprintf("FAIL fetching thumbnail for '%s'", $value); $this->logger->error($msg); $this->logger->error($e->getTraceAsString()); } $this->currentVideo = $v; return; } // youtube preg_match(Video::RE_YOUTUBE, $value, $m); if (sizeof($m) > 1) { $v = new Video(); $v->setType(Video::TYPE_YOUTUBE); $v->setOriginalUrl($value); $v->setVideoId($m[1]); $v->setEmbedUrl("https://www.youtube.com/embed/{$m[1]}"); $v->setThumbnailUrl("https://i.ytimg.com/vi/{$m[1]}/default.jpg"); $this->currentVideo = $v; return; } $context->buildViolation('This is not a valid Youtube or Vimeo url.')->atPath('videoUrl')->addViolation(); }