mirror of
https://github.com/Readarr/Readarr
synced 2026-01-02 13:48:47 +01:00
Fixed: Better aggregation of calibre data
This commit is contained in:
parent
f584d2d8d2
commit
8ec13f5ead
6 changed files with 14 additions and 22 deletions
|
|
@ -41,17 +41,22 @@ public class CalibreProxy : ICalibreProxy
|
|||
private readonly IHttpClient _httpClient;
|
||||
private readonly IMapCoversToLocal _mediaCoverService;
|
||||
private readonly IRemotePathMappingService _pathMapper;
|
||||
private readonly IRootFolderWatchingService _rootFolderWatchingService;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<CalibreBook> _bookCache;
|
||||
|
||||
public CalibreProxy(IHttpClient httpClient,
|
||||
IMapCoversToLocal mediaCoverService,
|
||||
IRemotePathMappingService pathMapper,
|
||||
IRootFolderWatchingService rootFolderWatchingService,
|
||||
ICacheManager cacheManager,
|
||||
Logger logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_mediaCoverService = mediaCoverService;
|
||||
_pathMapper = pathMapper;
|
||||
_rootFolderWatchingService = rootFolderWatchingService;
|
||||
_bookCache = cacheManager.GetCache<CalibreBook>(GetType());
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
@ -196,6 +201,7 @@ public void SetFields(BookFile file, CalibreSettings settings, bool updateCover
|
|||
|
||||
if (embed)
|
||||
{
|
||||
_rootFolderWatchingService.ReportFileSystemChangeBeginning(file.Path);
|
||||
EmbedMetadata(file.CalibreId, settings);
|
||||
}
|
||||
}
|
||||
|
|
@ -340,6 +346,8 @@ public List<string> GetAllBookFilePaths(CalibreSettings settings)
|
|||
|
||||
var localPath = _pathMapper.RemapRemoteToLocal(settings.Host, new OsPath(remotePath)).FullPath;
|
||||
result.Add(localPath);
|
||||
|
||||
_bookCache.Set(localPath, book);
|
||||
}
|
||||
}
|
||||
catch (HttpException ex)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Books.Calibre;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
|
@ -18,8 +17,6 @@ public AggregateCalibreData(Logger logger,
|
|||
{
|
||||
_logger = logger;
|
||||
_bookCache = cacheManager.GetCache<CalibreBook>(typeof(CalibreProxy));
|
||||
|
||||
_logger.Trace("Started calibre aug");
|
||||
}
|
||||
|
||||
public LocalBook Aggregate(LocalBook localTrack, bool others)
|
||||
|
|
@ -31,8 +28,10 @@ public LocalBook Aggregate(LocalBook localTrack, bool others)
|
|||
{
|
||||
_logger.Trace($"Using calibre data for {localTrack.Path}:\n{book.ToJson()}");
|
||||
|
||||
localTrack.CalibreId = book.Id;
|
||||
|
||||
var parsed = localTrack.FileTrackInfo;
|
||||
parsed.Asin = book.Identifiers.GetValueOrDefault("mobi-asin");
|
||||
parsed.Asin = book.Identifiers.GetValueOrDefault("mobi-asin") ?? book.Identifiers.GetValueOrDefault("asin");
|
||||
parsed.Isbn = book.Identifiers.GetValueOrDefault("isbn");
|
||||
parsed.GoodreadsId = book.Identifiers.GetValueOrDefault("goodreads");
|
||||
parsed.AuthorTitle = book.AuthorSort;
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ public List<ImportResult> Import(List<ImportDecision<LocalBook>> decisions, bool
|
|||
var bookFile = new BookFile
|
||||
{
|
||||
Path = localTrack.Path.CleanFilePath(),
|
||||
CalibreId = localTrack.CalibreId,
|
||||
Size = localTrack.Size,
|
||||
Modified = localTrack.Modified,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
|
|
@ -199,12 +200,6 @@ public List<ImportResult> Import(List<ImportDecision<LocalBook>> decisions, bool
|
|||
_mediaFileService.Delete(previousFile, DeleteMediaFileReason.ManualOverride);
|
||||
}
|
||||
|
||||
var rootFolder = _rootFolderService.GetBestRootFolder(localTrack.Path);
|
||||
if (rootFolder.IsCalibreLibrary)
|
||||
{
|
||||
bookFile.CalibreId = bookFile.Path.ParseCalibreId();
|
||||
}
|
||||
|
||||
_audioTagService.WriteTags(bookFile, false);
|
||||
_eBookTagService.WriteTags(bookFile, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ public void Scan(List<string> folders = null, FilterFilesType filter = FilterFil
|
|||
.Select(decision => new BookFile
|
||||
{
|
||||
Path = decision.Item.Path,
|
||||
CalibreId = decision.Item.Path.ParseCalibreId(),
|
||||
CalibreId = decision.Item.CalibreId,
|
||||
Size = decision.Item.Size,
|
||||
Modified = decision.Item.Modified,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace NzbDrone.Core.Parser.Model
|
|||
public class LocalBook
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public int CalibreId { get; set; }
|
||||
public long Size { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
public ParsedTrackInfo FileTrackInfo { get; set; }
|
||||
|
|
|
|||
|
|
@ -227,8 +227,6 @@ public static class Parser
|
|||
|
||||
private static readonly Regex AfterDashRegex = new Regex(@"[-:].*", RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex CalibreIdRegex = new Regex(@"\((?<id>\d+)\)", RegexOptions.Compiled);
|
||||
|
||||
public static ParsedTrackInfo ParseMusicPath(string path)
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
|
|
@ -481,15 +479,6 @@ private static string GetTitleFuzzy(string report, string name, out string remai
|
|||
return null;
|
||||
}
|
||||
|
||||
public static int ParseCalibreId(this string path)
|
||||
{
|
||||
var bookFolder = path.GetParentPath();
|
||||
|
||||
var match = CalibreIdRegex.Match(bookFolder);
|
||||
|
||||
return match.Success ? int.Parse(match.Groups["id"].Value) : 0;
|
||||
}
|
||||
|
||||
public static ParsedBookInfo ParseBookTitle(string title)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in a new issue