Bug fix #181 : if audible gives a null picture id then once that image is searched for, no further cover art was downloaded

This commit is contained in:
Robert McRackan 2022-01-12 22:20:58 -05:00
parent 6b649cf4ca
commit c296bff47f
3 changed files with 25 additions and 20 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>6.6.4.1</Version>
<Version>6.6.5.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -174,7 +174,9 @@ namespace DtoImporterService
var item = importItem.DtoItem;
// set/update book-specific info which may have changed
if (item.PictureId is not null)
book.PictureId = item.PictureId;
book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars);
// important to update user-specific info. this will have changed if user has rated/reviewed the book since last library import

View File

@ -73,16 +73,10 @@ namespace LibationFileManager
if (!cache.ContainsKey(def) || cache[def] == null)
{
var path = getPath(def);
byte[] bytes;
if (File.Exists(path))
bytes = File.ReadAllBytes(path);
else
{
bytes = downloadBytes(def);
saveFile(def, bytes);
}
var bytes
= File.Exists(path)
? File.ReadAllBytes(path)
: downloadBytes(def);
cache[def] = bytes;
}
return cache[def];
@ -104,7 +98,6 @@ namespace LibationFileManager
continue;
var bytes = downloadBytes(def);
saveFile(def, bytes);
lock (cacheLocker)
cache[def] = bytes;
@ -115,14 +108,24 @@ namespace LibationFileManager
private static HttpClient imageDownloadClient { get; } = new HttpClient();
private static byte[] downloadBytes(PictureDefinition def)
{
var sz = (int)def.Size;
return imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result;
}
if (def.PictureId is null)
return getDefaultImage(def.Size);
private static void saveFile(PictureDefinition def, byte[] bytes)
try
{
var sz = (int)def.Size;
var bytes = imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result;
// save image file. make sure to not save default image
var path = getPath(def);
File.WriteAllBytes(path, bytes);
return bytes;
}
catch
{
return getDefaultImage(def.Size);
}
}
}
}