Bugfix: decrypt file conflict

This commit is contained in:
Robert McRackan 2019-12-02 14:39:46 -05:00
parent b1b426427c
commit f1aacd92ad
4 changed files with 67 additions and 39 deletions

View File

@ -105,7 +105,9 @@ namespace AaxDecrypter
getASCIITag(tags.author), getASCIITag(tags.author),
getASCIITag(tags.title) + ".m4b" getASCIITag(tags.title) + ".m4b"
); );
SetOutputFilename(defaultFilename);
// set default name
SetOutputFilename(defaultFilename);
await Task.Run(() => saveCover(inputFileName)); await Task.Run(() => saveCover(inputFileName));
} }
@ -162,6 +164,9 @@ namespace AaxDecrypter
if (Path.GetExtension(outputFileName) != ".m4b") if (Path.GetExtension(outputFileName) != ".m4b")
outputFileName = outputFileWithNewExt(".m4b"); outputFileName = outputFileWithNewExt(".m4b");
if (File.Exists(outputFileName))
File.Delete(outputFileName);
outDir = Path.GetDirectoryName(outputFileName); outDir = Path.GetDirectoryName(outputFileName);
} }
@ -280,8 +285,9 @@ namespace AaxDecrypter
return exitCode; return exitCode;
} }
// temp file names for steps 3, 4, 5 // temp file names for steps 3, 4, 5
string tempChapsPath => Path.Combine(outDir, "tempChaps.mp4"); string tempChapsGuid { get; } = Guid.NewGuid().ToString().ToUpper().Replace("-", "");
string tempChapsPath => Path.Combine(outDir, $"tempChaps_{tempChapsGuid}.mp4");
string mp4_file => outputFileWithNewExt(".mp4"); string mp4_file => outputFileWithNewExt(".mp4");
string ff_txt_file => mp4_file + ".ff.txt"; string ff_txt_file => mp4_file + ".ff.txt";

View File

@ -94,6 +94,7 @@ namespace FileLiberator
NarratorsDiscovered?.Invoke(this, converter.tags.narrator); NarratorsDiscovered?.Invoke(this, converter.tags.narrator);
CoverImageFilepathDiscovered?.Invoke(this, converter.coverBytes); CoverImageFilepathDiscovered?.Invoke(this, converter.coverBytes);
// override default which was set in CreateAsync
converter.SetOutputFilename(proposedOutputFile); converter.SetOutputFilename(proposedOutputFile);
converter.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress); converter.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress);
@ -117,46 +118,58 @@ namespace FileLiberator
} }
private static void moveFilesToBooksDir(Book product, string outputAudioFilename) private static void moveFilesToBooksDir(Book product, string outputAudioFilename)
{ {
// files are: temp path\author\[asin].ext // create final directory. move each file into it. MOVE AUDIO FILE LAST
var m4bDir = new FileInfo(outputAudioFilename).Directory; // new dir: safetitle_limit50char + " [" + productId + "]"
var files = m4bDir
.EnumerateFiles()
.Where(f => f.Name.ContainsInsensitive(product.AudibleProductId))
.ToList();
// create final directory. move each file into it. MOVE AUDIO FILE LAST var destinationDir = getDestDir(product);
// new dir: safetitle_limit50char + " [" + productId + "]" Directory.CreateDirectory(destinationDir);
// to prevent the paths from getting too long, we don't need after the 1st ":" for the folder var sortedFiles = getProductFilesSorted(product, outputAudioFilename);
var underscoreIndex = product.Title.IndexOf(':');
var titleDir = (underscoreIndex < 4) ? product.Title : product.Title.Substring(0, underscoreIndex);
var finalDir = FileUtility.GetValidFilename(AudibleFileStorage.BooksDirectory, titleDir, null, product.AudibleProductId);
Directory.CreateDirectory(finalDir);
// move audio files to the end of the collection so these files are moved last var musicFileExt = Path.GetExtension(outputAudioFilename).Trim('.');
var musicFiles = files.Where(f => AudibleFileStorage.Audio.IsFileTypeMatch(f));
files = files
.Except(musicFiles)
.Concat(musicFiles)
.ToList();
var musicFileExt = musicFiles foreach (var f in sortedFiles)
.Select(f => f.Extension) {
.Distinct() var dest = AudibleFileStorage.Audio.IsFileTypeMatch(f)
.Single() // audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext
.Trim('.'); ? FileUtility.GetValidFilename(destinationDir, product.Title, musicFileExt, product.AudibleProductId)
// non-audio filename: safetitle_limit50char + " [" + productId + "][" + audio_ext +"]." + non_audio_ext
: FileUtility.GetValidFilename(destinationDir, product.Title, f.Extension, product.AudibleProductId, musicFileExt);
foreach (var f in files) File.Move(f.FullName, dest);
{ }
var dest = AudibleFileStorage.Audio.IsFileTypeMatch(f) }
// audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext
? FileUtility.GetValidFilename(finalDir, product.Title, musicFileExt, product.AudibleProductId)
// non-audio filename: safetitle_limit50char + " [" + productId + "][" + audio_ext +"]." + non_audio_ext
: FileUtility.GetValidFilename(finalDir, product.Title, f.Extension, product.AudibleProductId, musicFileExt);
File.Move(f.FullName, dest); private static string getDestDir(Book product)
} {
} // to prevent the paths from getting too long, we don't need after the 1st ":" for the folder
} var underscoreIndex = product.Title.IndexOf(':');
var titleDir
= underscoreIndex < 4
? product.Title
: product.Title.Substring(0, underscoreIndex);
var finalDir = FileUtility.GetValidFilename(AudibleFileStorage.BooksDirectory, titleDir, null, product.AudibleProductId);
return finalDir;
}
private static List<FileInfo> getProductFilesSorted(Book product, string outputAudioFilename)
{
// files are: temp path\author\[asin].ext
var m4bDir = new FileInfo(outputAudioFilename).Directory;
var files = m4bDir
.EnumerateFiles()
.Where(f => f.Name.ContainsInsensitive(product.AudibleProductId))
.ToList();
// move audio files to the end of the collection so these files are moved last
var musicFiles = files.Where(f => AudibleFileStorage.Audio.IsFileTypeMatch(f));
var sortedFiles = files
.Except(musicFiles)
.Concat(musicFiles)
.ToList();
return sortedFiles;
}
}
} }

View File

@ -44,6 +44,14 @@ namespace FileLiberator
tempAaxFilename, tempAaxFilename,
(p) => api.DownloadAaxWorkaroundAsync(libraryBook.Book.AudibleProductId, tempAaxFilename, p)); (p) => api.DownloadAaxWorkaroundAsync(libraryBook.Book.AudibleProductId, tempAaxFilename, p));
// if bad file download, a 0-33 byte file will be created
System.Threading.Thread.Sleep(100);
if (new FileInfo(actualFilePath).Length < 100)
{
File.Delete(actualFilePath);
throw new Exception("Error downloading file");
}
return actualFilePath; return actualFilePath;
} }

View File

@ -1,6 +1,7 @@
-- begin VERSIONING --------------------------------------------------------------------------------------------------------------------- -- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
https://github.com/rmcrackan/Libation/releases https://github.com/rmcrackan/Libation/releases
v3.1-beta.8 : Bugfix: decrypt file conflict
v3.1-beta.7 : Bugfix: decrypt book with no author v3.1-beta.7 : Bugfix: decrypt book with no author
v3.1-beta.6 : Improved logging v3.1-beta.6 : Improved logging
v3.1-beta.5 : Improved importing v3.1-beta.5 : Improved importing