Skip to content

Commit

Permalink
Added page log dump in case web image search fails
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefNemec committed Aug 12, 2024
1 parent 4efc2fb commit 5e5786f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions source/Playnite/GoogleImageDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class GoogleImage

public class GoogleImageDownloader : IDisposable
{
private static ILogger logger = LogManager.GetLogger();

private readonly OffscreenWebView webView;
public GoogleImageDownloader()
{
Expand Down Expand Up @@ -89,8 +91,8 @@ public async Task<List<GoogleImage>> 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<List<List<object>>>($"[{match.Value}]");
Expand All @@ -104,6 +106,12 @@ public async Task<List<GoogleImage>> GetImages(string searchTerm, SafeSearchSett
}
}

if (!images.HasItems())
{
logger.Error("Failed to parse any Google image results.");
logger.Debug(googleContent);
}

return images;
}
}
Expand Down

0 comments on commit 5e5786f

Please sign in to comment.