diff --git a/.craftplugin b/.craftplugin index 70c1702..c31a66d 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1 +1 @@ -{"pluginName":"Video Embedder","pluginDescription":"Craft plugin to generate an embed URL from a YouTube or Vimeo URL.","pluginVersion":"1.0.8","pluginAuthorName":"Mike Stecker","pluginVendorName":"mikestecker","pluginAuthorUrl":"http://github.com/mikestecker","pluginAuthorGithub":"mikestecker","codeComments":"yes","pluginComponents":["variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} \ No newline at end of file +{"pluginName":"Video Embedder","pluginDescription":"Craft plugin to generate an embed URL from a YouTube or Vimeo URL.","pluginVersion":"1.0.9","pluginAuthorName":"Mike Stecker","pluginVendorName":"mikestecker","pluginAuthorUrl":"http://github.com/mikestecker","pluginAuthorGithub":"mikestecker","codeComments":"yes","pluginComponents":["variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 95a7e0f..683ff9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.0.9 - 2018-04-12 +### Added +- Added `getVideoId` variable +### Changed +- Code cleanup +- Updated functions to return an empty string if the URL returns null for any reason. (#5, #6) +- Craft 3.0.0 release is required, no longer supporting RC versions + ## 1.0.8 - 2018-03-07 ### Added - Added `getTitle` variable diff --git a/README.md b/README.md index 77f68e5..c41b0e8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Ported over from [Viget's](https://viget.com) [Video Embed plugin for Craft 2.x] ## Requirements -This plugin requires Craft CMS 3.0.0-RC1 or later. +This plugin requires Craft CMS 3.0.0 or later. ## Installation @@ -25,16 +25,24 @@ Video Embedder will take your YouTube or Vimeo URL's and convert the URL into an ## Using Video Embedder -Pass a YouTube or Vimeo URL to the `getEmbedUrl` variable and an embed URL will be returned. +Pass a YouTube or Vimeo URL to the `getEmbedUrl` variable and an embed URL will be returned. The plugin will check if the URL is valid and allows embedding. If it doesn't, it will return an empty string. ``` -{{ craft.videoEmbedder.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254') }} +{% set embed = craft.videoEmbedder.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254') %} + +{% if embed | length %} + {{ embed }} +{% endif %} ``` **Example:** ``` - +{% set embed = craft.videoEmbedder.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254') %} + +{% if embed | length %} + +{% endif %} ``` **Output:** @@ -50,7 +58,7 @@ ___ `getEmbedUrl` will now accept optional parameters to YouTube and Vimeo URL's such as `autoplay`, `rel`, etc: ``` -{{ craft.videoEmbedder.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254', {autoplay: 1, rel: 0, theme: 'dark'}) }} +{% set embed = craft.videoEmbedder.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254', {autoplay: 1, rel: 0, theme: 'dark'}) %} ``` ___ @@ -58,7 +66,11 @@ ___ Video Embedder will also pull the largest thumbnail URL from YouTube or Vimeo using the `getVideoThumbnail` variable. ``` -{{ craft.videoEmbedder.getVideoThumbnail('https://www.youtube.com/watch?v=6xWpo5Dn254') }} +{% set thumbnail = craft.videoEmbedder.getVideoThumbnail('https://www.youtube.com/watch?v=6xWpo5Dn254') %} + +{% if thumbnail | length %} + {{ thumbnail }} +{% endif %} ``` **Output:** @@ -75,16 +87,37 @@ Video Embedder will now generate the iframe code. Simple use the `embed` variabl Basic example: ``` -{{ craft.videoEmbedder.embed('https://www.youtube.com/watch?v=6xWpo5Dn254') }} +{% set embed = craft.videoEmbedder.embed('https://www.youtube.com/watch?v=6xWpo5Dn254') %} + +{% if embed | length %} + {{ embed }} +{% endif %} ``` With parameters: ``` -{{ craft.videoEmbedder.embed('https://www.youtube.com/watch?v=6xWpo5Dn254', {autoplay: 1, rel: 0, theme: 'dark'}) }} +{% set embed = craft.videoEmbedder.embed('https://www.youtube.com/watch?v=6xWpo5Dn254', {autoplay: 1, rel: 0, theme: 'dark'}) %} ``` These parameters will simply output at the end of the embed URL string and have only been tested with YouTube and Vimeo. Check with each provider for which parameters are supported. +___ + +***New in 1.0.9:*** + +Return only the Vimeo or YouTube ID from the URL. This is helpful in use cases such as using it with [Plyr](https://github.com/sampotts/plyr/) + +Basic example: +``` +{% set videoUrl = 'https://www.youtube.com/watch?v=6xWpo5Dn254' %} +{% set videoId = craft.videoEmbedder.getVideoId(videoUrl) %} +{% set providerName = craft.videoEmbedder.getProviderName(videoUrl) %} + +{% if videoId | length %} +
+{% endif %} +``` + ## Video Embedder Roadmap diff --git a/composer.json b/composer.json index 0d81790..edb0488 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mikestecker/craft-videoembedder", "description": "Craft plugin to generate an embed URL from a YouTube or Vimeo URL.", "type": "craft-plugin", - "version": "1.0.8", + "version": "1.0.9", "keywords": [ "craft", "cms", @@ -22,7 +22,7 @@ } ], "require": { - "craftcms/cms": "^3.0.0-RC1", + "craftcms/cms": "^3.0.0", "embed/embed": "^3.3" }, "repositories": [