From 5e5786f6c862fa5eabc0944a574278e4fdb65039 Mon Sep 17 00:00:00 2001 From: Josef Nemec Date: Mon, 12 Aug 2024 13:39:57 +0200 Subject: [PATCH] Added page log dump in case web image search fails --- source/Playnite/GoogleImageDownloader.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/Playnite/GoogleImageDownloader.cs b/source/Playnite/GoogleImageDownloader.cs index 33b43430a..a6d43cb00 100644 --- a/source/Playnite/GoogleImageDownloader.cs +++ b/source/Playnite/GoogleImageDownloader.cs @@ -34,6 +34,8 @@ public class GoogleImage public class GoogleImageDownloader : IDisposable { + private static ILogger logger = LogManager.GetLogger(); + private readonly OffscreenWebView webView; public GoogleImageDownloader() { @@ -89,8 +91,8 @@ public async Task> GetImages(string searchTerm, SafeSearchSett } else { - googleContent = Regex.Replace(googleContent, @"\r\n?|\n", string.Empty); - var matches = Regex.Matches(googleContent, @"\[""(https:\/\/encrypted-[^,]+?)"",\d+,\d+\],\[""(http.+?)"",(\d+),(\d+)\]"); + var formatted = Regex.Replace(googleContent, @"\r\n?|\n", string.Empty); + var matches = Regex.Matches(formatted, @"\[""(https:\/\/encrypted-[^,]+?)"",\d+,\d+\],\[""(http.+?)"",(\d+),(\d+)\]"); foreach (Match match in matches) { var data = Serialization.FromJson>>($"[{match.Value}]"); @@ -104,6 +106,12 @@ public async Task> GetImages(string searchTerm, SafeSearchSett } } + if (!images.HasItems()) + { + logger.Error("Failed to parse any Google image results."); + logger.Debug(googleContent); + } + return images; } }