Skip to content

Latest commit

 

History

7 提交

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

仓库 files navigation

Video URL Parser

Easily extract information about a video from its URL.

This Drupal 8 module detects the hosting service from a video's URL and is able to retrieve the video's ID, thumbnail and embed URL to use in an iframe.

Using this gist as a starting point, this module currently supports YouTube and Vimeo URLs. It also registers a Twig extension to easily get video information from within a Twig template.

Usage

From a PHP file (Controller/Form/etc...):

// Use the parser class
use Drupal\video_url_parser\VideoUrlParser;

$vid_parser = new VideoUrlParser();
$my_video = $vid_parser->parse(VIDEO_URL); // Pass in the video URL

From a Twig template:

{% set url = VIDEO_URL %} // Pass in the video URL
{% set vid = url|video_url %} // Use the video_url filter to invoke the parser

On success, the parser will return an array containing the information extracted:

$vid = [
  'type' => "youtube",
  'thumb' => "http://img.youtube.com/vi/w3jLJU7DT5E/mqdefault.jpg",
  'embed' => "http://youtube.com/embed/w3jLJU7DT5E?autoplay=1"
];

关于

Drupal 8 project to easily retrieve information about a video by its URL.

Topics

Resources

Stars

0 stars

关注者

0 watching

复刻s

发布

贡献者

Languages