Jump to content

Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)


ryan

Recommended Posts

There's a list of valid urls on Vimeo's oEmbed docs page that seems to match the ones mentioned in the issue. It doesn't mention video ids now being hexadecimal, however.

vimeo.com/{video_id}
vimeo.com/album/{album_id}/video/{video_id}
vimeo.com/channels/{channel_id}/{video_id}
vimeo.com/groups/{group_id}/videos/{video_id}
vimeo.com/ondemand/{ondemand_id}/{video_id}

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@netcarver, this information about unlisted videos may be relevant: https://help.vimeo.com/hc/en-us/articles/12426199699985-Overview-of-video-privacy-settings

Quote

When you change your video's privacy settings to Unlisted, an extra set of numbers - what we call the privacy hash - will be added at the end of your video's URL, and must be included for embeds and sharing to work. 

So for a video with a URL like https://vimeo.com/553329597/04c306a466 the src for the iframe embed will need to include h=04c306a466 in the query string.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 10 months later...

I know I used this module a while back but moved on and used custom HannaCodes for video embeds for several reasons.

Maybe this could be your way as well - combined with HannaCodeDialog to insert the code into your textarea fields.

  • Like 1
Link to comment
Share on other sites

I've created a fork of the previous version a while ago that adds support for aspect ratios. Been working great for years, and haven't seen a need to update to the newer version. Here's the fork and the git diff in case you're still on v1. The newer v2 seems to be a complete rewrite, so...

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

5 hours ago, Ivan Gretsky said:

Can you share the hannacode?

$out = '';
$out .= <<<EOT
<div class="player youtube">
    <iframe 
        src="" 
        data-src="https://www.youtube-nocookie.com/embed/$video"
        data-category="external_media"
        data-ask-consent="1" 
        frameborder="0"
        scrolling="no"
        width="640"
        height="480"
        allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="link youtube">
    <a href="https://www.youtube.com/watch?v=$video" rel="nofollow" target="_blank">Watch on YouTube.com</a>
</div>
EOT;


echo $out;

This already has PrivacyWire attributes to make it work with it.

Here is the HannaCode export:

!HannaCode:youtube:eyJuYW1lIjoieW91dHViZSIsInR5cGUiOiI2IiwiY29kZSI6IlwvKmhjX2F0dHJcbnZpZGVvPVwiSHNEamxrZGpMZHdcIlxuaGNfYXR0cipcL1xuJG91dCA9ICcnO1xuJG91dCAuPSA8PDxFT1RcbjxkaXYgY2xhc3M9XCJwbGF5ZXIgeW91dHViZVwiPlxuICAgIDxpZnJhbWUgXG4gICAgICAgIHNyYz1cIlwiIFxuICAgICAgICBkYXRhLXNyYz1cImh0dHBzOlwvXC93d3cueW91dHViZS1ub2Nvb2tpZS5jb21cL2VtYmVkXC8kdmlkZW9cIlxuICAgICAgICBkYXRhLWNhdGVnb3J5PVwiZXh0ZXJuYWxfbWVkaWFcIlxuICAgICAgICBkYXRhLWFzay1jb25zZW50PVwiMVwiIFxuICAgICAgICBmcmFtZWJvcmRlcj1cIjBcIlxuICAgICAgICBzY3JvbGxpbmc9XCJub1wiXG4gICAgICAgIHdpZHRoPVwiNjQwXCJcbiAgICAgICAgaGVpZ2h0PVwiNDgwXCJcbiAgICAgICAgYWxsb3c9XCJhY2NlbGVyb21ldGVyOyBhdXRvcGxheTsgY2xpcGJvYXJkLXdyaXRlOyBlbmNyeXB0ZWQtbWVkaWE7IGd5cm9zY29wZTsgcGljdHVyZS1pbi1waWN0dXJlXCIgYWxsb3dmdWxsc2NyZWVuPjxcL2lmcmFtZT5cbjxcL2Rpdj5cbjxkaXYgY2xhc3M9XCJsaW5rIHlvdXR1YmVcIj5cbiAgICA8YSBocmVmPVwiaHR0cHM6XC9cL3d3dy55b3V0dWJlLmNvbVwvd2F0Y2g/dj0kdmlkZW9cIiByZWw9XCJub2ZvbGxvd1wiIHRhcmdldD1cIl9ibGFua1wiPkRpcmVrdCBiZWkgWW91VHViZSBhbnNjaGF1ZW48XC9hPlxuPFwvZGl2PlxuRU9UO1xuXG5cbmVjaG8gJG91dDsifQ==/!HannaCode

 

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

Adding the native lazy load loading='lazy' on the 381 line of TextformatterVideoEmbed.module doesn't seem to lazy load the iframe. I can see the attribute on the page's code that is injected but all the YouTube scripts are loading on the initial page load even through the embed video is about 2000+ pixels from top. What am I missing???

EDIT: All the Chromium browsers have a very large threshold. On Mozilla the threshold is much lower and the iframe gets loaded when you're getting close to it at about 500px.

Link to comment
Share on other sites

@ryan will you consider to add an option to populate the loading="lazy" attribute to iframe tags?

Although with a simple hook like below we can get the job done but it would be great if we can have it available on the module.

$wire->addHookAfter('Page::render', function(HookEvent $event) {

    if ($this->wire('page')->template->name != "my-content") return;
    $event->return = str_replace("<iframe ", "<iframe loading='lazy' ", $event->return);

});

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...