Hi, I think this module is exactly what I need, but I just cannot get it to work in the way I expect.

I have a site with oembed using https://youtu.be/ style links, but would like to switch the domain sitewide for https://www.youtube-nocookie.com/

I had originally thought I could just alter the output somewhere, but all the validation gets in the way. Therefore I found this module and wanted to use it to create a new oembed provider for this nocookie domain, but I just cannot seem to get it to work.

Has anyone done anything for youtube-nocookie already that could help me through the steps? In my module I have the below code within the hook, and it appears in the "bucket" page, but how do I make it an option on the field settings page?

$providers[] = [
    'provider_name' => 'YouTube NoCookie',
    'provider_url' => 'https://www.youtube-nocookie.com/',
    'endpoints' => [
      [
        'schemes' => [
          'https://www.youtube-nocookie.com/*'
        ],
        'url' => 'https://www.youtube-nocookie.com/oembed',
        'discovery' => 'true',
      ],
    ],
  ];

Also, I did some hacking to just see if this would work in theory, and it kept telling me this wasn't valid oembed, now my issue above may help with that, but is there a way to confirm if this is a vali oembed path?

Thanks for your time and help,
Dan

Comments

retrodans created an issue. See original summary.

chris burge’s picture

The 'provider_name' in the provider definition must match the 'provider_name' from the resource response.

Here's an example oEmbed request to www.youtube-nocookie.com: https://www.youtube-nocookie.com/oembed?url=https://www.youtube.com/watch?v=7SqirKJ2AK0

Here's the response:

{
  "title": "Guardians of the Galaxy Awesome Mix Vol. 1 & Vol. 2 (Full Soundtrack) - Part 02",
  "author_name": "TC REMIX",
  "author_url": "https://www.youtube.com/user/doonatassett",
  "type": "video",
  "height": 113,
  "width": 200,
  "version": "1.0",
  "provider_name": "YouTube",
  "provider_url": "https://www.youtube.com/",
  "thumbnail_height": 360,
  "thumbnail_width": 480,
  "thumbnail_url": "https://i.ytimg.com/vi/7SqirKJ2AK0/hqdefault.jpg",
  "html": "<iframe width=\"200\" height=\"113\" src=\"https://www.youtube.com/embed/7SqirKJ2AK0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
}

The problem is that while YouTube responds to oEmbed requests to www.youtube-nocookie.com, it responds as if the request had been sent to www.youtube.com. You're not going to get an embed code with www.youtube-nocookie.com as the domain. It's just how Google has its oEmbed service designed. You could create a custom provider that includes http://www.youtube-nocookie.com/* and https://www.youtube-nocookie.com/* as schemes. That would at least allow your users to submit YouTube URLs from www.youtube-nocookie.com. Just know, the embed code returned will be for www.youtube.com and not for www.youtube-nocookie.com.

retrodans’s picture

Thanks for your help @chris-burge sadly we are after rendering youtube-nocookie on the site.

So it sounds like if we want to you youtube-nocookie to render the media, then we would have to switch things to use something other than oembed (at least for the time being).

My current idea would be to write a custom formatter than instead of using oEmbed, would just create the embed code (with some regex replaces for the domain). As it would only be on our site, we should be able to make a few assumptions to get this to work. Before I proceed, doe you feel this seems like a sane approach, or would you have other approaches worth me looking into?

Thanks again for your time,
Dan

chris burge’s picture

Either of those could work. Before oEmbed, I had written a custom module that provided a text filter (e.g. extended Drupal\filter\Plugin\FilterBase). It basically worked like a WP short code.

Take a look at #3043821: Better privacy for youtube videos, specifically comment #35.

chris burge’s picture

Status: Active » Closed (works as designed)