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:
parent
6b649cf4ca
commit
c296bff47f
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>6.6.4.1</Version>
|
<Version>6.6.5.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -174,7 +174,9 @@ namespace DtoImporterService
|
|||||||
var item = importItem.DtoItem;
|
var item = importItem.DtoItem;
|
||||||
|
|
||||||
// set/update book-specific info which may have changed
|
// set/update book-specific info which may have changed
|
||||||
|
if (item.PictureId is not null)
|
||||||
book.PictureId = item.PictureId;
|
book.PictureId = item.PictureId;
|
||||||
|
|
||||||
book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars);
|
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
|
// important to update user-specific info. this will have changed if user has rated/reviewed the book since last library import
|
||||||
|
|||||||
@ -73,16 +73,10 @@ namespace LibationFileManager
|
|||||||
if (!cache.ContainsKey(def) || cache[def] == null)
|
if (!cache.ContainsKey(def) || cache[def] == null)
|
||||||
{
|
{
|
||||||
var path = getPath(def);
|
var path = getPath(def);
|
||||||
byte[] bytes;
|
var bytes
|
||||||
|
= File.Exists(path)
|
||||||
if (File.Exists(path))
|
? File.ReadAllBytes(path)
|
||||||
bytes = File.ReadAllBytes(path);
|
: downloadBytes(def);
|
||||||
else
|
|
||||||
{
|
|
||||||
bytes = downloadBytes(def);
|
|
||||||
saveFile(def, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
cache[def] = bytes;
|
cache[def] = bytes;
|
||||||
}
|
}
|
||||||
return cache[def];
|
return cache[def];
|
||||||
@ -104,7 +98,6 @@ namespace LibationFileManager
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var bytes = downloadBytes(def);
|
var bytes = downloadBytes(def);
|
||||||
saveFile(def, bytes);
|
|
||||||
lock (cacheLocker)
|
lock (cacheLocker)
|
||||||
cache[def] = bytes;
|
cache[def] = bytes;
|
||||||
|
|
||||||
@ -115,14 +108,24 @@ namespace LibationFileManager
|
|||||||
private static HttpClient imageDownloadClient { get; } = new HttpClient();
|
private static HttpClient imageDownloadClient { get; } = new HttpClient();
|
||||||
private static byte[] downloadBytes(PictureDefinition def)
|
private static byte[] downloadBytes(PictureDefinition def)
|
||||||
{
|
{
|
||||||
var sz = (int)def.Size;
|
if (def.PictureId is null)
|
||||||
return imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result;
|
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);
|
var path = getPath(def);
|
||||||
File.WriteAllBytes(path, bytes);
|
File.WriteAllBytes(path, bytes);
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return getDefaultImage(def.Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user