wrav / oembed
A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
Installs: 183 253
Dependents: 3
Suggesters: 0
Security: 0
Stars: 36
Watchers: 3
Forks: 37
Open Issues: 10
Type:craft-plugin
Requires
- ext-dom: *
- craftcms/cms: ^4.0 | ^5.0
- embed/embed: ^v4.4
Requires (Dev)
- roave/security-advisories: dev-latest
- dev-master
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- v2.x-dev
- 2.3.2
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- v1.x-dev
- 1.13.19
- 1.3.18
- 1.3.17
- 1.3.15
- 1.3.13
- 1.3.12
- 1.3.11
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.0
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feature/unit-tests
- dev-v3-php74-support
- dev-feature/fallback-support
- dev-hotfix/vimeo-craft-v3
- dev-feature/craft-cloud-support
- dev-feature/gql-params
- dev-feature/embed-v4
- dev-feature/caching-issue
- dev-bugfix/issue-113
- dev-feature/craft-v4
- dev-embed4
- dev-alpha
- dev-feature/gdpr
- dev-release/1.3.0
- dev-feature/php7
- dev-feature/table-preview
- dev-feature/query-param-override
- dev-release/1.2.1
- dev-release/1.2.0
- dev-feature/cp-trigger
- dev-feature/autoplay
- dev-feature/recursive-bug
- dev-feature/updated-embed-engine
- dev-hotfix/libsyn
- dev-feature/craft-v3.1
This package is auto-updated.
Last update: 2024-12-10 03:57:42 UTC
README
A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
If use are looking for CraftCMS 2.5 support use previous project version 1.0.4, which is the latest release for CraftCMS 2.5.
Versions
Quick FYI on URL issues
Many websites, such as Vimeo, are restricting access to standard URLs (e.g. www.vimeo.com) and sometimes require using the embed URL (e.g., player.vimeo.com) to retrieve oEmbed data.
You can typically find the embed URL through the "share" options on video and oEmbed-supported sites. While the plugin provides general rich content as a fallback, its true potential comes from utilizing the oEmbed protocol and the associated metadata from the content provider.
If you're experiencing issues, check whether the provider or page offers an embed version, and use that URL to ensure you're accessing the most accurate data.
Installing
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 wrav/oembed
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for oEmbed.
Using oEmbed
To use simply call one of the following methods on your field type
{{ entry.field.valid }} # Get the embed object
{{ entry.field.render }} # Renders HTML
{{ entry.field.embed }} # Get the embed object
{{ entry.field.media }} # Get the embed object
We also provide option to use as a Twig variable
{{ craft.oembed.valid(url, options, cacheFields) }}
{{ craft.oembed.render(url, options, cacheFields) }}
{% set embed = craft.oembed.embed(url, options, cacheFields) %}
{% set media = craft.oembed.media(url, options, cacheFields) %}
Updating the embed URL, such as autoplay, rel, mute paramaters. This allows for you to support features the provider might not yet support
{{
entry.oembed_field.render({
params: {
autoplay: 1,
rel: 0,
mute: 0,
loop: 1,
autopause: 1,
},
attributes: {
title: 'Main title',
'data-title': 'Some other title',
}
})
}}
We still support hte old legacy method, however this might be deprecated in future versions.
{{
entry.oembed_field.render({
autoplay: 1,
rel: 0,
mute: 0,
loop: 1,
autopause: 1,
})
}}
Updating the width & height attributes on the iframe can be done using the following method, however is CSS is still recommended view for sizing your iframe.
{{
entry.oembed_field.render({
width: 640,
height: 480,
})
}}
or
{{
entry.oembed_field.render({
attributes: {
width: 640,
height: 480,
}
})
}}
You can access additional media details using the examples below, these are the default keys.
entry.field.media.title
entry.field.media.description
entry.field.media.url
entry.field.media.type
entry.field.media.tags
entry.field.media.images
entry.field.media.image
entry.field.media.imageWidth
entry.field.media.imageHeight
entry.field.media.code
entry.field.media.width
entry.field.media.height
entry.field.media.aspectRatio
entry.field.media.authorName
entry.field.media.authorUrl
entry.field.media.providerName
entry.field.media.providerUrl
entry.field.media.providerIcons
entry.field.media.providerIcon
entry.field.media.publishedDate
entry.field.media.license
entry.field.media.linkedData
entry.field.media.feeds
You can access additional media details from the data array. These will be snake_case so be aware.
{{ dump(entry.field.media.data) }}
Additional Embed information can be found here
Cache
By default, the plugin will cache the following keys on the oembed object. The plugin can cache additional missing fields using the cache prop parameter which will take an array of strings.
{{ entry.oembed_field.render( { width: 640, height: 480, }, [ 'cacheable_key' ] ) }}
Default Keys
- title
- description
- url
- type
- tags
- images
- image
- imageWidth
- imageHeight
- code
- width
- height
- aspectRatio
- authorName
- authorUrl
- providerName
- providerUrl
- providerIcons
- providerIcon
- publishedDate
- license
- linkedData
- feeds
GraphQL
I recommend enabling caching in the plugin settings menu to speed up the API resolve timing.
Below is an example of a Oembed field called "foobar" add accessing properties from the embed object.
{
entries {
id,
... on page_page_Entry {
foobar {
code,
providerUrl,
aspectRatio
}
}
}
}
Credits
Original built while working at HutSix I've since been granted permission to continue development here.
Change Log
Changes can be viewed here
Support
Get in touch via email, Discord, or by creating a Github issue