- Add more null safety - Fix possible FilePathCache race condition - Add MoveFilesToBooksDir progress reporting - All metadata is now downloaded in parallel with other post-success tasks. - Improve download resuming and file cleanup reliability - The downloader creates temp files with a UUID filename and does not insert them into the FilePathCache. Created files only receive their final file names when they are moved into the Books folder. This is to prepare for a future plan re naming templates
52 lines
2.1 KiB
C#
52 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AaxDecrypter;
|
|
using DataLayer;
|
|
using LibationFileManager;
|
|
using LibationFileManager.Templates;
|
|
|
|
namespace FileLiberator
|
|
{
|
|
public static class AudioFileStorageExt
|
|
{
|
|
/// <summary>
|
|
/// DownloadDecryptBook:
|
|
/// File path for where to move files into.
|
|
/// Path: directory nested inside of Books directory
|
|
/// File name: n/a
|
|
/// </summary>
|
|
public static string GetDestinationDirectory(this AudioFileStorage _, LibraryBook libraryBook)
|
|
{
|
|
if (libraryBook.Book.IsEpisodeChild() && Configuration.Instance.SavePodcastsToParentFolder)
|
|
{
|
|
var series = libraryBook.Book.SeriesLink.SingleOrDefault();
|
|
if (series is not null)
|
|
{
|
|
using var context = ApplicationServices.DbContexts.GetContext();
|
|
var seriesParent = context.GetLibraryBook_Flat_NoTracking(series.Series.AudibleSeriesId);
|
|
|
|
if (seriesParent is not null)
|
|
{
|
|
return Templates.Folder.GetFilename(seriesParent.ToDto(), AudibleFileStorage.BooksDirectory, "");
|
|
}
|
|
}
|
|
}
|
|
return Templates.Folder.GetFilename(libraryBook.ToDto(), AudibleFileStorage.BooksDirectory, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// PDF: audio file does not exist
|
|
/// </summary>
|
|
public static string GetBooksDirectoryFilename(this AudioFileStorage _, LibraryBook libraryBook, string extension, bool returnFirstExisting = false)
|
|
=> Templates.File.GetFilename(libraryBook.ToDto(), AudibleFileStorage.BooksDirectory, extension, returnFirstExisting: returnFirstExisting);
|
|
|
|
/// <summary>
|
|
/// PDF: audio file already exists
|
|
/// </summary>
|
|
public static string GetCustomDirFilename(this AudioFileStorage _, LibraryBook libraryBook, string dirFullPath, string extension, MultiConvertFileProperties partProperties = null, bool returnFirstExisting = false)
|
|
=> partProperties is null ? Templates.File.GetFilename(libraryBook.ToDto(), dirFullPath, extension, returnFirstExisting: returnFirstExisting)
|
|
: Templates.ChapterFile.GetFilename(libraryBook.ToDto(), partProperties, dirFullPath, extension, returnFirstExisting: returnFirstExisting);
|
|
}
|
|
}
|