コード例 #1
0
 /**
  * @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':
             try {
                 $xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $code . '.xml');
                 $video->setThumbnailUrl((string) $xml->video->thumbnail_large);
             } catch (\Exception $e) {
             }
             break;
         case 'dailymotion':
             try {
                 $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);
             } catch (\Exception $e) {
             }
             break;
     }
 }
コード例 #2
0
 /**
  * @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());
 }
コード例 #3
0
 /**
  * @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);
     }
     $audio = new RemoteAudioHelper($media);
     $code = $audio->getCode();
     //update thumbnail
     switch ($audio->getType()) {
         case 'soundcloud':
             $scData = json_decode(file_get_contents('http://api.soundcloud.com/tracks/' . $code . '.json?client_id=' . $this->getSoundcloudApiKey()));
             $artworkUrl = $scData->artwork_url;
             $artworkUrl = str_replace('large.jpg', 't500x500.jpg', $artworkUrl);
             $audio->setThumbnailUrl($artworkUrl);
             break;
     }
 }
コード例 #4
0
 /**
  * @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($json->thumbnail);
             } catch (\ErrorException $e) {
                 // Silent exception - should not bubble up since failure to create a thumbnail is not a fatal error
             }
             break;
     }
 }
コード例 #5
0
 /**
  * @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);
 }
コード例 #6
0
 /**
  *
  *
  * @param Media $media
  * @return string
  */
 private function getFilePath(Media $media)
 {
     $filename = $media->getOriginalFilename();
     $filename = str_replace(array('/', '\\', '%'), '', $filename);
     $slugifier = new Slugifier();
     if (!empty($this->blacklistedExtensions)) {
         $filename = preg_replace('/\\.(' . join('|', $this->blacklistedExtensions) . ')$/', '.txt', $filename);
     }
     $parts = pathinfo($filename);
     $filename = $slugifier->slugify($parts['filename']);
     $filename .= '.' . strtolower($parts['extension']);
     return sprintf('%s/%s', $media->getUuid(), $filename);
 }
コード例 #7
0
 /**
  * @covers Kunstmaan\MediaBundle\Entity\Media::getUuid
  * @covers Kunstmaan\MediaBundle\Entity\Media::setUuid
  */
 public function testGetSetUuid()
 {
     $this->object->setUuid('abc');
     $this->assertEquals('abc', $this->object->getUuid());
 }
コード例 #8
0
 /**
  *
  *
  * @param Media $media
  * @return string
  */
 private function getFilePath(Media $media)
 {
     $filename = $media->getOriginalFilename();
     $filename = str_replace(array('/', '\\'), '', $filename);
     if (!empty($this->blacklistedExtensions)) {
         $filename = preg_replace('/\\.(' . join('|', $this->blacklistedExtensions) . ')$/', '.txt', $filename);
     }
     return sprintf('%s/%s', $media->getUuid(), $filename);
 }