Skip to content

Commit

Permalink
youtube: detect age-restrictions for YouTube shorts as well
Browse files Browse the repository at this point in the history
  • Loading branch information
iparamonau committed Nov 4, 2024
1 parent c6bd724 commit 4d63698
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
3 changes: 1 addition & 2 deletions config.local.js.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ 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,
fix_shorts_in_eu: true // Avoid consent redirect for EU servers
get_params: "?rel=0&showinfo=1", // https://developers.google.com/youtube/player_parameters
},
vimeo: {
get_params: "?byline=0&badge=0" // https://developer.vimeo.com/player/embedding
Expand Down
24 changes: 7 additions & 17 deletions plugins/domains/youtube.com/youtube.shorts.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
/**
* 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
* This was an alternative fix for https://github.com/itteco/iframely/issues/543.
* YT Shorts are now covered by main plugin to detect age-restricted players that do not work.
* Here, we only need a bigger og-image
*/

export default {

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

mixins: [
"domain-icon",
"oembed-title",
"oembed-site",
"oembed-author",
"oembed-thumbnail",
"oembed-video", // "allow" attributes will be merged from there
"oembed-iframe"
"og-image",
"oembed-thumbnail" // smaller image is backup for EU where they may get a redirect to consent page
],

getLink: function(iframe) {
return {
href: iframe.src,
type: CONFIG.T.text_html,
rel: CONFIG.R.player,
"aspect-ratio": 9/16,
}
getData: function(options) {
options.followHTTPRedirect = true;
}
};
8 changes: 5 additions & 3 deletions plugins/domains/youtube.com/youtube.video.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default {
/^https?:\/\/www\.youtube\.com\/live\/([a-zA-Z0-9_-]+)/i,
/^https?:\/\/www\.youtube\.com\/v\/([a-zA-Z0-9_-]+)/i,
/^https?:\/\/www\.youtube\.com\/user\/[a-zA-Z0-9_-]+\/?\?v=([a-zA-Z0-9_-]+)/i,
/^https?:\/\/www\.youtube-nocookie\.com\/(?:v|embed)\/([a-zA-Z0-9_-]+)/i
/^https?:\/\/www\.youtube-nocookie\.com\/(?:v|embed)\/([a-zA-Z0-9_-]+)/i,
/^https?:\/\/www\.youtube\.com\/shorts\/([a-zA-Z0-9_-]+)/i
],

mixins: ["domain-icon"],
Expand Down Expand Up @@ -104,7 +105,8 @@ export default {
embeddable: entry.status ? entry.status.embeddable : true,
uploadStatus: entry.status?.uploadStatus,
status: entry.status,
ytRating: entry.contentDetails?.contentRating?.ytRating
ytRating: entry.contentDetails?.contentRating?.ytRating,
isShort: /\/shorts\//i.test(urlMatch[0])
};

if (entry.snippet?.thumbnails) {
Expand Down Expand Up @@ -266,7 +268,7 @@ export default {
// End of widescreen & allow check

var links = [];
var aspect = widescreen ? 16 / 9 : 4 / 3;
var aspect = youtube_video_gdata.isShort ? 9 / 16 : (widescreen ? 16 / 9 : 4 / 3);

if (youtube_video_gdata.embeddable && youtube_video_gdata.ytRating !== 'ytAgeRestricted') {

Expand Down

0 comments on commit 4d63698

Please sign in to comment.