@throws \RuntimeException

@param MediaInterface $media
@param string         $url

@return mixed
162077
protected function getMetadata(MediaInterface $media, $url)
    {
        try {
            $metadata = file_get_contents($url);
        } catch (\RuntimeException $e) {
            throw new \RuntimeException('Unable to retrieve the video information for :'.$url, null, $e);
        }

        $metadata = json_decode($metadata, true);

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

        return $metadata;
    }
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;
    }
842415
public function updateFocus(MediaInterface $media)
    {
        $originalFocusLeftPx = ($media->getFocusLeft() * $media->getWidth()) / 100;
        $newFocusLeftPx = $originalFocusLeftPx - $this->x;
        $newFocusLeft = ($newFocusLeftPx * 100) / $this->w;

        if ($newFocusLeft < 0) {
            $newFocusLeft = 0;
        }
        if ($newFocusLeft > 100) {
            $newFocusLeft = 100;
        }

        $media->setFocusLeft($newFocusLeft);

        $originalFocusTopPx = ($media->getFocusTop() * $media->getHeight()) / 100;
        $newFocusTopPx = $originalFocusTopPx - $this->y;
        $newFocusTop = ($newFocusTopPx * 100) / $this->h;

        if ($newFocusTop < 0) {
            $newFocusTop = 0;
        }
        if ($newFocusTop > 100) {
            $newFocusTop = 100;
        }

        $media->setFocusTop($newFocusTop);
    }
475266
public function getMetadata(MediaInterface $media)
    {
        try {
            $oembed_endpoint = 'http://vimeo.com/api/oembed';

            $xml_url = $oembed_endpoint . '.xml?url=' . rawurlencode($media->getReference());

            $curl = curl_init($xml_url);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_TIMEOUT, 30);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
            $vimeoResult = curl_exec($curl);
            curl_close($curl);
        } catch (\RuntimeException $e) {
            throw new \RuntimeException('Unable to retrieve the video information for :'.$url, null, $e);
        }

        $metadata = simplexml_load_string($vimeoResult);

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

        return $metadata;
    }
1311095
public function registerCssFile($url, $media = '')
    {
        if (($cs = $this->getClientScript()) === false) {
            return null;
        }
        if (isset($this->_assetsUrl)) {
            $url = $this->_assetsUrl . '/' . ltrim($url, '/');
        }
        return $cs->registerCssFile($url, $media);
    }
1128751
public function addMedia(MediaInterface $media)
    {
        if (!$this->medias->contains($media)) {
            $this->medias->add($media);
        }
        return $this;
    }
111345
public function getUrl(MediaInterface $media, $alias = null)
    {
        return $this->filesystemManipulator->url($this->getAliasAndKey($media, $alias));
    }
1116322
protected function getResponse(string $url):ResponseInterface {
		curl_setopt($this->curl, CURLOPT_URL, $url);

		return new Response($this->curl);
	}
1263841
public function initialize($url, $user = null, $password = null)
    {
        // stupid, but surpresses phpcs warnings
        $user;
        $password;

        if (is_dir($this->root)) {
            if (count(glob($this->root . '/*'))) {
                throw new \RuntimeException("Checkout of $url failed");
            }

            rmdir($this->root);
        }

        // Fix incorrect windows checkout URLs
        $url = preg_replace('(^file://([A-Za-z]):)', 'file:///\\1:', $url);

        $process = new \Arbit\VCSWrapper\HgCli\Process();
        $process->argument('clone');
        $process->argument(str_replace('\\', '/', $url));
        $process->argument(new \SystemProcess\Argument\PathArgument($this->root));
        $return = $process->execute();

        // Cache basic revision information for checkout and update
        // currentVersion property.
        $this->getResourceInfo();
    }
523660
protected function fixFilename(MediaInterface $media)
    {
        if ($media->getBinaryContent() instanceof UploadedFile) {
            $media->setName($media->getName() ?: $media->getBinaryContent()->getClientOriginalName());
            $media->setMetadataValue('filename', $media->getBinaryContent()->getClientOriginalName());
        } elseif ($media->getBinaryContent() instanceof File) {
            $media->setName($media->getName() ?: $media->getBinaryContent()->getBasename());
            $media->setMetadataValue('filename', $media->getBinaryContent()->getBasename());
        }

        // this is the original name
        if (!$media->getName()) {
            throw new \RuntimeException('Please define a valid media\'s name');
        }
    }
725580
protected function generateData(EntityInterface $entity) {
    $data = parent::generateData($entity);

    // Find media belonging to node that has the source term, and set its file
    // url in the data array.
    $source_term = $this->utils->getTermForUri($this->configuration['source_term_uri']);
    if (!$source_term) {
      throw new \RuntimeException("Could not locate source term with uri" . $this->configuration['source_term_uri'], 500);
    }

    $source_media = $this->utils->getMediaWithTerm($entity, $source_term);
    if (!$source_media) {
      throw new \RuntimeException("Could not locate source media", 500);
    }

    $source_file = $this->mediaSource->getSourceFile($source_media);
    if (!$source_file) {
      throw new \RuntimeException("Could not locate source file for media {$source_media->id()}", 500);
    }

    $data['source_uri'] = $source_file->url('canonical', ['absolute' => TRUE]);

    // Find the term for the derivative and use it to set the destination url
    // in the data array.
    $derivative_term = $this->utils->getTermForUri($this->configuration['derivative_term_uri']);
    if (!$source_term) {
      throw new \RuntimeException("Could not locate derivative term with uri" . $this->configuration['derivative_term_uri'], 500);
    }

    $route_params = [
      'node' => $entity->id(),
      'media_type' => $this->configuration['destination_media_type'],
      'taxonomy_term' => $derivative_term->id(),
    ];
    $data['destination_uri'] = Url::fromRoute('islandora.media_source_put_to_node', $route_params)
      ->setAbsolute()
      ->toString();

    $token_data = [
      'node' => $entity,
      'media' => $source_media,
      'term' => $derivative_term,
    ];
    $path = $this->token->replace($data['path'], $token_data);
    $data['file_upload_uri'] = $data['scheme'] . '://' . $path;

    // Get rid of some config so we just pass along
    // what the camel route and microservice need.
    unset($data['source_term_uri']);
    unset($data['derivative_term_uri']);
    unset($data['path']);
    unset($data['scheme']);
    unset($data['destination_media_type']);

    return $data;
  }
1160536
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':
                try {
                    if (@fopen('https://img.youtube.com/vi/'.$code.'/maxresdefault.jpg', 'r') === false) {
                        $video->setThumbnailUrl('https://img.youtube.com/vi/'.$code.'/0.jpg');
                    } else {
                        $video->setThumbnailUrl('https://img.youtube.com/vi/'.$code.'/maxresdefault.jpg');
                    }
                } catch (\Exception $e) {
                }

                break;
            case 'vimeo':
                try {
                    $xml = simplexml_load_file('https://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;
        }
    }
724273
private static function uploadImage(MediaService $mediaService, $url)
    {
        // Creates an image and upload it to the server.
        $image = new Image();
        $image->setData(file_get_contents($url));
        $image->setType(MediaMediaType::IMAGE);

        return $mediaService->upload([$image])[0];
    }
643349
public function getHtml(MediaInterface $media, $alias = null)
    {
        if ($media->getType() == $media::IMAGE) {
            $template = 'ApoutchikaMediaBundle:Render:image.html.twig';
        } elseif ($media->getType() == $media::VIDEO) {
            $template = 'ApoutchikaMediaBundle:Render:video.html.twig';
        } elseif ($media->getType() == $media::AUDIO) {
            $template = 'ApoutchikaMediaBundle:Render:audio.html.twig';
        } else {
            $template = 'ApoutchikaMediaBundle:Render:other.html.twig';
        }

        return $this->container->get('templating')->render($template, array(
            'media' => $media,
            'alias' => $alias,
            'url' => $this->getAbsoluteUrl($media, $alias),
        ));
    }
191853
public function create($uri, $content)
    {
        $uri = '/' . trim($uri, '/');

        foreach ($this->patterns as $pattern => $key) {
            if (preg_match($pattern, $uri)) {
                return call_user_func($this->builders[$key], (array) $content);
            }
        }

        throw new RuntimeException(sprintf('Cannot create resource by URI "%s"', $uri));
    }
1254419
public function registerCssFile($url, $media = '')
    {
        if (isset($this->_assetsUrl)) {
            $url = $this->_assetsUrl . '/' . ltrim($url, '/');
        }
        $this->getClientScript()->registerCssFile($url, $media);
    }
475217
private function getRemoteData(string $url): ResponseInterface
    {
        $context      = $this->streamHelper->getStreamContext();
        $stream       = @fopen($url, 'rb', false, $context);

        if (false === $stream) {
            throw new Exception('could not initialize the connection to load the data');
        }

        $timeout = $this->loader->getTimeout();

        stream_set_timeout($stream, $timeout);
        stream_set_blocking($stream, true);

        $meta    = stream_get_meta_data($stream);
        $headers = [];
        $code    = 200;

        if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
            $headers = $meta['wrapper_data'];

            foreach ($headers as $metaData) {
                if ('http/' === mb_substr(mb_strtolower($metaData), 0, 5)) {
                    $tmp_status_parts = explode(' ', $metaData, 3);
                    $code             = $tmp_status_parts[1];

                    break;
                }
            }
        }

        return new Response($code, $headers, new Stream($stream));
    }