You are here

public function YouTube::getRemoteThumbnailUrl in Video Embed Field 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/video_embed_field/Provider/YouTube.php \Drupal\video_embed_field\Plugin\video_embed_field\Provider\YouTube::getRemoteThumbnailUrl()

Get the URL of the remote thumbnail.

This is used to download the remote thumbnail and place it on the local file system so that it can be rendered with image styles. This is only called if no existing file is found for the thumbnail and should not be called unnecessarily, as it might query APIs for video thumbnail information.

Return value

string The URL to the remote thumbnail file.

Overrides ProviderPluginInterface::getRemoteThumbnailUrl

File

src/Plugin/video_embed_field/Provider/YouTube.php, line 73

Class

YouTube
A YouTube provider plugin.

Namespace

Drupal\video_embed_field\Plugin\video_embed_field\Provider

Code

public function getRemoteThumbnailUrl() {
  $url = 'http://img.youtube.com/vi/%s/%s.jpg';
  $high_resolution = sprintf($url, $this
    ->getVideoId(), 'maxresdefault');
  $backup = sprintf($url, $this
    ->getVideoId(), 'mqdefault');
  try {
    $this->httpClient
      ->head($high_resolution);
    return $high_resolution;
  } catch (\Exception $e) {
    return $backup;
  }
}