From 17c8cdb7c5fe5556b62bfc35e8177f89cff4a96c Mon Sep 17 00:00:00 2001 From: Ivan Paramonau Date: Mon, 24 Jun 2024 16:59:24 -0400 Subject: [PATCH 1/2] youtube: an option to fix EU redirects for YT shorts via a feature flag Please configure `fix_shorts_in_eu: true` - see example config file. cc #543 --- config.local.js.SAMPLE | 3 +- lib/plugins/system/oembed/providers.json | 7 ++++ plugins/domains/youtube.com/youtube.shorts.js | 34 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 plugins/domains/youtube.com/youtube.shorts.js diff --git a/config.local.js.SAMPLE b/config.local.js.SAMPLE index 5c78c4f8f..4d2d7761f 100644 --- a/config.local.js.SAMPLE +++ b/config.local.js.SAMPLE @@ -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 diff --git a/lib/plugins/system/oembed/providers.json b/lib/plugins/system/oembed/providers.json index 5387e0062..6db37fae9 100644 --- a/lib/plugins/system/oembed/providers.json +++ b/lib/plugins/system/oembed/providers.json @@ -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": [ diff --git a/plugins/domains/youtube.com/youtube.shorts.js b/plugins/domains/youtube.com/youtube.shorts.js new file mode 100644 index 000000000..d8dd581d5 --- /dev/null +++ b/plugins/domains/youtube.com/youtube.shorts.js @@ -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, + } + } +}; \ No newline at end of file From c03633871525976f68df4da13e8aca7cd8600055 Mon Sep 17 00:00:00 2001 From: Nazar Leush <39333+nleush@users.noreply.github.com> Date: Tue, 2 Jul 2024 22:44:32 +0300 Subject: [PATCH 2/2] Feature: retry econnreset (#544) * fetch: retry on ECONNRESET * retry on errors list * update algorythm * bugfix * bugfix undefined * CONFIG.ERRORS_TO_RETRY * allow ERRORS_TO_RETRY == null --- config.js | 10 +++++++++- lib/fetch.js | 35 +++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/config.js b/config.js index 0beaa8ac8..b6c8b5313 100644 --- a/config.js +++ b/config.js @@ -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. diff --git a/lib/fetch.js b/lib/fetch.js index 8da22a8df..67a362318 100644 --- a/lib/fetch.js +++ b/lib/fetch.js @@ -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); } }); });