mirror of
https://github.com/fergalmoran/Readarr.git
synced 2026-01-05 16:25:05 +00:00
Fixed: Better aggregation of calibre data
This commit is contained in:
@@ -41,17 +41,22 @@ namespace NzbDrone.Core.Books.Calibre
|
||||
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 @@ namespace NzbDrone.Core.Books.Calibre
|
||||
|
||||
if (embed)
|
||||
{
|
||||
_rootFolderWatchingService.ReportFileSystemChangeBeginning(file.Path);
|
||||
EmbedMetadata(file.CalibreId, settings);
|
||||
}
|
||||
}
|
||||
@@ -340,6 +346,8 @@ namespace NzbDrone.Core.Books.Calibre
|
||||
|
||||
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 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Aggregation.Aggregators
|
||||
{
|
||||
_logger = logger;
|
||||
_bookCache = cacheManager.GetCache<CalibreBook>(typeof(CalibreProxy));
|
||||
|
||||
_logger.Trace("Started calibre aug");
|
||||
}
|
||||
|
||||
public LocalBook Aggregate(LocalBook localTrack, bool others)
|
||||
@@ -31,8 +28,10 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Aggregation.Aggregators
|
||||
{
|
||||
_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 @@ namespace NzbDrone.Core.MediaFiles.BookImport
|
||||
var bookFile = new BookFile
|
||||
{
|
||||
Path = localTrack.Path.CleanFilePath(),
|
||||
CalibreId = localTrack.CalibreId,
|
||||
Size = localTrack.Size,
|
||||
Modified = localTrack.Modified,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
@@ -199,12 +200,6 @@ namespace NzbDrone.Core.MediaFiles.BookImport
|
||||
_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 @@ namespace NzbDrone.Core.MediaFiles
|
||||
.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 @@ namespace NzbDrone.Core.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 @@ namespace NzbDrone.Core.Parser
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user