Move cover art downloader to DownloadDecryptBook
This commit is contained in:
parent
de9b3fd6ec
commit
9a5d9f3867
@ -71,6 +71,8 @@ namespace FileLiberator
|
|||||||
// moves new files from temp dir to final dest
|
// moves new files from temp dir to final dest
|
||||||
var movedAudioFile = moveFilesToBooksDir(libraryBook, entries);
|
var movedAudioFile = moveFilesToBooksDir(libraryBook, entries);
|
||||||
|
|
||||||
|
DownloadCoverArt(libraryBook);
|
||||||
|
|
||||||
// decrypt failed
|
// decrypt failed
|
||||||
if (!movedAudioFile)
|
if (!movedAudioFile)
|
||||||
return new StatusHandler { "Cannot find final audio file after decryption" };
|
return new StatusHandler { "Cannot find final audio file after decryption" };
|
||||||
@ -187,31 +189,27 @@ namespace FileLiberator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NAudio.Lame.LameConfig lameConfig = new();
|
audiobookDlLic.LameConfig = new();
|
||||||
|
audiobookDlLic.LameConfig.Mode = NAudio.Lame.MPEGMode.Mono;
|
||||||
|
|
||||||
lameConfig.Mode = NAudio.Lame.MPEGMode.Mono;
|
|
||||||
|
|
||||||
if (config.LameTargetBitrate)
|
if (config.LameTargetBitrate)
|
||||||
{
|
{
|
||||||
if (config.LameConstantBitrate)
|
if (config.LameConstantBitrate)
|
||||||
lameConfig.BitRate = config.LameBitrate;
|
audiobookDlLic.LameConfig.BitRate = config.LameBitrate;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lameConfig.ABRRateKbps = config.LameBitrate;
|
audiobookDlLic.LameConfig.ABRRateKbps = config.LameBitrate;
|
||||||
lameConfig.VBR = NAudio.Lame.VBRMode.ABR;
|
audiobookDlLic.LameConfig.VBR = NAudio.Lame.VBRMode.ABR;
|
||||||
lameConfig.WriteVBRTag = true;
|
audiobookDlLic.LameConfig.WriteVBRTag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lameConfig.VBR = NAudio.Lame.VBRMode.Default;
|
audiobookDlLic.LameConfig.VBR = NAudio.Lame.VBRMode.Default;
|
||||||
lameConfig.VBRQuality = config.LameVBRQuality;
|
audiobookDlLic.LameConfig.VBRQuality = config.LameVBRQuality;
|
||||||
lameConfig.WriteVBRTag = true;
|
audiobookDlLic.LameConfig.WriteVBRTag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
audiobookDlLic.LameConfig = lameConfig;
|
|
||||||
|
|
||||||
return audiobookDlLic;
|
return audiobookDlLic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,5 +275,34 @@ namespace FileLiberator
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DownloadCoverArt(LibraryBook libraryBook)
|
||||||
|
{
|
||||||
|
var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook);
|
||||||
|
var coverPath = AudibleFileStorage.Audio.GetBooksDirectoryFilename(libraryBook, ".jpg");
|
||||||
|
coverPath = Path.Combine(destinationDir, Path.GetFileName(coverPath));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(coverPath))
|
||||||
|
FileUtility.SaferDelete(coverPath);
|
||||||
|
|
||||||
|
(string picId, PictureSize size) = libraryBook.Book.PictureLarge is null ?
|
||||||
|
(libraryBook.Book.PictureId, PictureSize.Native) :
|
||||||
|
(libraryBook.Book.PictureLarge, PictureSize.Native);
|
||||||
|
|
||||||
|
var picBytes = PictureStorage.GetPictureSynchronously(new PictureDefinition(picId, size));
|
||||||
|
|
||||||
|
if (picBytes.Length > 0)
|
||||||
|
File.WriteAllBytes(coverPath, picBytes);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//Failure to download cover art should not be
|
||||||
|
//considered a failure to download the book
|
||||||
|
Serilog.Log.Logger.Error(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,38 +48,9 @@ namespace FileLiberator
|
|||||||
= (await ProcessAsync(libraryBook))
|
= (await ProcessAsync(libraryBook))
|
||||||
?? new StatusHandler { "Processable should never return a null status" };
|
?? new StatusHandler { "Processable should never return a null status" };
|
||||||
|
|
||||||
if (status.IsSuccess)
|
|
||||||
DownloadCoverArt(libraryBook);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DownloadCoverArt(LibraryBook libraryBook)
|
|
||||||
{
|
|
||||||
var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook);
|
|
||||||
var coverPath = FileManager.FileUtility.GetValidFilename(System.IO.Path.Combine(destinationDir, "Cover.jpg"), "", true);
|
|
||||||
|
|
||||||
if (System.IO.File.Exists(coverPath)) return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
(string picId, PictureSize size) = libraryBook.Book.PictureLarge is null ?
|
|
||||||
(libraryBook.Book.PictureId, PictureSize.Native) :
|
|
||||||
(libraryBook.Book.PictureLarge, PictureSize.Native);
|
|
||||||
|
|
||||||
var picBytes = PictureStorage.GetPictureSynchronously(new PictureDefinition(picId, size));
|
|
||||||
|
|
||||||
if (picBytes.Length > 0)
|
|
||||||
System.IO.File.WriteAllBytes(coverPath, picBytes);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//Failure to download cover art should not be
|
|
||||||
//considered a failure to download the book
|
|
||||||
Serilog.Log.Logger.Error(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<StatusHandler> TryProcessAsync(LibraryBook libraryBook)
|
public async Task<StatusHandler> TryProcessAsync(LibraryBook libraryBook)
|
||||||
=> Validate(libraryBook)
|
=> Validate(libraryBook)
|
||||||
? await ProcessAsync(libraryBook)
|
? await ProcessAsync(libraryBook)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user