From 45d0f4bdb73ae9f52c4ff4549223cb87acb60802 Mon Sep 17 00:00:00 2001 From: Robin Dadswell Date: Thu, 14 Jan 2021 20:25:56 +0000 Subject: [PATCH] fixes to build errors --- src/NzbDrone.Common/Http/HttpRequest.cs | 7 +++++++ .../Blacklisting/BlacklistRepository.cs | 3 ++- .../Books/Repositories/AuthorRepository.cs | 10 ++++++++++ src/NzbDrone.Core/Books/Services/AuthorService.cs | 6 ++++++ .../DecisionEngine/DownloadDecisionMaker.cs | 14 +++++++------- .../Specifications/QueueSpecification.cs | 4 ++-- .../Specifications/RssSync/HistorySpecification.cs | 2 +- .../Specifications/UpgradeAllowedSpecification.cs | 7 ++----- .../Aggregators/AggregatePreferredWordScore.cs | 2 +- src/NzbDrone.Core/Download/DownloadService.cs | 2 +- .../Extras/ExistingExtraFileService.cs | 2 +- src/NzbDrone.Core/History/HistoryRepository.cs | 1 + .../Housekeepers/DeleteBadMediaCovers.cs | 4 ++-- .../Indexers/FileList/FileListRequestGenerator.cs | 13 +++++-------- src/NzbDrone.Core/MediaFiles/DiskScanService.cs | 2 +- .../MediaFiles/MediaFileDeletionService.cs | 4 ++-- src/NzbDrone.Core/Notifications/Prowl/Prowl.cs | 6 +++--- .../Notifications/SendGrid/SendGrid.cs | 8 ++++---- src/NzbDrone.Core/Notifications/Webhook/Webhook.cs | 12 ++++++------ .../Notifications/Webhook/WebhookRenamePayload.cs | 2 +- .../Notifications/Webhook/WebhookRetagPayload.cs | 2 +- .../Profiles/Releases/PreferredWordService.cs | 4 ++-- .../Validation/Paths/AuthorAncestorValidator.cs | 2 +- .../Validation/Paths/AuthorPathValidator.cs | 2 +- 24 files changed, 70 insertions(+), 51 deletions(-) diff --git a/src/NzbDrone.Common/Http/HttpRequest.cs b/src/NzbDrone.Common/Http/HttpRequest.cs index ecb5784af..d6265798b 100644 --- a/src/NzbDrone.Common/Http/HttpRequest.cs +++ b/src/NzbDrone.Common/Http/HttpRequest.cs @@ -82,5 +82,12 @@ public void SetContent(string data) var encoding = HttpHeader.GetEncodingFromContentType(Headers.ContentType); ContentData = encoding.GetBytes(data); } + + public void AddBasicAuthentication(string username, string password) + { + var authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{username}:{password}")); + + Headers.Set("Authorization", "Basic " + authInfo); + } } } diff --git a/src/NzbDrone.Core/Blacklisting/BlacklistRepository.cs b/src/NzbDrone.Core/Blacklisting/BlacklistRepository.cs index 4384ccf00..340765a3f 100644 --- a/src/NzbDrone.Core/Blacklisting/BlacklistRepository.cs +++ b/src/NzbDrone.Core/Blacklisting/BlacklistRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections.Generic; +using NzbDrone.Core.Books; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; diff --git a/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs b/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs index a5acebf2e..69a0ae8f6 100644 --- a/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs +++ b/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs @@ -12,6 +12,7 @@ public interface IAuthorRepository : IBasicRepository bool AuthorPathExists(string path); Author FindByName(string cleanName); Author FindById(string foreignAuthorId); + Dictionary AllAuthorPaths(); Author GetAuthorByMetadataId(int authorMetadataId); List GetAuthorsByMetadataId(IEnumerable authorMetadataId); } @@ -60,6 +61,15 @@ public Author GetAuthorByMetadataId(int authorMetadataId) return Query(s => s.AuthorMetadataId == authorMetadataId).SingleOrDefault(); } + public Dictionary AllAuthorPaths() + { + using (var conn = _database.OpenConnection()) + { + var strSql = "SELECT Id AS [Key], Path AS [Value] FROM Authors"; + return conn.Query>(strSql).ToDictionary(x => x.Key, x => x.Value); + } + } + public List GetAuthorsByMetadataId(IEnumerable authorMetadataIds) { return Query(s => authorMetadataIds.Contains(s.AuthorMetadataId)); diff --git a/src/NzbDrone.Core/Books/Services/AuthorService.cs b/src/NzbDrone.Core/Books/Services/AuthorService.cs index 1509351bf..38b7193a0 100644 --- a/src/NzbDrone.Core/Books/Services/AuthorService.cs +++ b/src/NzbDrone.Core/Books/Services/AuthorService.cs @@ -27,6 +27,7 @@ public interface IAuthorService List AllForTag(int tagId); Author UpdateAuthor(Author author); List UpdateAuthors(List authors, bool useExistingRelativeFolder); + Dictionary AllAuthorPaths(); bool AuthorPathExists(string folder); void RemoveAddOptions(Author author); } @@ -131,6 +132,11 @@ public Author FindByNameInexact(string title) return null; } + public Dictionary AllAuthorPaths() + { + return _authorRepository.AllAuthorPaths(); + } + public List GetCandidates(string title) { var authors = GetAllAuthors(); diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index f1a7da30f..11fef7832 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -156,23 +156,23 @@ private IEnumerable GetBookDecisions(List reports if (searchCriteria != null) { - if (parsedAlbumInfo == null) + if (parsedBookInfo == null) { - parsedAlbumInfo = new ParsedAlbumInfo + parsedBookInfo = new ParsedBookInfo { - Quality = QualityParser.ParseQuality(report.Title, null, 0) + Quality = QualityParser.ParseQuality(report.Title, null) }; } - if (parsedAlbumInfo.ArtistName.IsNullOrWhiteSpace()) + if (parsedBookInfo.AuthorName.IsNullOrWhiteSpace()) { - var remoteAlbum = new RemoteAlbum + var remoteBook = new RemoteBook { Release = report, - ParsedAlbumInfo = parsedAlbumInfo + ParsedBookInfo = parsedBookInfo }; - decision = new DownloadDecision(remoteAlbum, new Rejection("Unable to parse release")); + decision = new DownloadDecision(remoteBook, new Rejection("Unable to parse release")); } } } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/QueueSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/QueueSpecification.cs index b1a53db2d..0b6a6de10 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/QueueSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/QueueSpecification.cs @@ -68,7 +68,7 @@ public Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCrite _logger.Debug("Checking if release is higher quality than queued release. Queued: {0}", remoteBook.ParsedBookInfo.Quality); if (!_upgradableSpecification.IsUpgradable(qualityProfile, - new List { remoteBook.ParsedBookInfo.Quality }, + remoteBook.ParsedBookInfo.Quality, queuedItemPreferredWordScore, subject.ParsedBookInfo.Quality, subject.PreferredWordScore)) @@ -79,7 +79,7 @@ public Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCrite _logger.Debug("Checking if profiles allow upgrading. Queued: {0}", remoteBook.ParsedBookInfo.Quality); if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile, - new List { remoteBook.ParsedBookInfo.Quality }, + remoteBook.ParsedBookInfo.Quality, subject.ParsedBookInfo.Quality)) { return Decision.Reject("Another release is queued and the Quality profile does not allow upgrades"); diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs index 7b700696a..123599916 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs @@ -73,7 +73,7 @@ public virtual Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase sea var upgradeable = _upgradableSpecification.IsUpgradable( subject.Author.QualityProfile, - new List { mostRecent.Quality }, + mostRecent.Quality, preferredWordScore, subject.ParsedBookInfo.Quality, subject.PreferredWordScore); diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradeAllowedSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradeAllowedSpecification.cs index 42ce9c70c..1d6828697 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradeAllowedSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradeAllowedSpecification.cs @@ -35,13 +35,10 @@ public virtual Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase sea continue; } - // Get a distinct list of all current track qualities for a given book - var currentQualities = new List { file.Quality }; - - _logger.Debug("Comparing file quality with report. Existing files contain {0}", currentQualities.ConcatToString()); + _logger.Debug("Comparing file quality with report. Existing files contain {0}", file.Quality); if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile, - currentQualities, + file.Quality, subject.ParsedBookInfo.Quality)) { _logger.Debug("Upgrading is not allowed by the quality profile"); diff --git a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregatePreferredWordScore.cs b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregatePreferredWordScore.cs index 92c09f7b8..3ae007811 100644 --- a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregatePreferredWordScore.cs +++ b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregatePreferredWordScore.cs @@ -14,7 +14,7 @@ public AggregatePreferredWordScore(IPreferredWordService preferredWordServiceCal public RemoteBook Aggregate(RemoteBook remoteBook) { - remoteBook.PreferredWordScore = _preferredWordServiceCalculator.Calculate(remoteAlbum.Author, remoteBook.Release.Title, remoteBook.Release.IndexerId); + remoteBook.PreferredWordScore = _preferredWordServiceCalculator.Calculate(remoteBook.Author, remoteBook.Release.Title, remoteBook.Release.IndexerId); return remoteBook; } diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index 6abc6a91f..6e900dfb9 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -82,7 +82,7 @@ public void DownloadReport(RemoteBook remoteBook) } catch (DownloadClientRejectedReleaseException) { - _logger.Trace("Release {0} rejected by download client, possible duplicate.", remoteAlbum); + _logger.Trace("Release {0} rejected by download client, possible duplicate.", remoteBook); throw; } catch (ReleaseDownloadException ex) diff --git a/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs b/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs index 8602bb4f6..653edc554 100644 --- a/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs @@ -41,7 +41,7 @@ public void Handle(AuthorScannedEvent message) _logger.Debug("Looking for existing extra files in {0}", author.Path); var filesOnDisk = _diskScanService.GetNonBookFiles(author.Path); - var possibleExtraFiles = _diskScanService.FilterFiles(author.Path, filesOnDisk); + var possibleExtraFiles = _diskScanService.FilterPaths(author.Path, filesOnDisk); var filteredFiles = possibleExtraFiles; var importedFiles = new List(); diff --git a/src/NzbDrone.Core/History/HistoryRepository.cs b/src/NzbDrone.Core/History/HistoryRepository.cs index 0c7ae7be7..61cddb484 100644 --- a/src/NzbDrone.Core/History/HistoryRepository.cs +++ b/src/NzbDrone.Core/History/HistoryRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NzbDrone.Core.Books; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Qualities; diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs index 828afd07a..96c8ca906 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs @@ -38,10 +38,10 @@ public void Clean() return; } - var artists = _authorService.GetAllAuthors(); + var authors = _authorService.AllAuthorPaths(); var imageExtensions = new List { ".jpg", ".png", ".gif" }; - foreach (var author in artists) + foreach (var author in authors) { var images = _metaFileService.GetFilesByAuthor(author.Key) .Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && imageExtensions.Any(x => c.RelativePath.EndsWith(x, StringComparison.InvariantCultureIgnoreCase))); diff --git a/src/NzbDrone.Core/Indexers/FileList/FileListRequestGenerator.cs b/src/NzbDrone.Core/Indexers/FileList/FileListRequestGenerator.cs index ce140bb37..1d41733d3 100644 --- a/src/NzbDrone.Core/Indexers/FileList/FileListRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/FileList/FileListRequestGenerator.cs @@ -19,20 +19,20 @@ public virtual IndexerPageableRequestChain GetRecentRequests() return pageableRequests; } - public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria) + public IndexerPageableRequestChain GetSearchRequests(BookSearchCriteria searchCriteria) { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetRequest("search-torrents", Settings.Categories, string.Format(" & type=name&query={0}+{1}", Uri.EscapeDataString(searchCriteria.ArtistQuery.Trim()), Uri.EscapeDataString(searchCriteria.AlbumQuery.Trim())))); + pageableRequests.Add(GetRequest("search-torrents", Settings.Categories, string.Format(" & type=name&query={0}+{1}", Uri.EscapeDataString(searchCriteria.AuthorQuery.Trim()), Uri.EscapeDataString(searchCriteria.BookQuery.Trim())))); return pageableRequests; } - public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria) + public IndexerPageableRequestChain GetSearchRequests(AuthorSearchCriteria searchCriteria) { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetRequest("search-torrents", Settings.Categories, string.Format(" & type=name&query={0}", Uri.EscapeDataString(searchCriteria.ArtistQuery.Trim())))); + pageableRequests.Add(GetRequest("search-torrents", Settings.Categories, string.Format(" & type=name&query={0}", Uri.EscapeDataString(searchCriteria.AuthorQuery.Trim())))); return pageableRequests; } @@ -43,10 +43,7 @@ private IEnumerable GetRequest(string searchType, IEnumerable new WebhookBook(x) + Author = new WebhookAuthor(message.Author), + Books = remoteBook.Books.ConvertAll(x => new WebhookBook(x) { // TODO: Stop passing these parameters inside an album v3 Quality = quality.Quality.Name, @@ -49,7 +49,7 @@ public override void OnReleaseImport(BookDownloadMessage message) var payload = new WebhookImportPayload { EventType = WebhookEventType.Download, - Artist = new WebhookAuthor(message.Author), + Author = new WebhookAuthor(message.Author), Book = new WebhookBook(message.Book), BookFiles = bookFiles.ConvertAll(x => new WebhookBookFile(x)), IsUpgrade = message.OldFiles.Any(), @@ -65,7 +65,7 @@ public override void OnRename(Author author) var payload = new WebhookRenamePayload { EventType = WebhookEventType.Rename, - Artist = new WebhookAuthor(author) + Author = new WebhookAuthor(author) }; _proxy.SendWebhook(payload, Settings); @@ -76,7 +76,7 @@ public override void OnBookRetag(BookRetagMessage message) var payload = new WebhookRetagPayload { EventType = WebhookEventType.Retag, - Artist = new WebhookAuthor(message.Author) + Author = new WebhookAuthor(message.Author) }; _proxy.SendWebhook(payload, Settings); @@ -114,7 +114,7 @@ private ValidationFailure SendWebhookTest() var payload = new WebhookGrabPayload { EventType = WebhookEventType.Test, - Artist = new WebhookAuthor() + Author = new WebhookAuthor() { Id = 1, Name = "Test Name", diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs index 94e4e5cc3..bb9a3e56b 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs @@ -2,6 +2,6 @@ namespace NzbDrone.Core.Notifications.Webhook { public class WebhookRenamePayload : WebhookPayload { - public WebhookArtist Artist { get; set; } + public WebhookAuthor Author { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs index b969060da..67e3ec729 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs @@ -2,6 +2,6 @@ namespace NzbDrone.Core.Notifications.Webhook { public class WebhookRetagPayload : WebhookPayload { - public WebhookArtist Artist { get; set; } + public WebhookAuthor Author { get; set; } } } diff --git a/src/NzbDrone.Core/Profiles/Releases/PreferredWordService.cs b/src/NzbDrone.Core/Profiles/Releases/PreferredWordService.cs index 86f9a525b..85070073a 100644 --- a/src/NzbDrone.Core/Profiles/Releases/PreferredWordService.cs +++ b/src/NzbDrone.Core/Profiles/Releases/PreferredWordService.cs @@ -25,11 +25,11 @@ public PreferredWordService(IReleaseProfileService releaseProfileService, ITermM _logger = logger; } - public int Calculate(Author series, string title, int indexerId) + public int Calculate(Author author, string title, int indexerId) { _logger.Trace("Calculating preferred word score for '{0}'", title); - var releaseProfiles = _releaseProfileService.EnabledForTags(artist.Tags, indexerId); + var releaseProfiles = _releaseProfileService.EnabledForTags(author.Tags, indexerId); var matchingPairs = new List>(); foreach (var releaseProfile in releaseProfiles) diff --git a/src/NzbDrone.Core/Validation/Paths/AuthorAncestorValidator.cs b/src/NzbDrone.Core/Validation/Paths/AuthorAncestorValidator.cs index 520f7bdc9..faac7a529 100644 --- a/src/NzbDrone.Core/Validation/Paths/AuthorAncestorValidator.cs +++ b/src/NzbDrone.Core/Validation/Paths/AuthorAncestorValidator.cs @@ -22,7 +22,7 @@ protected override bool IsValid(PropertyValidatorContext context) return true; } - return !_artistService.GetAllAuthors().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value)); + return !_authorService.GetAllAuthors().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value)); } } } diff --git a/src/NzbDrone.Core/Validation/Paths/AuthorPathValidator.cs b/src/NzbDrone.Core/Validation/Paths/AuthorPathValidator.cs index 906e77c67..1105afecb 100644 --- a/src/NzbDrone.Core/Validation/Paths/AuthorPathValidator.cs +++ b/src/NzbDrone.Core/Validation/Paths/AuthorPathValidator.cs @@ -25,7 +25,7 @@ protected override bool IsValid(PropertyValidatorContext context) dynamic instance = context.ParentContext.InstanceToValidate; var instanceId = (int)instance.Id; - return !_authorService.GetAllAuthors().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId); + return !_authorService.AllAuthorPaths().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId); } } }