Centralize audio/aaxc files GetPath and Exists into temp TransitionalFileLocator
This commit is contained in:
parent
d4fbb03577
commit
0c265a9010
10 changed files with 80 additions and 40 deletions
|
|
@ -6,7 +6,6 @@ using AudibleApi;
|
|||
using DataLayer;
|
||||
using Dinah.Core;
|
||||
using DtoImporterService;
|
||||
using FileManager;
|
||||
using InternalUtilities;
|
||||
using Serilog;
|
||||
|
||||
|
|
@ -181,8 +180,8 @@ namespace ApplicationServices
|
|||
// this is a query, not command so maybe I should make a LibraryQueries. except there's already one of those...
|
||||
private enum AudioFileState { full, aax, none }
|
||||
private static AudioFileState getAudioFileState(string productId)
|
||||
=> AudibleFileStorage.Audio.Exists(productId) ? AudioFileState.full
|
||||
: AudibleFileStorage.AAXC.Exists(productId) ? AudioFileState.aax
|
||||
=> TransitionalFileLocator.Audio_Exists(productId) ? AudioFileState.full
|
||||
: TransitionalFileLocator.AAXC_Exists(productId) ? AudioFileState.aax
|
||||
: AudioFileState.none;
|
||||
public record LibraryStats(int booksFullyBackedUp, int booksDownloadedOnly, int booksNoProgress, int pdfsDownloaded, int pdfsNotDownloaded) { }
|
||||
public static LibraryStats GetCounts()
|
||||
|
|
@ -202,7 +201,7 @@ namespace ApplicationServices
|
|||
var boolResults = libraryBooks
|
||||
.AsParallel()
|
||||
.Where(lb => lb.Book.Supplements.Any())
|
||||
.Select(lb => AudibleFileStorage.PDF.Exists(lb.Book.AudibleProductId))
|
||||
.Select(lb => TransitionalFileLocator.PDF_Exists(lb.Book.AudibleProductId))
|
||||
.ToList();
|
||||
var pdfsDownloaded = boolResults.Count(r => r);
|
||||
var pdfsNotDownloaded = boolResults.Count(r => !r);
|
||||
|
|
|
|||
49
ApplicationServices/TransitionalFileLocator.cs
Normal file
49
ApplicationServices/TransitionalFileLocator.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DataLayer;
|
||||
using FileManager;
|
||||
|
||||
namespace ApplicationServices
|
||||
{
|
||||
public static class TransitionalFileLocator
|
||||
{
|
||||
public static string Audio_GetPath(string productId)
|
||||
{
|
||||
var book = DbContexts.GetContext().GetBook_Flat_NoTracking(productId);
|
||||
var loc = book?.UserDefinedItem?.BookLocation ?? "";
|
||||
if (File.Exists(loc))
|
||||
return loc;
|
||||
|
||||
return AudibleFileStorage.Audio.GetPath(productId);
|
||||
}
|
||||
|
||||
public static bool PDF_Exists(string productId)
|
||||
{
|
||||
var book = DbContexts.GetContext().GetBook_Flat_NoTracking(productId);
|
||||
var status = book?.UserDefinedItem?.PdfStatus;
|
||||
if (status.HasValue && status.Value == LiberatedStatus.Liberated)
|
||||
return true;
|
||||
|
||||
return AudibleFileStorage.PDF.Exists(productId);
|
||||
}
|
||||
|
||||
public static bool Audio_Exists(string productId)
|
||||
{
|
||||
var book = DbContexts.GetContext().GetBook_Flat_NoTracking(productId);
|
||||
var status = book?.UserDefinedItem?.BookStatus;
|
||||
// true since Error == libhack
|
||||
if (status != LiberatedStatus.NotLiberated)
|
||||
return true;
|
||||
|
||||
return AudibleFileStorage.Audio.Exists(productId);
|
||||
}
|
||||
|
||||
public static bool AAXC_Exists(string productId)
|
||||
{
|
||||
// this one will actually stay the same. centralizing helps with organization in the interim though
|
||||
return AudibleFileStorage.AAXC.Exists(productId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue