YouTube.php in Video 8.2
File
src/Plugin/video/Provider/YouTube.php
View source
<?php
namespace Drupal\video\Plugin\video\Provider;
use Drupal\video\ProviderPluginBase;
use GuzzleHttp\Exception\ClientException;
class YouTube extends ProviderPluginBase {
public function renderEmbedCode($settings) {
$file = $this
->getVideoFile();
$data = $this
->getVideoMetadata();
return [
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'width' => $settings['width'],
'height' => $settings['height'],
'frameborder' => '0',
'allowfullscreen' => 'allowfullscreen',
'src' => sprintf('https://www.youtube.com/embed/%s?autoplay=%d&rel=%d&start=%d', $data['id'], $settings['autoplay'], $settings['related_videos'], NULL),
],
];
}
public function getRemoteThumbnailUrl() {
$data = $this
->getVideoMetadata();
$url = '';
$img_urls = [
'http://img.youtube.com/vi/' . $data['id'] . "/maxresdefault.jpg",
'http://img.youtube.com/vi/' . $data['id'] . "/hqdefault.jpg",
'http://img.youtube.com/vi/' . $data['id'] . "/default.jpg",
];
foreach ($img_urls as $url) {
try {
$this->httpClient
->request('GET', $url);
return $url;
} catch (ClientException $e) {
continue;
}
}
return FALSE;
}
}
Classes
Name |
Description |
YouTube |
Plugin annotation
@VideoEmbeddableProvider(
id = "youtube",
label = @Translation("YouTube"),
description = @Translation("YouTube Video Provider"),
regular_expressions = {
… |