Youku.php in Video Embed Youku 8
File
src/Plugin/video_embed_field/Provider/Youku.php
View source
<?php
namespace Drupal\video_embed_youku\Plugin\video_embed_field\Provider;
use Drupal\video_embed_field\ProviderPluginBase;
class Youku extends ProviderPluginBase {
public function renderEmbedCode($width, $height, $autoplay) {
return [
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'width' => $width,
'height' => $height,
'frameborder' => '0',
'allowfullscreen' => 'allowfullscreen',
'src' => sprintf('https://player.youku.com/embed/%s?autoplay=%d', $this
->getVideoId(), $autoplay),
],
];
}
protected function oEmbedData() {
return json_decode(file_get_contents(sprintf('https://api.youku.com/videos/show.json?client_id=8d025b9c897b22a8&video_id=%s', $this
->getVideoId())));
}
public function getRemoteThumbnailUrl() {
return $this
->oEmbedData()->bigThumbnail;
}
public function getName() {
return $this
->oEmbedData()->title;
}
public function getDescription() {
return $this
->oEmbedData()->description;
}
public static function getIdFromInput($input) {
$id = FALSE;
$parsed = parse_url($input);
$path = $parsed['path'];
$parts = explode('/', $path);
foreach ($parts as $part) {
if (strstr($part, 'id_')) {
$id = str_replace('id_', '', $part);
$id = str_replace('.html', '', $id);
return $id;
}
}
}
}
Classes
Name |
Description |
|
Youku |
Plugin annotation
@VideoEmbedProvider(
id = "youku",
title = @Translation("Youku")
) |