Ejemplo n.º 1
0
        private async Task prelimProcessing()
        {
            tags         = new Tags(inputFileName);
            encodingInfo = new EncodingInfo(inputFileName);
            chapters     = new Chapters(inputFileName, tags.duration.TotalSeconds);

            var defaultFilename = Path.Combine(
                Path.GetDirectoryName(inputFileName),
                PathLib.ToPathSafeString(tags.author),
                PathLib.ToPathSafeString(tags.title) + ".m4b"
                );

            // set default name
            SetOutputFilename(defaultFilename);

            await Task.Run(() => saveCover(inputFileName));
        }
Ejemplo n.º 2
0
        private async Task <string> aaxToM4bConverterDecryptAsync(string cacheDir, string destinationDir, LibraryBook libraryBook)
        {
            DecryptBegin?.Invoke(this, $"Begin decrypting {libraryBook}");

            try
            {
                validate(libraryBook);

                var api = await InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale);

                var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId);

                var aaxcDecryptDlLic = new DownloadLicense
                                       (
                    contentLic.ContentMetadata?.ContentUrl?.OfflineUrl,
                    contentLic.Voucher?.Key,
                    contentLic.Voucher?.Iv,
                    Resources.UserAgent
                                       );

                if (Configuration.Instance.AllowLibationFixup)
                {
                    aaxcDecryptDlLic.ChapterInfo = new AAXClean.ChapterInfo();

                    foreach (var chap in contentLic.ContentMetadata?.ChapterInfo?.Chapters)
                    {
                        aaxcDecryptDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs));
                    }
                }


                var format = Configuration.Instance.DecryptToLossy ? OutputFormat.Mp3 : OutputFormat.Mp4a;

                var extension = format switch
                {
                    OutputFormat.Mp4a => "m4b",
                    OutputFormat.Mp3 => "mp3",
                    _ => throw new NotImplementedException(),
                };

                var proposedOutputFile = Path.Combine(destinationDir, $"{PathLib.ToPathSafeString(libraryBook.Book.Title)} [{libraryBook.Book.AudibleProductId}].{extension}");


                aaxcDownloader = new AaxcDownloadConverter(proposedOutputFile, cacheDir, aaxcDecryptDlLic, format)
                {
                    AppName = "Libation"
                };
                aaxcDownloader.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress);
                aaxcDownloader.DecryptTimeRemaining  += (s, remaining) => UpdateRemainingTime?.Invoke(this, remaining);
                aaxcDownloader.RetrievedCoverArt     += AaxcDownloader_RetrievedCoverArt;
                aaxcDownloader.RetrievedTags         += aaxcDownloader_RetrievedTags;

                // REAL WORK DONE HERE
                var success = await Task.Run(() => aaxcDownloader.Run());

                // decrypt failed
                if (!success)
                {
                    return(null);
                }

                return(aaxcDownloader.OutputFileName);
            }
            finally
            {
                DecryptCompleted?.Invoke(this, $"Completed downloading and decrypting {libraryBook.Book.Title}");
            }
        }