Generate a thumbnail for $media

@param MediaInterface $media
488834
public function generateThumbnail(MediaInterface $media)
    {
        $fileName = $media->getFilesystemName();
        $thumbnailName = '';

        $extractedImagePath = $this->imageManager->extractImageFromPdf(
            $this->tmpDir . DIRECTORY_SEPARATOR . $fileName
        );

        $thumbnailPath = $this->imageManager->generateAlternative($extractedImagePath, $this->thumbnailFormat);

        if ($thumbnailPath != '') {
            $thumbnailName = self::THUMBNAIL_PREFIX . '-' . str_replace('.pdf', '.jpg', $fileName);
            $this->mediaStorageManager->uploadFile($thumbnailName, $thumbnailPath);
        }

        if (trim($extractedImagePath, DIRECTORY_SEPARATOR) != trim($this->tmpDir, DIRECTORY_SEPARATOR)) {
            $this->fileSystem->remove(array($extractedImagePath));
        }

        $media->setThumbnail($thumbnailName);
    }
171450
public function generateFrontUrl(MediaInterface $media)
    {
        $path = null;

        if ($media->getType() === MediaTypes::IMAGE) {
            $path = $this->cacheManager->getBrowserPath($media->getPath(), 'media_front');
        } elseif (in_array($media->getType(), [MediaTypes::VIDEO, MediaTypes::AUDIO, MediaTypes::FLASH])) {
            $path = $this->urlGenerator->generate('ekyna_media_player', ['key' => $media->getPath()], true);
        } else {
            $path = $this->urlGenerator->generate('ekyna_media_download', ['key' => $media->getPath()], true);
        }

        return $path;
    }
1236946
public function getDownloadStrategy(MediaInterface $media)
    {
        $context = $this->getContext($media->getContext());

        $id = $context['download']['strategy'];

        // NEXT_MAJOR: remove this line with the next major release.
        if (isset($this->downloadSecurities[$id])) {
            return $this->downloadSecurities[$id];
        }

        if (!isset($this->downloadStrategies[$id])) {
            throw new \RuntimeException('Unable to retrieve the download security : '.$id);
        }

        return $this->downloadStrategies[$id];
    }
295115
private function getImageUrl($media, $locale)
    {
        $mediaApi = new Media($media, $locale);
        $this->mediaManager->addFormatsAndUrl($mediaApi);
        $formats = $mediaApi->getThumbnails();

        if (!isset($formats[$this->searchImageFormat])) {
            $this->logger->warning(sprintf(
                'Media with ID "%s" does not have thumbnail format "%s". This thumbnail would be used by the search results.',
                $media->getId(),
                $this->searchImageFormat
            ));

            return;
        }

        return $formats[$this->searchImageFormat];
    }
855323
public function transform($media)
    {
        if (null === $media || !$media instanceof \Apoutchika\MediaBundle\Model\MediaInterface) {
            return '';
        }

        return $media->getId();
    }
717461
public function updateMedadata(MediaInterface $media)
    {
        try {
            $url = sprintf(
                'https://www.googleapis.com/youtube/v3/videos?id=%s&key=%s&part=snippet,contentDetails,statistics,status',
                $media->getReference(),
                $this->apikey
            );
            $metadata = $this->getMetadata($media, $url);
        } catch (\RuntimeException $e) {
            $media->setStatus(Media::STATUS_DISABLED);

            return;
        }

        $metadata = $metadata['items'][0];
        $metadata['contentDetails']['duration'] = $this->convertDuration($metadata['contentDetails']['duration']);

        if (!$media->getName()) {
            $media->setName($metadata['snippet']['title']);
        }

        $thumb = $this->saveThumbnail($media, $metadata['snippet']['thumbnails']['high']['url']);
        $media->setThumb($thumb);

        $media->setMetadata($metadata);
        $media->setContentType('video/x-flv');
    }
334814
public function getMediaFormatUrl(MediaInterface $media, $format)
    {
        $key = $media->getFilesystemName();

        if ($format != '' && MediaInterface::MEDIA_ORIGINAL != $format) {
            $key = $media->getAlternative($format);
        }

        return $this->getFileUrl($key);
    }
900156
private function addInfosForFront(MediaInterface $media)
    {
        $mediaManager = $this->getMediaManager();

        $media->setUrls(array(
            'original' => $mediaManager->getUrl($media),
            '500x400' => $mediaManager->getUrl($media, '500x400'),
            '78x44_focus' => $mediaManager->getUrl($media, '78x44_focus'),
        ));

        $media->setHtml(
            $mediaManager->getHtml($media)
        );

        return $media;
    }
299300
public function updateFocus(MediaInterface $media)
    {
        if ($this->direction == 'x') {
            $media->setFocusLeft(100 - $media->getFocusLeft());
        } elseif ($this->direction == 'y') {
            $media->setFocusTop(100 - $media->getFocusTop());
        }
    }
1058798
public function preSave(MediaInterface $media)
    {
        preg_match('/(?<=v(\=|\/))([-a-zA-Z0-9_]+)|(?<=youtu\.be\/)([-a-zA-Z0-9_]+)/', $media->getReference(), $matches);

        $media->setReference($matches[2]);

        //Check if the reference already exists
        if (!isset($media->old) && $referenceMedia = $this->mediaManager->getRepository()->findOneBy(['reference' => $media->getReference()])) {
            throw new \Exception(sprintf('Video with reference: %s already exists for under the name: %s', $media->getReference(), $referenceMedia->getName()));
        }

        if (!isset($media->old) || $media->old->getReference() !== $media->getReference()) {
            $this->updateMedadata($media);
        }
    }
569595
protected function getExtension(MediaInterface $media)
    {
        $ext = $media->getExtension();
        if (!\is_string($ext) || \strlen($ext) < 3) {
            $ext = $this->defaultFormat;
        }

        return $ext;
    }
694432
public function addMedia(Media $media)
	{
		$this->media[] = $media;
		$media->addGallery($this);

		return $this;
	}
66377
public function prepareMedia(Media $media)
    {
        if (null === $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }
        $content = $media->getContent();
        if (empty($content)) {
            return;
        }
        if (!$content instanceof File) {
            if (!is_file($content)) {
                throw new \RuntimeException('Invalid file');
            }
            $file = new File($content);
            $media->setContent($file);
        }
        if ($content instanceof UploadedFile) {
            $pathInfo = pathinfo($content->getClientOriginalName());
            $media->setOriginalFilename($this->urlizer->urlize($pathInfo['filename']).'.'.$pathInfo['extension']);
            $name = $media->getName();
            if (empty($name)) {
                $media->setName($media->getOriginalFilename());
            }
        }
        $media->setFileSize(filesize($media->getContent()));
        $contentType = $this->mimeTypeGuesser->guess($media->getContent()->getPathname());
        $media->setContentType($contentType);
        $relativePath = sprintf('/%s.%s', $media->getUuid(), ExtensionGuesser::getInstance()->guess($media->getContentType()));
        $media->setUrl('/uploads/media'.$relativePath);
        $media->setLocation('local');
    }
932565
public function updateSourceField(
    MediaInterface $media,
    $resource,
    $mimetype
  ) {
    $source_field = $this->getSourceFieldName($media->bundle());
    $file = $this->getSourceFile($media);

    // Update it.
    $this->updateFile($file, $resource, $mimetype);
    $file->save();

    // Set fields provided by type plugin and mapped in bundle configuration
    // for the media.
    foreach ($media->bundle->entity->getFieldMap() as $source => $destination) {
      if ($media->hasField($destination) && $value = $media->getSource()->getMetadata($media, $source)) {
        $media->set($destination, $value);
      }
      // Ensure width and height are updated on File reference when it's an
      // image. Otherwise you run into scaling problems when updating images
      // with different sizes.
      if ($source == 'width' || $source == 'height') {
        $media->get($source_field)->first()->set($source, $value);
      }
    }

    $media->save();
  }
913230
public function getMediaFormatUrl(MediaInterface $media, $format)
    {
        /** @var DisplayMediaInterface $strategy */
        foreach ($this->strategies as $strategy) {
            if ($strategy->support($media)) {
                return $strategy->getMediaFormatUrl($media, $format);
            }
        }

        return $this->defaultStrategy->getMediaFormatUrl($media, $format);
    }
1128751
public function addMedia(MediaInterface $media)
    {
        if (!$this->medias->contains($media)) {
            $this->medias->add($media);
        }
        return $this;
    }
659724
public function getAliasAndKey(MediaInterface $media, $alias = null)
    {
        $aliasManipulator = $this->aliasManipulatorFactory->setAlias($alias);

        if ($media->getType() === $media::IMAGE) {
            $alias = $aliasManipulator->getAliasName();

            if ($alias !== $this->originalDir) {
                $this->cropImage($media, $aliasManipulator);
            }
        } else {
            $alias = $this->originalDir;
        }

        return $alias.'/'.$media->getReference();
    }