From 15f789d36632f8d82f03d667b489e2fb434245ea Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Tue, 10 May 2022 22:36:44 +0300 Subject: [PATCH] Workaround some backends sending invalid UTF8 content. --- src/Libs/Servers/JellyfinServer.php | 20 ++++++++++++++++---- src/Libs/Servers/PlexServer.php | 25 +++++++++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Libs/Servers/JellyfinServer.php b/src/Libs/Servers/JellyfinServer.php index 2f055a46..816e2ed4 100644 --- a/src/Libs/Servers/JellyfinServer.php +++ b/src/Libs/Servers/JellyfinServer.php @@ -160,7 +160,11 @@ class JellyfinServer implements ServerInterface return null; } - $json = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); $this->uuid = ag($json, 'Id', null); @@ -185,7 +189,11 @@ class JellyfinServer implements ServerInterface ); } - $json = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); $list = []; @@ -676,7 +684,7 @@ class JellyfinServer implements ServerInterface $json = json_decode( json: $response->getContent(), associative: true, - flags: JSON_THROW_ON_ERROR + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE ); $json = ag($json, 'Items', [])[0] ?? []; @@ -1617,7 +1625,11 @@ class JellyfinServer implements ServerInterface return []; } - $json = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); if (null === ($type = ag($json, 'Type'))) { return []; diff --git a/src/Libs/Servers/PlexServer.php b/src/Libs/Servers/PlexServer.php index c3e288d1..befc4204 100644 --- a/src/Libs/Servers/PlexServer.php +++ b/src/Libs/Servers/PlexServer.php @@ -168,7 +168,11 @@ class PlexServer implements ServerInterface return null; } - $json = json_decode($response->getContent(false), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(false), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); $this->uuid = ag($json, 'MediaContainer.machineIdentifier', null); @@ -200,7 +204,11 @@ class PlexServer implements ServerInterface ); } - $json = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); $list = []; @@ -1810,7 +1818,12 @@ class PlexServer implements ServerInterface return null; } - $json = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); + $tempToken = ag($json, 'authToken', null); $url = Container::getNew(UriInterface::class)->withPort(443)->withScheme('https')->withHost('plex.tv') @@ -1839,7 +1852,11 @@ class PlexServer implements ServerInterface ], ]); - $json = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR); + $json = json_decode( + json: $response->getContent(), + associative: true, + flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE + ); foreach ($json ?? [] as $server) { if (ag($server, 'clientIdentifier') !== $uuid) {