Use the YouTube Data API to get video thumbnail from video URL
This plugin requires Craft CMS 3.0.0 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require sampsonpete/craft-yt-thumbs
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft YT Thumbs.
This plugin uses the YouTube Data API to get video thumbnails from YouTube videos. Other plugins that get videos from YouTube don’t use the Data API and so YouTube rejects the unauthenticated thumbnail calls when over a certain limit. Using this plugin gets around this limit.
Add your YouTube Data API developer key to the plugin settings screen.
Pass a YouTube URL to the getYtThumbnail
variable and a thumbnail image URL will be returned.
Example:
{% set thumb = craft.videoEmbedder.getYtThumbnail('https://www.youtube.com/watch?v=HtRGeyznv7k') %}
{% if thumb | length %}
{{ thumb }}
{% endif %}
Output:
https://i.ytimg.com/vi/HtRGeyznv7k/hqdefault.jpg
Brought to you by Pete Sampson