Example #1
0
        private int decrypt(string tempRipFile)
        {
            FileExt.SafeDelete(tempRipFile);

            Console.WriteLine("Decrypting with key " + decryptKey);

            var returnCode = 100;
            var thread     = new Thread(() => returnCode = ngDecrypt());

            thread.Start();

            double fileLen = new FileInfo(inputFileName).Length;

            while (thread.IsAlive && returnCode == 100)
            {
                Thread.Sleep(500);
                if (File.Exists(tempRipFile))
                {
                    double tempLen         = new FileInfo(tempRipFile).Length;
                    var    percentProgress = tempLen / fileLen * 100.0;
                    DecryptProgressUpdate?.Invoke(this, (int)percentProgress);
                }
            }

            return(returnCode);
        }
Example #2
0
        public bool Step2_DecryptAax()
        {
            DecryptProgressUpdate?.Invoke(this, 0);

            var tempRipFile = Path.Combine(outDir, "funny.aac");

            var fail = "WARNING-Decrypt failure. ";

            int returnCode;

            if (string.IsNullOrWhiteSpace(decryptKey))
            {
                returnCode = getKey_decrypt(tempRipFile);
            }
            else
            {
                returnCode = decrypt(tempRipFile);
                if (returnCode == -99)
                {
                    Console.WriteLine($"{fail}Incorrect decrypt key: {decryptKey}");
                    decryptKey = null;
                    returnCode = getKey_decrypt(tempRipFile);
                }
            }

            if (returnCode == 100)
            {
                Console.WriteLine($"{fail}Thread completed without changing return code. This shouldn't be possible");
            }
            else if (returnCode == 0)
            {
                // success!
                FileExt.SafeMove(tempRipFile, outputFileWithNewExt(".mp4"));
                DecryptProgressUpdate?.Invoke(this, 100);
                return(true);
            }
            else if (returnCode == -99)
            {
                Console.WriteLine($"{fail}Incorrect decrypt key: {decryptKey}");
            }
            else // any other returnCode
            {
                Console.WriteLine($"{fail}Unknown failure code: {returnCode}");
            }

            FileExt.SafeDelete(tempRipFile);
            DecryptProgressUpdate?.Invoke(this, 0);
            return(false);
        }
        private void AaxFile_ConversionProgressUpdate(object sender, ConversionProgressEventArgs e)
        {
            var    duration = aaxFile.Duration;
            double remainingSecsToProcess = (duration - e.ProcessPosition).TotalSeconds;
            double estTimeRemaining       = remainingSecsToProcess / e.ProcessSpeed;

            if (double.IsNormal(estTimeRemaining))
            {
                DecryptTimeRemaining?.Invoke(this, TimeSpan.FromSeconds(estTimeRemaining));
            }

            double progressPercent = 100 * e.ProcessPosition.TotalSeconds / duration.TotalSeconds;

            DecryptProgressUpdate?.Invoke(this, (int)progressPercent);
        }
        public bool Step2_DownloadAndCombine()
        {
            DecryptProgressUpdate?.Invoke(this, 0);

            if (File.Exists(OutputFileName))
            {
                FileExt.SafeDelete(OutputFileName);
            }

            FileStream outFile = File.OpenWrite(OutputFileName);

            aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV);

            aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;

            var decryptionResult = OutputFormat == OutputFormat.Mp4a ? aaxFile.ConvertToMp4a(outFile, downloadLicense.ChapterInfo) : aaxFile.ConvertToMp3(outFile);

            aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;

            aaxFile.Close();

            downloadLicense.ChapterInfo = aaxFile.Chapters;

            if (decryptionResult == ConversionResult.NoErrorsDetected &&
                coverArt is not null &&
                OutputFormat == OutputFormat.Mp4a)
            {
                //This handles a special case where the aaxc file doesn't contain cover art and
                //Libation downloaded it instead (Animal Farm). Currently only works for Mp4a files.
                using var decryptedBook = new Mp4File(OutputFileName, FileAccess.ReadWrite);
                decryptedBook.AppleTags?.SetCoverArt(coverArt);
                decryptedBook.Save();
                decryptedBook.Close();
            }

            nfsPersister.Dispose();

            DecryptProgressUpdate?.Invoke(this, 0);

            return(decryptionResult == ConversionResult.NoErrorsDetected && !isCanceled);
        }