コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/vimeo\\.com\\/(\\d+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/www.dailymotion.com\\/video\\/([0-9a-zA-Z]*)_/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/(?<=v(\\=|\\/))([-a-zA-Z0-9_]+)|(?<=youtu\\.be\\/)([-a-zA-Z0-9_]+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[2]);
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (strlen($media->getBinaryContent()) === 11) {
         return;
     }
     if (preg_match("/^(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:youtu\\.be\\/|youtube\\.com\\/(?:(?:watch)?\\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\\/))([^\\#\\?&\"'>]+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (strlen($media->getBinaryContent()) === 11) {
         return;
     }
     if (preg_match("/videos\\.sapo\\.pt\\/([A-Za-z0-9]+)(\\/mov\\/)?/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (strpos($media->getBinaryContent(), '|') !== FALSE) {
         return;
     }
     if (preg_match('/(?:config\\.|player\\.)?playwire.com\\/(\\d+)\\/videos\\/v2\\/(\\d+)\\//', $media->getBinaryContent(), $matches)) {
         $binary = sprintf('%d|%d', $matches[1], $matches[2]);
         $media->setBinaryContent($binary);
     }
 }
コード例 #7
0
 /**
  * @throws \RuntimeException
  * @param \Sonata\MediaBundle\Model\MediaInterface $media
  * @return mixed|null|string
  */
 public function getMetadata(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return null;
     }
     $url = sprintf('http://www.dailymotion.com/services/oembed?url=http://www.dailymotion.com/video/%s&format=json', $media->getBinaryContent());
     $metadata = @file_get_contents($url);
     if (!$metadata) {
         throw new \RuntimeException('Unable to retrieve dailymotion video information for :' . $url);
     }
     $metadata = json_decode($metadata, true);
     if (!$metadata) {
         throw new \RuntimeException('Unable to decode dailymotion video information for :' . $url);
     }
     return $metadata;
 }
コード例 #8
0
ファイル: BaseProvider.php プロジェクト: ingeniorweb/symfo3cv
 /**
  * {@inheritdoc}
  */
 public final function transform(MediaInterface $media)
 {
     if (null === $media->getBinaryContent()) {
         return;
     }
     $this->doTransform($media);
 }
コード例 #9
0
 public function getMetadata(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     $format = 'reference';
     $getId3 = new GetId3();
     $fileinfo = $getId3->setOptionMD5Data(true)->setOptionMD5DataSource(true)->setEncoding('UTF-8')->analyze($media->getBinaryContent()->getPathname());
     $metadata = array('src' => $this->generatePublicUrl($media, $format), 'filesize' => $fileinfo['filesize'], 'fileformat' => $fileinfo['fileformat'], 'encoding' => $fileinfo['encoding'], 'mime_type' => $fileinfo['mime_type'], 'playtime_seconds' => $fileinfo['playtime_seconds'], 'playtime_string' => $fileinfo['playtime_string'], 'bitrate' => $fileinfo['bitrate'], 'audio_dataformat' => $fileinfo['audio']['dataformat'], 'audio_codec' => isset($fileinfo['audio']['codec']) ? $fileinfo['audio']['codec'] : '', 'audio_sample_rate' => $fileinfo['audio']['sample_rate'], 'audio_channels' => $fileinfo['audio']['channels'], 'audio_bits_per_sample' => isset($fileinfo['audio']['bits_per_sample']) ? $fileinfo['audio']['bits_per_sample'] : '', 'audio_lossless' => isset($fileinfo['audio']['lossless']) ? $fileinfo['audio']['lossless'] : '', 'audio_channelmode' => isset($fileinfo['audio']['channelmode']) ? $fileinfo['audio']['channelmode'] : '', 'video_dataformat' => $fileinfo['video']['dataformat'], 'video_resolution_x' => $fileinfo['video']['resolution_x'], 'video_resolution_y' => $fileinfo['video']['resolution_y'], 'video_fourcc' => isset($fileinfo['video']['fourcc']) ? $fileinfo['video']['fourcc'] : '', 'video_frame_rate' => $fileinfo['video']['frame_rate'], 'video_codec' => isset($fileinfo['video']['codec']) ? $fileinfo['video']['codec'] : '');
     /*echo "<pre>";
       print_r($metadata);
       print_r($fileinfo);
       echo "</pre>";
       exit();*/
     return $metadata;
 }
コード例 #10
0
 protected function createQrCode(MediaInterface $media)
 {
     $path = tempnam(sys_get_temp_dir(), 'sonata_media_qrcode_reference') . '.' . $this->config['extension'];
     $qrCode = new QrCode();
     $qrCode->setText($media->getBinaryContent())->setSize($this->config['size'])->setPadding($this->config['padding'])->setErrorCorrection($this->config['error_correction'])->setForegroundColor($this->config['foreground'])->setBackgroundColor($this->config['background'])->setLabel($this->config['label'])->setLabelFontSize($this->config['label_size'])->setImageType($this->config['extension']);
     if ($this->config['logo'] && is_file($this->config['logo'])) {
         $qrCode->setLogo($this->config['logo']);
     }
     $qrCode->save($path);
     return $path;
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function updateMetadata(MediaInterface $media, $force = true)
 {
     try {
         if (!$media->getBinaryContent() instanceof \SplFileInfo) {
             // this is now optimized at all!!!
             $path = tempnam(sys_get_temp_dir(), 'sonata_update_metadata');
             $fileObject = new \SplFileObject($path, 'w');
             $fileObject->fwrite($this->getReferenceFile($media)->getContent());
         } else {
             $fileObject = $media->getBinaryContent();
         }
         $image = $this->imagineAdapter->open($fileObject->getPathname());
         $size = $image->getSize();
         $media->setSize($fileObject->getSize());
         $media->setWidth($size->getWidth());
         $media->setHeight($size->getHeight());
     } catch (\LogicException $e) {
         $media->setProviderStatus(MediaInterface::STATUS_ERROR);
         $media->setSize(0);
         $media->setWidth(0);
         $media->setHeight(0);
     }
 }
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 public function postPersist(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     $this->generateThumbnails($media);
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function postPersist(MediaInterface $media)
 {
     if ($media->getBinaryContent() === null) {
         return;
     }
     $this->setFileContents($media);
     $this->generateThumbnails($media);
 }
コード例 #14
0
 /**
  * Set media binary content according to request content.
  *
  * @param MediaInterface $media
  */
 protected function generateBinaryFromRequest(MediaInterface $media)
 {
     if (php_sapi_name() === 'cli') {
         throw new \RuntimeException('The current process cannot be executed in cli environment');
     }
     if (!$media->getContentType()) {
         throw new \RuntimeException('You must provide the content type value for your media before setting the binary content');
     }
     $request = $media->getBinaryContent();
     if (!$request instanceof Request) {
         throw new \RuntimeException('Expected Request in binary content');
     }
     $content = $request->getContent();
     // create unique id for media reference
     $guesser = ExtensionGuesser::getInstance();
     $extension = $guesser->guess($media->getContentType());
     if (!$extension) {
         throw new \RuntimeException(sprintf('Unable to guess extension for content type %s', $media->getContentType()));
     }
     $handle = tmpfile();
     fwrite($handle, $content);
     $file = new ApiMediaFile($handle);
     $file->setExtension($extension);
     $file->setMimetype($media->getContentType());
     $media->setBinaryContent($file);
 }
コード例 #15
0
 /**
  * Set the file contents for a video
  *
  * @param \Sonata\MediaBundle\Model\MediaInterface $media
  * @param string $contents path to contents, defaults to MediaInterface BinaryContent
  *
  * @return void
  */
 protected function setFileContents(MediaInterface $media, $contents = null)
 {
     if (!$contents) {
         $contents = $media->getBinaryContent()->getRealPath();
     }
     $destination = sprintf('%s/%s/', $this->getFilesystem()->getAdapter()->getDirectory(), $this->generatePath($media));
     if (!is_dir($destination)) {
         mkdir($destination, 775, true);
     }
     if (is_uploaded_file($contents)) {
         move_uploaded_file($contents, $destination . $media->getProviderReference());
     } else {
         copy($contents, $destination . $media->getProviderReference());
     }
 }
コード例 #16
0
ファイル: FileProvider.php プロジェクト: ingeniorweb/symfo3cv
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, MediaInterface $media)
 {
     if (!$media->getBinaryContent() instanceof \SplFileInfo) {
         return;
     }
     if ($media->getBinaryContent() instanceof UploadedFile) {
         $fileName = $media->getBinaryContent()->getClientOriginalName();
     } elseif ($media->getBinaryContent() instanceof File) {
         $fileName = $media->getBinaryContent()->getFilename();
     } else {
         throw new \RuntimeException(sprintf('Invalid binary content type: %s', get_class($media->getBinaryContent())));
     }
     if (!in_array(strtolower(pathinfo($fileName, PATHINFO_EXTENSION)), $this->allowedExtensions)) {
         $errorElement->with('binaryContent')->addViolation('Invalid extensions')->end();
     }
     if (!in_array($media->getBinaryContent()->getMimeType(), $this->allowedMimeTypes)) {
         $errorElement->with('binaryContent')->addViolation('Invalid mime type : ' . $media->getBinaryContent()->getMimeType())->end();
     }
 }
コード例 #17
0
ファイル: FileProvider.php プロジェクト: ronnylt/MediaBundle
    /**
     * @throws \RuntimeException
     * @param \Sonata\MediaBundle\Model\MediaInterface $media
     * @return void
     */
    protected function fixFilename(MediaInterface $media)
    {
        if ($media->getBinaryContent() instanceof UploadedFile) {
            $media->setName($media->getBinaryContent()->getOriginalName());
        } else if ($media->getBinaryContent() instanceof File) {
            $media->setName($media->getBinaryContent()->getName());
        } else {
            $mediaName = false;
        }

        // this is the original name
        if (!$media->getName() && !$mediaName) {
            throw new \RuntimeException('Please define a valid media\'s name');
        } else if (!$media->getName()) {
            $media->setName($mediaName);
        }
    }
コード例 #18
0
ファイル: VimeoProvider.php プロジェクト: ronnylt/MediaBundle
    /**
     * @throws \RuntimeException
     * @param \Sonata\MediaBundle\Entity\BaseMedia $media
     * @return mixed|string
     */
    public function getMetadata(MediaInterface $media)
    {
        if (!$media->getBinaryContent()) {
            return null;
        }

        $url = sprintf('http://vimeo.com/api/oembed.json?url=http://vimeo.com/%s', $media->getBinaryContent());
        $metadata = @file_get_contents($url);

        if (!$metadata) {
            throw new \RuntimeException('Unable to retrieve vimeo video information for :' . $url);
        }

        $metadata = json_decode($metadata, true);

        if (!$metadata) {
            throw new \RuntimeException('Unable to decode vimeo video information for :' . $url);
        }

        return $metadata;
    }
コード例 #19
0
 /**
  * {@inheritdoc}
  */
 public function updateMetadata(MediaInterface $media, $force = true)
 {
     try {
         if (!$media->getBinaryContent() instanceof \SplFileInfo) {
             // this is now optimized at all!!!
             $dir = $this->getFilesystem()->getAdapter()->getDirectory();
             $movie_path = sprintf('%s/%s/%s', $dir, $this->generatePath($media), $media->getProviderReference());
             $fileObject = new \SplFileObject($movie_path, 'r');
         } else {
             $fileObject = $media->getBinaryContent();
         }
         $info = $this->getFFProbe()->format($media->getBinaryContent()->getPathname());
         $media->setLength($info->get('duration'));
         $media->setWidth(1300);
         $media->setHeight(250);
         $media->setProviderStatus(MediaInterface::STATUS_OK);
     } catch (\LogicException $e) {
         $media->setSize(0);
         $media->setWidth(0);
         $media->setHeight(0);
         $media->setProviderStatus(MediaInterface::STATUS_ERROR);
     }
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 public function updateMetadata(MediaInterface $media, $force = true)
 {
     try {
         if (!$media->getBinaryContent() instanceof \SplFileInfo) {
             // this is now optimized at all!!!
             $dir = $this->getFilesystem()->getAdapter()->getDirectory();
             $movie_path = sprintf('%s/%s/%s', $dir, $this->generatePath($media), $media->getProviderReference());
             $fileObject = new \SplFileObject($movie_path, 'r');
         } else {
             $fileObject = $media->getBinaryContent();
         }
         /* $ffprobe = \FFMpeg\FFProbe::create(); */
         $ffprobe = $this->getFFProbe();
         $dimension = $ffprobe->streams($fileObject->getPathname())->videos()->first()->getDimensions();
         $media->setSize($fileObject->getSize());
         $media->setWidth($dimension->getWidth());
         $media->setHeight($dimension->getHeight());
         $media->setProviderStatus(MediaInterface::STATUS_OK);
     } catch (\LogicException $e) {
         $media->setSize(0);
         $media->setWidth(0);
         $media->setHeight(0);
         $media->setProviderStatus(MediaInterface::STATUS_ERROR);
     }
 }