class YouTube in Video 8
Same name and namespace in other branches
- 8.2 src/Plugin/video/Provider/YouTube.php \Drupal\video\Plugin\video\Provider\YouTube
Plugin annotation
@VideoEmbeddableProvider(
id = "youtube",
label = @Translation("YouTube"),
description = @Translation("YouTube Video Provider"),
regular_expressions = {
"@(?:(?<protocol>http|https):)?//(?:www\.)?youtube(?<cookie>-nocookie)?\.com/embed/(?<id>[a-z0-9_-]+)@i",
"@(?:(?<protocol>http|https):)?//(?:www\.)?youtube(?<cookie>-nocookie)?\.com/v/(?<id>[a-z0-9_-]+)@i",
"@(?:(?<protocol>http|https):)?//(?:www\.)?youtube(?<cookie>-nocookie)?\.com/watch(\?|\?.*\&)v=(?<id>[a-z0-9_-]+)@i",
"@(?:(?<protocol>http|https):)?//youtu(?<cookie>-nocookie)?\.be/(?<id>[a-z0-9_-]+)@i"
},
mimetype = "video/youtube",
stream_wrapper = "youtube"
)
Hierarchy
- class \Drupal\video\ProviderPluginBase implements ContainerFactoryPluginInterface, ProviderPluginInterface
- class \Drupal\video\Plugin\video\Provider\YouTube
Expanded class hierarchy of YouTube
1 string reference to 'YouTube'
- YoutubeStream::getName in src/
StreamWrapper/ YoutubeStream.php - Returns the name of the stream wrapper for use in the UI.
File
- src/
Plugin/ video/ Provider/ YouTube.php, line 23
Namespace
Drupal\video\Plugin\video\ProviderView source
class YouTube extends ProviderPluginBase {
/**
* {@inheritdoc}
*/
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),
],
];
}
/**
* {@inheritdoc}
*/
public function getRemoteThumbnailUrl() {
$data = $this
->getVideoMetadata();
$url = '';
// Sometimes the video has not every version of thumbnails. Guzzle throws
// exception at that time. Now catch it, and try download another size of
// thumbnail.
$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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProviderPluginBase:: |
protected | property | File object to handle | |
ProviderPluginBase:: |
protected | property | An http client. | |
ProviderPluginBase:: |
protected | property | Additional metadata for the embedded video object | |
ProviderPluginBase:: |
protected | property | Additional settings for the video widget | |
ProviderPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ProviderPluginBase:: |
protected | function | Download the remote thumbnail to the local file system. | |
ProviderPluginBase:: |
public | function | Get the URL to the local thumbnail. | |
ProviderPluginBase:: |
protected | function | Determines the URI for a video field. | |
ProviderPluginBase:: |
protected | function | Get the ID of the video. | |
ProviderPluginBase:: |
protected | function | Get the input which caused this plugin to be selected. | |
ProviderPluginBase:: |
protected | function | Get the input which caused this plugin to be selected. | |
ProviderPluginBase:: |
public | function | ||
ProviderPluginBase:: |
public | function | Create a plugin with the given input. | |
YouTube:: |
public | function |
Get the URL of the remote thumbnail. Overrides ProviderPluginInterface:: |
|
YouTube:: |
public | function |
Render embed code. Overrides ProviderPluginInterface:: |