itteco / iframely

oEmbed proxy. Supports over 1800 domains via custom parsers, oEmbed, Twitter Cards and Open Graph
https://iframely.com
Other
1.5k stars 292 forks source link

YouTube Shorts / GDPR consent #543

Closed TheDelta closed 2 months ago

TheDelta commented 2 months ago

In https://github.com/itteco/iframely/issues/326 the consent issue was described for YouTube (and Google Maps). and the fix is to fetch it over the API (requires token) or to use a custom plugin.

The latest version of iframely doesn't handle unfortunately YouTube shorts url. My fix is to simply add the shorts url to the regex as well:

custom_plugins/domains/youtube.video.js

import * as plugin from './../../plugins/domains/youtube.com/youtube.video.js';

const fixedPlugin = { ...plugin.default };

fixedPlugin.re = [
    ...fixedPlugin.re,
    // add missing shorts support:
    /^https?:\/\/(?:www\.)?youtube\.com\/shorts\/([\w-]+)/i,
];

export default fixedPlugin;

but this will embed the short as a youtube video.

The other way to make it work (and display as embedded short) would be to set the cookie consent with the request. Based on: https://stackoverflow.com/a/74132453/5152479

a new custom plugin custom_plugins/domains/youtube.short.js

// https://stackoverflow.com/a/74132453/5152479
const CONSENT_ACCEPT = 'CAISNQgDEitib3FfaWRlbnRpdHlmcm9udGVuZHVpc2VydmVyXzIwMjMwODI5LjA3X3AxGgJlbiACGgYIgLC_pwY';
const CONSENT_REJECT = 'CAESEwgDEgk0ODE3Nzk3MjQaAmVuIAEaBgiA_LyaBg';

export default {
    re: /^https?:\/\/(?:www\.)?youtube\.com\/shorts\/([\w-]+)/i,
    getData: function(options) {
        options.jar = { SOCS: CONSENT_REJECT };
    },
};

This will make the request with accepted consent and does the fetch like with an US based server and proper short embed. But once youtube changes the format, this will most likely break.

Would be great to have some discussion and maybe a better solutions by the developers.

iparamonau commented 2 months ago

Please see the suggested fix and activate it via fix_shorts_in_eu: true flag in your config file for YouTube.

YouTube video player and YouTube player for shorts is the same thing. It seems they style they differently via CSS based on the aspect-ratio.