diff --git a/src/NzbDrone.Core/Books/Calibre/CalibreProxy.cs b/src/NzbDrone.Core/Books/Calibre/CalibreProxy.cs index 79bc317a0..25bb773f2 100644 --- a/src/NzbDrone.Core/Books/Calibre/CalibreProxy.cs +++ b/src/NzbDrone.Core/Books/Calibre/CalibreProxy.cs @@ -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 _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(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) diff --git a/src/NzbDrone.Core/MediaFiles/BookImport/Aggregation/Aggregators/AggregateCalibreData.cs b/src/NzbDrone.Core/MediaFiles/BookImport/Aggregation/Aggregators/AggregateCalibreData.cs index 547a416f3..e7cae7325 100644 --- a/src/NzbDrone.Core/MediaFiles/BookImport/Aggregation/Aggregators/AggregateCalibreData.cs +++ b/src/NzbDrone.Core/MediaFiles/BookImport/Aggregation/Aggregators/AggregateCalibreData.cs @@ -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(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; diff --git a/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs b/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs index 2b782ca4e..a8dd76e97 100644 --- a/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs +++ b/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs @@ -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); } diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index a56dd05a2..670631f85 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -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, diff --git a/src/NzbDrone.Core/Parser/Model/LocalBook.cs b/src/NzbDrone.Core/Parser/Model/LocalBook.cs index 7d5d92ed1..0f9133b85 100644 --- a/src/NzbDrone.Core/Parser/Model/LocalBook.cs +++ b/src/NzbDrone.Core/Parser/Model/LocalBook.cs @@ -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; } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 36066636d..9f9892f1c 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -227,8 +227,6 @@ namespace NzbDrone.Core.Parser private static readonly Regex AfterDashRegex = new Regex(@"[-:].*", RegexOptions.Compiled); - private static readonly Regex CalibreIdRegex = new Regex(@"\((?\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