mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-13 06:07:30 -04:00
Reported in issue #1973: a scheduled liberate run re-requested a content license for the same 59 titles every 15 minutes, 1397 refused requests in six hours, because nothing about a failed PDF was remembered and the PDF step asked Audible afresh every time. The two download paths have been converging for a while - a PDF is now named and placed by the audiobook path's own logic, and verified like one - and every part of this bug lives where that stopped short. Both steps ask Audible for the same license. The request asks for pdf_url alongside the content reference, and LicenseInfo dropped it, so DownloadPdf turned round and requested an identical license to read the field the first response had already returned. Carry PdfUrl on LicenseInfo and give both steps one ILicensedDownload contract: a license may be supplied to a step, and the one a step ended up using is published for the next step for the same title. The CLI and the GUI queue hand it on, so a title costs one license request per run however many steps want something from it. A carried license is retried once with a fresh one if it does not work, since Audible's links are signed and a long decrypt can run between the two steps. Where the audiobook step obtained no license there is nothing to hand on and the supplement step does not run, which deletes a bug rather than guarding it: Completed fires from a finally, so a refused audio download was followed at once by a PDF request that reproduced the refusal. Error now means the same for a PDF as for a book. The audiobook step has always skipped LiberatedStatus.Error through AudioExists, and NeedsPdfDownload agrees, but DownloadPdf selected on PdfExists and so retried an errored PDF forever. A license that is granted and carries no pdf_url - the 'No PDF URL available' in the report - is Audible saying the title has no PDF, and is written off that same way instead of failing identically on every run. It stays resettable by everything that resets a book: --force, a named title, Set PDF Not Downloaded. Refusals now reach ProcessSingleAsync, which has always recorded them for whichever step throws one; DownloadPdf swallowed everything and recorded nothing. It keeps swallowing what the classifier does not recognise, which is what stopped a missing PDF from taking the app down with it. A bulk CLI run leaves alone the titles the last scan did not find, by the same Downloadable rule every multi-title path in the app already uses, and the PDF back-fill pass waits on a refused title just as the first pass does. --force and a named title still attempt everything. Co-authored-by: rmcrackan <rmcrackan@gmail.com>
94 lines
4.0 KiB
C#
94 lines
4.0 KiB
C#
using AaxDecrypter;
|
|
using DataLayer;
|
|
using Dinah.Core;
|
|
using LibationFileManager;
|
|
using LibationFileManager.Templates;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace FileLiberator;
|
|
|
|
public partial class DownloadOptions : IDownloadOptions, IDisposable
|
|
{
|
|
public event EventHandler<long>? DownloadSpeedChanged;
|
|
public LibraryBook LibraryBook { get; }
|
|
public LibraryBookDto LibraryBookDto { get; }
|
|
public string DownloadUrl { get; }
|
|
public KeyData[]? DecryptionKeys { get; }
|
|
public required TimeSpan RuntimeLength { get; init; }
|
|
public OutputFormat OutputFormat { get; }
|
|
public required Mpeg4Lib.ChapterInfo ChapterInfo { get; init; }
|
|
public string Title => LibraryBook.Book.Title;
|
|
public string Subtitle => LibraryBook.Book.Subtitle;
|
|
public string? Publisher => LibraryBook.Book.Publisher;
|
|
public string? Language => LibraryBook.Book.Language;
|
|
public string AudibleProductId => LibraryBookDto.AudibleProductId;
|
|
public string? SeriesName => LibraryBookDto.FirstSeries?.Name;
|
|
public string? SeriesNumber => LibraryBookDto.FirstSeries?.Order?.ToString();
|
|
public NAudio.Lame.LameConfig? LameConfig { get; }
|
|
public string UserAgent => AudibleApi.Resources.Download_User_Agent;
|
|
public bool StripUnabridged => Config.AllowLibationFixup && Config.StripUnabridged;
|
|
public bool CreateCueSheet => Config.CreateCueSheet;
|
|
public long DownloadSpeedBps => Config.DownloadSpeedLimit;
|
|
public bool FixupFile => Config.AllowLibationFixup;
|
|
public bool Downsample => Config.AllowLibationFixup && Config.LameDownsampleMono;
|
|
public bool MatchSourceBitrate => Config.AllowLibationFixup && Config.LameMatchSourceBR && Config.LameTargetBitrate;
|
|
public bool MoveMoovToBeginning => Config.MoveMoovToBeginning;
|
|
public AAXClean.FileType? InputType { get; }
|
|
public AudibleApi.Common.DrmType DrmType { get; }
|
|
public AudibleApi.Common.ContentMetadata ContentMetadata { get; }
|
|
|
|
public string GetMultipartTitle(MultiConvertFileProperties props)
|
|
=> Templates.ChapterTitle.GetName(LibraryBookDto, props);
|
|
|
|
public Configuration Config { get; }
|
|
private readonly IDisposable cancellation;
|
|
public void Dispose()
|
|
{
|
|
cancellation?.Dispose();
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
private DownloadOptions(Configuration config, LibraryBook libraryBook, LicenseInfo licInfo)
|
|
{
|
|
Config = ArgumentValidator.EnsureNotNull(config, nameof(config));
|
|
LibraryBook = ArgumentValidator.EnsureNotNull(libraryBook, nameof(libraryBook));
|
|
|
|
ArgumentValidator.EnsureNotNull(licInfo, nameof(licInfo));
|
|
|
|
if (licInfo.ContentMetadata is not AudibleApi.Common.ContentMetadata contentMetadata)
|
|
throw new InvalidDataException("Content license doesn't contain content metadata");
|
|
|
|
if (contentMetadata.ContentUrl?.OfflineUrl is not string licUrl)
|
|
throw new InvalidDataException("Content license doesn't contain an offline Url");
|
|
|
|
DownloadUrl = licUrl;
|
|
DecryptionKeys = licInfo.DecryptionKeys;
|
|
DrmType = licInfo.DrmType;
|
|
ContentMetadata = contentMetadata;
|
|
InputType
|
|
= licInfo.DrmType is AudibleApi.Common.DrmType.Widevine ? AAXClean.FileType.Dash
|
|
: licInfo.DrmType is AudibleApi.Common.DrmType.Adrm && licInfo.DecryptionKeys?.Length == 1 && licInfo.DecryptionKeys[0].KeyPart1.Length == 4 && licInfo.DecryptionKeys[0].KeyPart2 is null ? AAXClean.FileType.Aax
|
|
: licInfo.DrmType is AudibleApi.Common.DrmType.Adrm && licInfo.DecryptionKeys?.Length == 1 && licInfo.DecryptionKeys[0].KeyPart1.Length == 16 && licInfo.DecryptionKeys[0].KeyPart2?.Length == 16 ? AAXClean.FileType.Aaxc
|
|
: null;
|
|
|
|
//If DrmType is not Adrm or Widevine, the delivered file is an unencrypted mp3.
|
|
OutputFormat
|
|
= licInfo.DrmType is not AudibleApi.Common.DrmType.Adrm and not AudibleApi.Common.DrmType.Widevine ||
|
|
(config.AllowLibationFixup && config.DecryptToLossy)
|
|
? OutputFormat.Mp3
|
|
: OutputFormat.M4b;
|
|
|
|
LameConfig = OutputFormat == OutputFormat.Mp3 ? GetLameOptions(config) : null;
|
|
|
|
// no null/empty check for key/iv. unencrypted files do not have them
|
|
LibraryBookDto = LibraryBook.ToDto();
|
|
|
|
cancellation =
|
|
config
|
|
.ObservePropertyChanged<long>(
|
|
nameof(Configuration.DownloadSpeedLimit),
|
|
newVal => DownloadSpeedChanged?.Invoke(this, newVal));
|
|
}
|
|
}
|