All audible-related file naming terminates at FileUtility
File extensions: Dinah.Core => Libation FileUtility
This commit is contained in:
parent
6a81b9b02d
commit
648b84ee55
15 changed files with 162 additions and 101 deletions
|
|
@ -1,13 +1,12 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AAXClean;
|
||||
using DataLayer;
|
||||
using Dinah.Core;
|
||||
using Dinah.Core.ErrorHandling;
|
||||
using Dinah.Core.IO;
|
||||
using Dinah.Core.Net.Http;
|
||||
using FileManager;
|
||||
using LibationFileManager;
|
||||
|
||||
namespace FileLiberator
|
||||
|
|
@ -52,10 +51,9 @@ namespace FileLiberator
|
|||
m4bBook.InputStream.Close();
|
||||
mp3File.Close();
|
||||
|
||||
var mp3Path = Mp3FileName(m4bPath);
|
||||
|
||||
FileExt.SafeMove(mp3File.Name, mp3Path);
|
||||
OnFileCreated(libraryBook.Book.AudibleProductId, mp3Path);
|
||||
var proposedMp3Path = Mp3FileName(m4bPath);
|
||||
var realMp3Path = FileUtility.Move(mp3File.Name, proposedMp3Path);
|
||||
OnFileCreated(libraryBook, realMp3Path);
|
||||
|
||||
var statusHandler = new StatusHandler();
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ namespace FileLiberator
|
|||
abDownloader.RetrievedAuthors += (_, authors) => OnAuthorsDiscovered(authors);
|
||||
abDownloader.RetrievedNarrators += (_, narrators) => OnNarratorsDiscovered(narrators);
|
||||
abDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt;
|
||||
abDownloader.FileCreated += (_, path) => OnFileCreated(libraryBook.Book.AudibleProductId, path);
|
||||
abDownloader.FileCreated += (_, path) => OnFileCreated(libraryBook, path);
|
||||
|
||||
// REAL WORK DONE HERE
|
||||
var success = await Task.Run(abDownloader.Run);
|
||||
|
|
@ -189,31 +189,26 @@ namespace FileLiberator
|
|||
var destinationDir = FileUtility.GetValidFilename(AudibleFileStorage.BooksDirectory, titleDir, null, asin);
|
||||
Directory.CreateDirectory(destinationDir);
|
||||
|
||||
var music = entries.FirstOrDefault(f => f.FileType == FileType.Audio);
|
||||
FilePathCache.CacheEntry getFirstAudio() => entries.FirstOrDefault(f => f.FileType == FileType.Audio);
|
||||
|
||||
if (music == default)
|
||||
if (getFirstAudio() == default)
|
||||
return false;
|
||||
|
||||
var musicFileExt = Path.GetExtension(music.Path).Trim('.');
|
||||
|
||||
var audioFileName = FileUtility.GetValidFilename(destinationDir, book.Title, musicFileExt, book.AudibleProductId);
|
||||
|
||||
foreach (var entry in entries)
|
||||
for (var i = 0; i < entries.Count; i++)
|
||||
{
|
||||
var fileInfo = new FileInfo(entry.Path);
|
||||
var entry = entries[i];
|
||||
|
||||
var dest
|
||||
= entry.FileType == FileType.Audio
|
||||
? Path.Join(destinationDir, fileInfo.Name)
|
||||
: FileUtility.GetValidFilename(destinationDir, book.Title, fileInfo.Extension, book.AudibleProductId, musicFileExt);
|
||||
var realDest = FileUtility.Move(entry.Path, Path.Combine(destinationDir, Path.GetFileName(entry.Path)));
|
||||
FilePathCache.Insert(book.AudibleProductId, realDest);
|
||||
|
||||
if (Path.GetExtension(dest).Trim('.').ToLower() == "cue")
|
||||
Cue.UpdateFileName(fileInfo, audioFileName);
|
||||
|
||||
File.Move(fileInfo.FullName, dest);
|
||||
FilePathCache.Insert(book.AudibleProductId, dest);
|
||||
// propogate corrected path. Must update cache with corrected path. Also want updated path for cue file (after this for-loop)
|
||||
entries[i] = entry with { Path = realDest };
|
||||
}
|
||||
|
||||
var cue = entries.FirstOrDefault(f => f.FileType == FileType.Cue);
|
||||
if (cue != default)
|
||||
Cue.UpdateFileName(cue.Path, getFirstAudio().Path);
|
||||
|
||||
AudibleFileStorage.Audio.Refresh();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace FileLiberator
|
|||
var client = new HttpClient();
|
||||
|
||||
var actualDownloadedFilePath = await client.DownloadFileAsync(downloadUrl, proposedDownloadFilePath, progress);
|
||||
OnFileCreated(libraryBook.Book.AudibleProductId, actualDownloadedFilePath);
|
||||
OnFileCreated(libraryBook, actualDownloadedFilePath);
|
||||
|
||||
OnStatusUpdate(actualDownloadedFilePath);
|
||||
return actualDownloadedFilePath;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ namespace FileLiberator
|
|||
StreamingCompleted?.Invoke(this, filePath);
|
||||
}
|
||||
|
||||
protected void OnFileCreated(DataLayer.LibraryBook libraryBook, string path) => OnFileCreated(libraryBook.Book.AudibleProductId, path);
|
||||
protected void OnFileCreated(string id, string path)
|
||||
{
|
||||
Serilog.Log.Logger.Information("File created {@DebugInfo}", new { Name = nameof(FileCreated), id, path });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue