From a3543090f269ab7f824f4c631d44b84037dd37ac Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 15 Aug 2022 23:37:07 +0200 Subject: [PATCH] Translate plex query params to fixed --- seasoned_api/src/plex/plex.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/plex/plex.js b/seasoned_api/src/plex/plex.js index 9eb1b29..1568596 100644 --- a/seasoned_api/src/plex/plex.js +++ b/seasoned_api/src/plex/plex.js @@ -10,6 +10,12 @@ const redisCache = new RedisCache(); const sanitize = string => string.toLowerCase().replace(/[^\w]/gi, ""); +function fixedEncodeURIComponent(str) { + return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { + return "%" + c.charCodeAt(0).toString(16).toUpperCase(); + }); +} + const matchingTitleAndYear = (plex, tmdb) => { let matchingTitle, matchingYear; @@ -152,7 +158,7 @@ class Plex { ) return false; - const keyUriComponent = encodeURIComponent(matchingObjectInPlex.key); + const keyUriComponent = fixedEncodeURIComponent(matchingObjectInPlex.key); return `https://app.plex.tv/desktop#!/server/${machineIdentifier}/details?key=${keyUriComponent}`; }); } @@ -162,7 +168,7 @@ class Plex { const url = `http://${this.plexIP}:${ this.plexPort - }/hubs/search?query=${encodeURIComponent(query)}`; + }/hubs/search?query=${fixedEncodeURIComponent(query)}`; const options = { timeout: 20000, headers: { Accept: "application/json" }