Skip to content

Commit

Permalink
Download .pngs instead of .pnjs (#252)
Browse files Browse the repository at this point in the history
* Download the png version when available
* Works with searches now
  • Loading branch information
Khodyn authored Jun 25, 2022
1 parent 3ab44a1 commit a1aeee8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ private static ImageResponse DeserializeImageResponse(string s)

protected string RetrieveOriginalImageUrl(string url, int width, int height, bool isInline)
{
if (url.EndsWith(".pnj")) url = url.Substring(0, url.Length - 4) + ".png";
if (width > height) { (width, height) = (height, width); }
if (ShellService.Settings.ImageSize != "best"
|| !isInline && !url.Contains("/s1280x1920/")
Expand All @@ -397,6 +398,7 @@ protected string RetrieveOriginalImageUrl(string url, int width, int height, boo
{
url = url.Replace("/s1280x1920/", (width <= 2048 && height <= 3072) ? "/s2048x3072/" : "/s99999x99999/");
}

string pageContent = "";
int errCnt = 0;
Exception lastError = null;
Expand Down Expand Up @@ -442,7 +444,11 @@ protected string RetrieveOriginalImageUrl(string url, int width, int height, boo
ImageResponse imgRsp = DeserializeImageResponse(extracted);
int maxWidth = imgRsp.Images.Max(x => x.Width);
Image img = imgRsp.Images.FirstOrDefault(x => x.Width == maxWidth);
return string.IsNullOrEmpty(img?.MediaKey) ? url : img.Url;

if (string.IsNullOrEmpty(img?.MediaKey))
return url;

return img.Url.EndsWith(".pnj") ? img.Url.Substring(0, img.Url.Length - 4) + ".png" : img.Url;
}
catch (Exception ex)
{
Expand Down

0 comments on commit a1aeee8

Please sign in to comment.