mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-12 13:47:16 -04:00
getProposedDownloadFilePath looked for the book's audio file and fell back to the Books directory itself when it found none. That lookup matches on the product id appearing in the path, so it finds nothing for a library whose folder and file templates omit <id>, and nothing for a title marked downloaded whose files are not on this machine. Those PDFs landed in the library root, where they also shared one namespace and so could collide with each other. Fall back to the folder template instead - the same folder the audiobook itself would go in - and create it, since nothing else does on the PDF-only path. Also give MockLibraryBook a three-field version: ToVersionString formats to at least three fields, so the two-field default threw as soon as anything rendered a naming template for a mock book. Co-authored-by: rmcrackan <rmcrackan@gmail.com>
56 lines
2.4 KiB
C#
56 lines
2.4 KiB
C#
using AaxDecrypter;
|
|
using DataLayer;
|
|
using LibationFileManager;
|
|
using LibationFileManager.Templates;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
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, Configuration? config = null)
|
|
{
|
|
if (AudibleFileStorage.BooksDirectory is not { } books)
|
|
throw new InvalidOperationException("Books directory is not set.");
|
|
|
|
config ??= Configuration.Instance;
|
|
if (libraryBook.Book.IsEpisodeChild() && config.SavePodcastsToParentFolder)
|
|
{
|
|
var series = libraryBook.Book.SeriesLink.SingleOrDefault();
|
|
if (series is not null)
|
|
{
|
|
LibraryBook? seriesParent = ApplicationServices.DbContexts.GetLibraryBook_Flat_NoTracking(
|
|
series.Series.AudibleSeriesId,
|
|
account: libraryBook.Account);
|
|
if (seriesParent is not null)
|
|
{
|
|
return Templates.Folder.GetFilename(seriesParent.ToDto(), books, "");
|
|
}
|
|
}
|
|
}
|
|
return Templates.Folder.GetFilename(libraryBook.ToDto(), books, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// A file name from the file template, directly under the Books directory rather than in the book's own
|
|
/// folder. Only the "save a copy of the cover art" dialogs use this, and only for the name they suggest.
|
|
/// </summary>
|
|
public static string GetBooksDirectoryFilename(this AudioFileStorage _, LibraryBook libraryBook, string extension, bool returnFirstExisting = false)
|
|
=> AudibleFileStorage.BooksDirectory is { } books ? Templates.File.GetFilename(libraryBook.ToDto(), books, extension, null, returnFirstExisting)
|
|
: throw new InvalidOperationException("Books directory is not set.");
|
|
|
|
/// <summary>
|
|
/// A file name from the file template, in a directory the caller has already chosen.
|
|
/// </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);
|
|
}
|