Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Jul 2, 2024
2 parents 680397e + c036338 commit dd04de4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
10 changes: 9 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,15 @@
"twitter.status": {}
},

LOG_DATE_FORMAT: "\\[YY-MM-DD HH:mm:ss\\]:"
LOG_DATE_FORMAT: "\\[YY-MM-DD HH:mm:ss\\]:",

ERRORS_TO_RETRY: [
'ECONN',
'EAI_AGAIN',
'ENET',
'HPE_INVALID_',
'ERR_SSL_'
]
};

// Providers config loader.
Expand Down
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
35 changes: 21 additions & 14 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,31 @@ function doFetch(fetch_func, h1_fetch_func, options) {
.catch(error => {
clearTimeout(timeoutTimerId);
if (!options.disable_http2 && error.code && /^ERR_HTTP2/.test(error.code)) {

log(' -- doFetch http2 error', error.code, uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true})));

} else if (!options.disable_http2 && error.code && error instanceof FetchError && error.code === 'ABORT_ERR') {

// Special case, when shared session request aborted by htmlparser logic.
/**
* https://polldaddy.com/poll/7451882/?s=twitter
* https://app.everviz.com/show/O0Cy7Dyt
*/
log(' -- doFetch h2 aborted error', uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true})));

} else if (!options.stopRecursion && CONFIG.ERRORS_TO_RETRY?.some(code => error.code?.indexOf(code) > -1)) {

log(' -- doFetch ECONNRESET retry', error.code, uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {stopRecursion: true, disable_http2: true})));

} else {
if (!options.disable_http2 && error.code && error instanceof FetchError && error.code === 'ABORT_ERR') {
// Special case, when shared session request aborted by htmlparser logic.
/**
* https://polldaddy.com/poll/7451882/?s=twitter
* https://app.everviz.com/show/O0Cy7Dyt
*/
log(' -- doFetch h2 aborted error', uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true})));
} else {
if (error instanceof AbortError) {
// `AbortError` before `response` occurs only on timeout.
error = 'timeout';
}
reject(error);
if (error instanceof AbortError) {
// `AbortError` before `response` occurs only on timeout.
error = 'timeout';
}
reject(error);
}
});
});
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 dd04de4

Please sign in to comment.