diff --git a/AaxDecrypter/AaxDecrypter.csproj b/AaxDecrypter/AaxDecrypter.csproj index 9262a8fc..4e49e78c 100644 --- a/AaxDecrypter/AaxDecrypter.csproj +++ b/AaxDecrypter/AaxDecrypter.csproj @@ -4,43 +4,9 @@ net5.0 - - - - - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index 84610fbe..72e1a4e2 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -19,7 +19,7 @@ namespace AaxDecrypter string outDir { get; } string outputFileName { get; } DownloadLicense downloadLicense { get; } - Mp4File aaxFile { get; } + AaxFile aaxFile { get; } byte[] coverArt { get; } void SetCoverArt(byte[] coverArt); void SetOutputFilename(string outFileName); @@ -45,7 +45,7 @@ namespace AaxDecrypter public string cacheDir { get; private set; } public string outputFileName { get; private set; } public DownloadLicense downloadLicense { get; private set; } - public Mp4File aaxFile { get; private set; } + public AaxFile aaxFile { get; private set; } public byte[] coverArt { get; private set; } private StepSequence steps { get; } @@ -136,22 +136,27 @@ namespace AaxDecrypter if (File.Exists(jsonDownloadState)) { - nfsPersister = new NetworkFileStreamPersister(jsonDownloadState); - //If More thaan ~1 hour has elapsed since getting the download url, it will expire. - //The new url will be to the same file. - nfsPersister.NetworkFileStream.SetUriForSameFile(new Uri(downloadLicense.DownloadUrl)); + try + { + nfsPersister = new NetworkFileStreamPersister(jsonDownloadState); + //If More thaan ~1 hour has elapsed since getting the download url, it will expire. + //The new url will be to the same file. + nfsPersister.NetworkFileStream.SetUriForSameFile(new Uri(downloadLicense.DownloadUrl)); + } + catch + { + FileExt.SafeDelete(jsonDownloadState); + FileExt.SafeDelete(tempFile); + nfsPersister = NewNetworkFilePersister(); + } } else { - var headers = new System.Net.WebHeaderCollection(); - headers.Add("User-Agent", downloadLicense.UserAgent); - - NetworkFileStream networkFileStream = new NetworkFileStream(tempFile, new Uri(downloadLicense.DownloadUrl), 0, headers); - nfsPersister = new NetworkFileStreamPersister(networkFileStream, jsonDownloadState); + nfsPersister = NewNetworkFilePersister(); } nfsPersister.NetworkFileStream.BeginDownloading(); - aaxFile = new Mp4File(nfsPersister.NetworkFileStream); + aaxFile = new AaxFile(nfsPersister.NetworkFileStream); coverArt = aaxFile.AppleTags.Cover; RetrievedTags?.Invoke(this, aaxFile.AppleTags); @@ -159,6 +164,14 @@ namespace AaxDecrypter return !isCanceled; } + private NetworkFileStreamPersister NewNetworkFilePersister() + { + var headers = new System.Net.WebHeaderCollection(); + headers.Add("User-Agent", downloadLicense.UserAgent); + + NetworkFileStream networkFileStream = new NetworkFileStream(tempFile, new Uri(downloadLicense.DownloadUrl), 0, headers); + return new NetworkFileStreamPersister(networkFileStream, jsonDownloadState); + } public bool Step3_DownloadAndCombine() { @@ -170,7 +183,7 @@ namespace AaxDecrypter FileStream outFile = File.OpenWrite(outputFileName); aaxFile.DecryptionProgressUpdate += AaxFile_DecryptionProgressUpdate; - var decryptedBook = aaxFile.DecryptAaxc(outFile, downloadLicense.AudibleKey, downloadLicense.AudibleIV, downloadLicense.ChapterInfo); + using var decryptedBook = aaxFile.DecryptAaxc(outFile, downloadLicense.AudibleKey, downloadLicense.AudibleIV, downloadLicense.ChapterInfo); aaxFile.DecryptionProgressUpdate -= AaxFile_DecryptionProgressUpdate; downloadLicense.ChapterInfo = aaxFile.Chapters; diff --git a/AaxDecrypter/DecryptLib/avcodec-58.dll b/AaxDecrypter/DecryptLib/avcodec-58.dll deleted file mode 100644 index 596f682a..00000000 Binary files a/AaxDecrypter/DecryptLib/avcodec-58.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/avdevice-58.dll b/AaxDecrypter/DecryptLib/avdevice-58.dll deleted file mode 100644 index f88b6c5c..00000000 Binary files a/AaxDecrypter/DecryptLib/avdevice-58.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/avfilter-7.dll b/AaxDecrypter/DecryptLib/avfilter-7.dll deleted file mode 100644 index 6cbedea3..00000000 Binary files a/AaxDecrypter/DecryptLib/avfilter-7.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/avformat-58.dll b/AaxDecrypter/DecryptLib/avformat-58.dll deleted file mode 100644 index 37161814..00000000 Binary files a/AaxDecrypter/DecryptLib/avformat-58.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/avutil-56.dll b/AaxDecrypter/DecryptLib/avutil-56.dll deleted file mode 100644 index d1565ae4..00000000 Binary files a/AaxDecrypter/DecryptLib/avutil-56.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/ffmpeg.exe b/AaxDecrypter/DecryptLib/ffmpeg.exe deleted file mode 100644 index f2840373..00000000 Binary files a/AaxDecrypter/DecryptLib/ffmpeg.exe and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/ffprobe.exe b/AaxDecrypter/DecryptLib/ffprobe.exe deleted file mode 100644 index 6028bea1..00000000 Binary files a/AaxDecrypter/DecryptLib/ffprobe.exe and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/swresample-3.dll b/AaxDecrypter/DecryptLib/swresample-3.dll deleted file mode 100644 index d2f5ea87..00000000 Binary files a/AaxDecrypter/DecryptLib/swresample-3.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptLib/swscale-5.dll b/AaxDecrypter/DecryptLib/swscale-5.dll deleted file mode 100644 index a30c307e..00000000 Binary files a/AaxDecrypter/DecryptLib/swscale-5.dll and /dev/null differ diff --git a/AaxDecrypter/DecryptSupportLibraries.cs b/AaxDecrypter/DecryptSupportLibraries.cs deleted file mode 100644 index 8eb5ddb9..00000000 --- a/AaxDecrypter/DecryptSupportLibraries.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.IO; - -namespace AaxDecrypter -{ - public static class DecryptSupportLibraries - { - // OTHER EXTERNAL DEPENDENCIES - // ffprobe has these pre-req.s as I'm using it: - // avcodec-58.dll, avdevice-58.dll, avfilter-7.dll, avformat-58.dll, avutil-56.dll, swresample-3.dll, swscale-5.dll, taglib-sharp.dll - - private static string appPath_ { get; } = Path.GetDirectoryName(Dinah.Core.Exe.FileLocationOnDisk); - private static string decryptLib_ { get; } = Path.Combine(appPath_, "DecryptLib"); - public static string ffmpegPath { get; } = Path.Combine(decryptLib_, "ffmpeg.exe"); - public static string ffprobePath { get; } = Path.Combine(decryptLib_, "ffprobe.exe"); - } -} \ No newline at end of file diff --git a/AaxDecrypter/NetworkFileAbstraction.cs b/AaxDecrypter/NetworkFileAbstraction.cs deleted file mode 100644 index 60f52a9f..00000000 --- a/AaxDecrypter/NetworkFileAbstraction.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.IO; -using System.Net.Http; -using System.Threading.Tasks; - -namespace AaxDecrypter -{ - /// - /// Provides a for a file over Http. - /// - class NetworkFileAbstraction : TagLib.File.IFileAbstraction - { - private NetworkFileStream aaxNetworkStream; - - public NetworkFileAbstraction( NetworkFileStream networkFileStream) - { - Name = networkFileStream.SaveFilePath; - aaxNetworkStream = networkFileStream; - } - public string Name { get; private set; } - - public Stream ReadStream => aaxNetworkStream; - - public Stream WriteStream => throw new NotImplementedException(); - - public void CloseStream(Stream stream) - { - aaxNetworkStream.Close(); - } - } -}