No unnecessary downloads of covers if they already exist
This commit is contained in:
parent
23f703d5a5
commit
4772ae0756
@ -100,10 +100,8 @@ public class MangaDex : Connector
|
|||||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||||
string? coverCacheName = null;
|
string? coverCacheName = null;
|
||||||
if (coverUrl is not null)
|
if (coverUrl is not null)
|
||||||
{
|
coverCacheName = SaveImage(coverUrl);
|
||||||
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(coverUrl, (byte)RequestType.AtHomeServer);
|
|
||||||
coverCacheName = SaveImage(coverUrl, coverResult.result);
|
|
||||||
}
|
|
||||||
string? author = GetAuthor(authorId);
|
string? author = GetAuthor(authorId);
|
||||||
|
|
||||||
Dictionary<string, string> linksDict = new();
|
Dictionary<string, string> linksDict = new();
|
||||||
@ -300,13 +298,18 @@ public class MangaDex : Connector
|
|||||||
DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer);
|
DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string SaveImage(string url, Stream imageData)
|
private string SaveImage(string url)
|
||||||
{
|
{
|
||||||
string[] split = url.Split('/');
|
string[] split = url.Split('/');
|
||||||
string filename = split[^1];
|
string filename = split[^1];
|
||||||
string saveImagePath = Path.Join(imageCachePath, filename);
|
string saveImagePath = Path.Join(imageCachePath, filename);
|
||||||
|
|
||||||
|
if (File.Exists(saveImagePath))
|
||||||
|
return saveImagePath;
|
||||||
|
|
||||||
|
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(url, (byte)RequestType.AtHomeServer);
|
||||||
using MemoryStream ms = new();
|
using MemoryStream ms = new();
|
||||||
imageData.CopyTo(ms);
|
coverResult.result.CopyTo(ms);
|
||||||
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user