Skip to content

Commit

Permalink
youtube: an option to fix EU redirects for YT shorts via a feature flag
Browse files Browse the repository at this point in the history
Please configure  `fix_shorts_in_eu: true` - see example config file.

cc #543
  • Loading branch information
iparamonau committed Jun 24, 2024
1 parent d13e3a0 commit 17c8cdb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config.local.js.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ export default {
youtube: {
// api_key: "INSERT YOUR VALUE",
// parts: [ "snippet", "player" ], // list of fields you want to use in the request, in most cases you only need those two
get_params: "?rel=0&showinfo=1" // https://developers.google.com/youtube/player_parameters
get_params: "?rel=0&showinfo=1" // https://developers.google.com/youtube/player_parameters,
fix_shorts_in_eu: true // Avoid consent redirect for EU servers
},
vimeo: {
get_params: "?byline=0&badge=0" // https://developer.vimeo.com/player/embedding
Expand Down
7 changes: 7 additions & 0 deletions lib/plugins/system/oembed/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
"url": "https://www.youtube.com/watch?v={1}",
"endpoint": "https://www.youtube.com/oembed?format={format}&url={url}"
},
{
"name": "YouTube Shorts",
"templates": [
"www\\.youtube\\.com/shorts/([a-zA-Z0-9_-]+)"
],
"endpoint": "https://www.youtube.com/oembed"
},
{
"name": "YouTube Playlist",
"templates": [
Expand Down
34 changes: 34 additions & 0 deletions plugins/domains/youtube.com/youtube.shorts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* This is an alternative fix for https://github.com/itteco/iframely/issues/543.
* If your servers are in EU, this avoids a redirect to cookie consents,
* Activate it by addong
*/

export default {

re: /^https?:\/\/www\.youtube\.com\/shorts\/([a-zA-Z0-9_-]+)/i,

// The issue with EU consent redirect needs to be bypassed
// by avoiding htmlparser-dependent plugins and mixins.

notPlugin: !CONFIG.providerOptions?.youtube?.fix_shorts_in_eu,

mixins: [
"domain-icon",
"oembed-title",
"oembed-site",
"oembed-author",
"oembed-thumbnail",
"oembed-video", // "allow" attributes will be merged from there
"oembed-iframe"
],

getLink: function(iframe) {
return {
href: iframe.src,
type: CONFIG.T.text_html,
rel: CONFIG.R.player,
"aspect-ratio": 9/16,
}
}
};

0 comments on commit 17c8cdb

Please sign in to comment.