/** * @param Media $media * * @throws \RuntimeException when the file does not exist */ public function prepareMedia(Media $media) { if (null == $media->getUuid()) { $uuid = uniqid(); $media->setUuid($uuid); } $video = new RemoteVideoHelper($media); $code = $video->getCode(); //update thumbnail switch ($video->getType()) { case 'youtube': $video->setThumbnailUrl('http://img.youtube.com/vi/' . $code . '/0.jpg'); break; case 'vimeo': $xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $code . '.xml'); $video->setThumbnailUrl((string) $xml->video->thumbnail_large); break; case 'dailymotion': $json = json_decode(file_get_contents('https://api.dailymotion.com/video/' . $code . '?fields=thumbnail_large_url')); $thumbnailUrl = $json->{'thumbnail_large_url'}; /* dirty hack to fix urls for imagine */ if (!$this->endsWith($thumbnailUrl, '.jpg') && !$this->endsWith($thumbnailUrl, '.png')) { $thumbnailUrl = $thumbnailUrl . '&ext=.jpg'; } $video->setThumbnailUrl($thumbnailUrl); break; } }
/** * @param Media $media */ public function delete(Media $media) { $em = $this->getEntityManager(); $media->setDeleted(true); $em->persist($media); $em->flush(); }
/** * @param Media $media * * @throws \RuntimeException when the file does not exist */ public function prepareMedia(Media $media) { if (null == $media->getUuid()) { $uuid = uniqid(); $media->setUuid($uuid); } $slide = new RemoteSlideHelper($media); $code = $slide->getCode(); //update thumbnail switch ($slide->getType()) { case 'slideshare': try { $json = json_decode(file_get_contents('http://www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/slideshow/embed_code/' . $code . '&format=json')); $slide->setThumbnailUrl('http:' . $json->thumbnail); } catch (\ErrorException $e) { } break; } }
/** * @param File $file */ public function setFile(File $file) { $this->file = $file; $this->media->setContent($file); $this->media->setContentType($file->getMimeType()); $this->media->setUrl('/uploads/media/' . $this->media->getUuid() . '.' . $this->media->getContent()->getExtension()); }
/** * @param Media $media * * @return \Gaufrette\File */ public function getOriginalFile(Media $media) { $relativePath = sprintf('/%s.%s', $media->getUuid(), ExtensionGuesser::getInstance()->guess($media->getContentType())); return $this->fileSystem->get($relativePath, true); }
/** * @param Media $media The media entity * @param string $basepath The base path * * @return string */ public function getImageUrl(Media $media, $basepath) { return $basepath . $media->getUrl(); }
/** * Set type. * * @param string $type * * @return RemoteSlideHelper */ public function setType($type) { $this->media->setMetadataValue('type', $type); return $this; }