From c8993db2ad784ef587dc6c55fbf8b4f49c535119 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 2 Jan 2015 10:57:51 -0800 Subject: [PATCH] Fix: Remove invalid metadata images --- .../Http/HttpClientFixture.cs | 15 ++ src/NzbDrone.Core.Test/Files/emptyfile.txt | 1 + src/NzbDrone.Core.Test/Files/html_image.jpg | 25 +++ .../Checks/DeleteBadMediaCovers.cs | 166 ++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 7 + .../Configuration/ConfigService.cs | 7 + .../Configuration/IConfigService.cs | 5 + .../CleanupAdditionalNamingSpecs.cs | 9 +- .../CleanupDuplicateMetadataFiles.cs | 9 +- .../Housekeepers/CleanupOrphanedBlacklist.cs | 9 +- .../CleanupOrphanedEpisodeFiles.cs | 6 +- .../Housekeepers/CleanupOrphanedEpisodes.cs | 6 +- .../CleanupOrphanedHistoryItems.cs | 8 +- .../CleanupOrphanedMetadataFiles.cs | 9 +- .../CleanupOrphanedPendingReleases.cs | 9 +- .../Housekeepers/DeleteBadMediaCovers.cs | 83 +++++++++ .../FixFutureRunScheduledTasks.cs | 2 - .../Housekeepers/UpdateAnimeCategories.cs | 63 ------- .../Housekeepers/UpdateCleanTitleForSeries.cs | 7 +- .../Housekeeping/HousekeepingService.cs | 16 +- src/NzbDrone.Core/NzbDrone.Core.csproj | 2 +- 21 files changed, 332 insertions(+), 132 deletions(-) create mode 100644 src/NzbDrone.Core.Test/Files/emptyfile.txt create mode 100644 src/NzbDrone.Core.Test/Files/html_image.jpg create mode 100644 src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs create mode 100644 src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs delete mode 100644 src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateAnimeCategories.cs diff --git a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs index e4e03c734..8673dae16 100644 --- a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs +++ b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; using FluentAssertions; using NUnit.Framework; @@ -96,6 +97,20 @@ namespace NzbDrone.Common.Test.Http response.Resource.Headers[header].ToString().Should().Be(value); } + + + [Test] + public void should_not_download_file_with_error() + { + var file = GetTempFilePath(); + + Assert.Throws(() => Subject.DownloadFile("http://download.sonarr.tv/wrongpath", file)); + + File.Exists(file).Should().BeFalse(); + + ExceptionVerification.ExpectedWarns(1); + + } } public class HttpBinResource diff --git a/src/NzbDrone.Core.Test/Files/emptyfile.txt b/src/NzbDrone.Core.Test/Files/emptyfile.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/src/NzbDrone.Core.Test/Files/emptyfile.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/Files/html_image.jpg b/src/NzbDrone.Core.Test/Files/html_image.jpg new file mode 100644 index 000000000..233f30e13 --- /dev/null +++ b/src/NzbDrone.Core.Test/Files/html_image.jpg @@ -0,0 +1,25 @@ + + +

Directory browsing not allowed

+ + + + diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs new file mode 100644 index 000000000..368101286 --- /dev/null +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using FizzWare.NBuilder; +using Moq; +using NUnit.Framework; +using NzbDrone.Common.Disk; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Housekeeping.Housekeepers; +using NzbDrone.Core.Metadata; +using NzbDrone.Core.Metadata.Files; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.HealthCheck.Checks +{ + [TestFixture] + public class DeleteBadMediaCoversFixture : CoreTest + { + private List _metaData; + private List _series; + + [SetUp] + public void Setup() + { + _series = Builder.CreateListOfSize(1) + .All() + .With(c => c.Path = "C:\\TV\\".AsOsAgnostic()) + .Build().ToList(); + + + _metaData = Builder.CreateListOfSize(1) + .Build().ToList(); + + Mocker.GetMock() + .Setup(c => c.GetAllSeries()) + .Returns(_series); + + + Mocker.GetMock() + .Setup(c => c.GetFilesBySeries(_series.First().Id)) + .Returns(_metaData); + + + Mocker.GetMock().SetupGet(c => c.CleanupMetadataImages).Returns(true); + } + + + [Test] + public void should_not_process_non_image_files() + { + _metaData.First().RelativePath = "season\\file.xml".AsOsAgnostic(); + _metaData.First().Type = MetadataType.EpisodeMetadata; + + Subject.Clean(); + + Mocker.GetMock().Verify(c => c.StreamFile(It.IsAny()), Times.Never()); + + } + + [Test] + public void should_not_process_images_before_tvdb_switch() + { + _metaData.First().LastUpdated = new DateTime(2014, 12, 25); + + Subject.Clean(); + + Mocker.GetMock().Verify(c => c.StreamFile(It.IsAny()), Times.Never()); + } + + + + [Test] + public void should_not_run_if_flag_is_false() + { + Mocker.GetMock().SetupGet(c => c.CleanupMetadataImages).Returns(false); + + Subject.Clean(); + + Mocker.GetMock().VerifySet(c => c.CleanupMetadataImages = true, Times.Never()); + Mocker.GetMock().Verify(c => c.GetAllSeries(), Times.Never()); + + AssertImageWasNotRemoved(); + } + + + [Test] + public void should_set_clean_flag_to_false() + { + _metaData.First().LastUpdated = new DateTime(2014, 12, 25); + + Subject.Clean(); + + Mocker.GetMock().VerifySet(c => c.CleanupMetadataImages = false, Times.Once()); + } + + + [Test] + public void should_delete_html_images() + { + + var imagePath = "C:\\TV\\Season\\image.jpg".AsOsAgnostic(); + _metaData.First().LastUpdated = new DateTime(2014, 12, 29); + _metaData.First().RelativePath = "Season\\image.jpg".AsOsAgnostic(); + _metaData.First().Type = MetadataType.SeriesImage; + + Mocker.GetMock() + .Setup(c => c.StreamFile(imagePath)) + .Returns(new FileStream("Files\\html_image.jpg".AsOsAgnostic(), FileMode.Open, FileAccess.Read)); + + + Subject.Clean(); + + + Mocker.GetMock().Verify(c => c.DeleteFile(imagePath), Times.Once()); + Mocker.GetMock().Verify(c => c.Delete(_metaData.First().Id), Times.Once()); + } + + + [Test] + public void should_delete_empty_images() + { + + var imagePath = "C:\\TV\\Season\\image.jpg".AsOsAgnostic(); + _metaData.First().LastUpdated = new DateTime(2014, 12, 29); + _metaData.First().Type = MetadataType.SeasonImage; + _metaData.First().RelativePath = "Season\\image.jpg".AsOsAgnostic(); + + Mocker.GetMock() + .Setup(c => c.StreamFile(imagePath)) + .Returns(new FileStream("Files\\emptyfile.txt".AsOsAgnostic(), FileMode.Open, FileAccess.Read)); + + + Subject.Clean(); + + Mocker.GetMock().Verify(c => c.DeleteFile(imagePath), Times.Once()); + Mocker.GetMock().Verify(c => c.Delete(_metaData.First().Id), Times.Once()); + } + + + [Test] + public void should_not_delete_non_html_files() + { + + var imagePath = "C:\\TV\\Season\\image.jpg".AsOsAgnostic(); + _metaData.First().LastUpdated = new DateTime(2014, 12, 29); + _metaData.First().RelativePath = "Season\\image.jpg".AsOsAgnostic(); + + Mocker.GetMock() + .Setup(c => c.StreamFile(imagePath)) + .Returns(new FileStream("Files\\Queue.txt".AsOsAgnostic(), FileMode.Open, FileAccess.Read)); + + + Subject.Clean(); + AssertImageWasNotRemoved(); + } + + private void AssertImageWasNotRemoved() + { + Mocker.GetMock().Verify(c => c.DeleteFile(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 030a66613..39e5ac214 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -165,6 +165,7 @@ + @@ -352,6 +353,12 @@ Always + + PreserveNewest + + + Always + Always diff --git a/src/NzbDrone.Core/Configuration/ConfigService.cs b/src/NzbDrone.Core/Configuration/ConfigService.cs index 6d8b7d257..1b715aec3 100644 --- a/src/NzbDrone.Core/Configuration/ConfigService.cs +++ b/src/NzbDrone.Core/Configuration/ConfigService.cs @@ -282,6 +282,13 @@ namespace NzbDrone.Core.Configuration set { SetValue("ShowRelativeDates", value); } } + public bool CleanupMetadataImages + { + get { return GetValueBoolean("CleanupMetadataImages", true); } + + set { SetValue("CleanupMetadataImages", value); } + } + private string GetValue(string key) { return GetValue(key, String.Empty); diff --git a/src/NzbDrone.Core/Configuration/IConfigService.cs b/src/NzbDrone.Core/Configuration/IConfigService.cs index 53927c0b7..c84805647 100644 --- a/src/NzbDrone.Core/Configuration/IConfigService.cs +++ b/src/NzbDrone.Core/Configuration/IConfigService.cs @@ -55,5 +55,10 @@ namespace NzbDrone.Core.Configuration String LongDateFormat { get; set; } String TimeFormat { get; set; } Boolean ShowRelativeDates { get; set; } + + + + //Internal + Boolean CleanupMetadataImages { get; set; } } } diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalNamingSpecs.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalNamingSpecs.cs index f11d30ef8..06ac1423e 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalNamingSpecs.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalNamingSpecs.cs @@ -1,23 +1,18 @@ -using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers { public class CleanupAdditionalNamingSpecs : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupAdditionalNamingSpecs(IDatabase database, Logger logger) + public CleanupAdditionalNamingSpecs(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running naming spec cleanup"); - var mapper = _database.GetDataMapper(); mapper.ExecuteNonQuery(@"DELETE FROM NamingConfig diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs index 1b720b9e9..5d6f3be79 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs @@ -1,23 +1,18 @@ -using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers { public class CleanupDuplicateMetadataFiles : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupDuplicateMetadataFiles(IDatabase database, Logger logger) + public CleanupDuplicateMetadataFiles(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running cleanup of duplicate metadata files"); - DeleteDuplicateSeriesMetadata(); DeleteDuplicateEpisodeMetadata(); DeleteDuplicateEpisodeImages(); diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedBlacklist.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedBlacklist.cs index 83c3e3d82..fabbe5b78 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedBlacklist.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedBlacklist.cs @@ -1,23 +1,18 @@ -using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers { public class CleanupOrphanedBlacklist : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupOrphanedBlacklist(IDatabase database, Logger logger) + public CleanupOrphanedBlacklist(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running orphaned blacklist cleanup"); - var mapper = _database.GetDataMapper(); mapper.ExecuteNonQuery(@"DELETE FROM Blacklist diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs index 3a6b661f5..3349322a3 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs @@ -6,18 +6,14 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers public class CleanupOrphanedEpisodeFiles : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupOrphanedEpisodeFiles(IDatabase database, Logger logger) + public CleanupOrphanedEpisodeFiles(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running orphaned episode files cleanup"); - var mapper = _database.GetDataMapper(); mapper.ExecuteNonQuery(@"DELETE FROM EpisodeFiles diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs index 2c2792f04..66c4b9067 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs @@ -6,18 +6,14 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers public class CleanupOrphanedEpisodes : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupOrphanedEpisodes(IDatabase database, Logger logger) + public CleanupOrphanedEpisodes(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running orphaned episodes cleanup"); - var mapper = _database.GetDataMapper(); mapper.ExecuteNonQuery(@"DELETE FROM Episodes diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs index 0b8e9d374..d577ee92f 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs @@ -1,22 +1,18 @@ -using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers { public class CleanupOrphanedHistoryItems : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupOrphanedHistoryItems(IDatabase database, Logger logger) + public CleanupOrphanedHistoryItems(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running orphaned history cleanup"); CleanupOrphanedBySeries(); CleanupOrphanedByEpisode(); } diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs index e889b3214..c36a91303 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs @@ -1,23 +1,18 @@ -using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers { public class CleanupOrphanedMetadataFiles : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupOrphanedMetadataFiles(IDatabase database, Logger logger) + public CleanupOrphanedMetadataFiles(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running orphaned episode files cleanup"); - DeleteOrphanedBySeries(); DeleteOrphanedByEpisodeFile(); DeleteWhereEpisodeFileIsZero(); diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedPendingReleases.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedPendingReleases.cs index 83a5e9fd0..12d41e05d 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedPendingReleases.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedPendingReleases.cs @@ -1,23 +1,18 @@ -using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers { public class CleanupOrphanedPendingReleases : IHousekeepingTask { private readonly IDatabase _database; - private readonly Logger _logger; - public CleanupOrphanedPendingReleases(IDatabase database, Logger logger) + public CleanupOrphanedPendingReleases(IDatabase database) { _database = database; - _logger = logger; } public void Clean() { - _logger.Debug("Running orphaned pending releases cleanup"); - var mapper = _database.GetDataMapper(); mapper.ExecuteNonQuery(@"DELETE FROM PendingReleases diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs new file mode 100644 index 000000000..beac8cca2 --- /dev/null +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs @@ -0,0 +1,83 @@ +using System; +using System.IO; +using System.Linq; +using NLog; +using NzbDrone.Common.Disk; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Metadata.Files; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Housekeeping.Housekeepers +{ + public class DeleteBadMediaCovers : IHousekeepingTask + { + private readonly ISeriesService _seriesService; + private readonly IMetadataFileService _metadataFileService; + private readonly IDiskProvider _diskProvider; + private readonly IConfigService _configService; + private readonly Logger _logger; + + public DeleteBadMediaCovers(ISeriesService seriesService, IMetadataFileService metadataFileService, IDiskProvider diskProvider, IConfigService configService, Logger logger) + { + _seriesService = seriesService; + _metadataFileService = metadataFileService; + _diskProvider = diskProvider; + _configService = configService; + _logger = logger; + } + + public void Clean() + { + if (!_configService.CleanupMetadataImages) return; + + var series = _seriesService.GetAllSeries(); + + foreach (var show in series) + { + var images = _metadataFileService.GetFilesBySeries(show.Id) + .Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && c.RelativePath.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase)); + + foreach (var image in images) + { + try + { + var path = Path.Combine(show.Path, image.RelativePath); + if (!IsValid(path)) + { + _logger.Debug("Deleting invalid image file " + path); + DeleteMetadata(image.Id, path); + } + } + catch (Exception e) + { + _logger.ErrorException("Couldn't validate image " + image.RelativePath, e); + } + } + } + + + _configService.CleanupMetadataImages = false; + } + + private void DeleteMetadata(int id, string path) + { + _metadataFileService.Delete(id); + _diskProvider.DeleteFile(path); + } + + private bool IsValid(string path) + { + var buffer = new byte[10]; + + using (var imageStream = _diskProvider.StreamFile(path)) + { + if (imageStream.Length < buffer.Length) return false; + imageStream.Read(buffer, 0, buffer.Length); + } + + var text = System.Text.Encoding.Default.GetString(buffer); + + return !text.ToLowerInvariant().Contains("html"); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/FixFutureRunScheduledTasks.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/FixFutureRunScheduledTasks.cs index 41d47498e..40090891a 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/FixFutureRunScheduledTasks.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/FixFutureRunScheduledTasks.cs @@ -23,8 +23,6 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers _logger.Debug("Not running scheduled task last execution cleanup during debug"); } - _logger.Debug("Running scheduled task last execution cleanup"); - var mapper = _database.GetDataMapper(); mapper.AddParameter("time", DateTime.UtcNow); diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateAnimeCategories.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateAnimeCategories.cs deleted file mode 100644 index 33f4a772a..000000000 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateAnimeCategories.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Common.Extensions; -using NzbDrone.Core.Indexers; -using NzbDrone.Core.Indexers.Newznab; - -namespace NzbDrone.Core.Housekeeping.Housekeepers -{ - public class UpdateAnimeCategories : IHousekeepingTask - { - private readonly IIndexerFactory _indexerFactory; - private readonly Logger _logger; - - private const int NZBS_ORG_ANIME_ID = 7040; - private const int NEWZNAB_ANIME_ID = 5070; - - public UpdateAnimeCategories(IIndexerFactory indexerFactory, Logger logger) - { - _indexerFactory = indexerFactory; - _logger = logger; - } - - public void Clean() - { - //TODO: We should remove this before merging it into develop - _logger.Debug("Updating Anime Categories for newznab indexers"); - - var indexers = _indexerFactory.All().Where(i => i.Implementation == typeof (Newznab).Name); - - foreach (var indexer in indexers) - { - var settings = indexer.Settings as NewznabSettings; - - if (settings.Url.ContainsIgnoreCase("nzbs.org") && settings.Categories.Contains(NZBS_ORG_ANIME_ID)) - { - var animeCategories = new List(settings.AnimeCategories); - animeCategories.Add(NZBS_ORG_ANIME_ID); - - settings.AnimeCategories = animeCategories; - - settings.Categories = settings.Categories.Where(c => c != NZBS_ORG_ANIME_ID); - - indexer.Settings = settings; - _indexerFactory.Update(indexer); - } - - else if (settings.Categories.Contains(NEWZNAB_ANIME_ID)) - { - var animeCategories = new List(settings.AnimeCategories); - animeCategories.Add(NEWZNAB_ANIME_ID); - - settings.AnimeCategories = animeCategories; - - settings.Categories = settings.Categories.Where(c => c != NEWZNAB_ANIME_ID); - - indexer.Settings = settings; - _indexerFactory.Update(indexer); - } - } - } - } -} diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs index 4242b56ac..16b19c505 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs @@ -1,5 +1,4 @@ using System.Linq; -using NLog; using NzbDrone.Core.Parser; using NzbDrone.Core.Tv; @@ -8,18 +7,14 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers public class UpdateCleanTitleForSeries : IHousekeepingTask { private readonly ISeriesRepository _seriesRepository; - private readonly Logger _logger; - public UpdateCleanTitleForSeries(ISeriesRepository seriesRepository, Logger logger) + public UpdateCleanTitleForSeries(ISeriesRepository seriesRepository) { _seriesRepository = seriesRepository; - _logger = logger; } public void Clean() { - _logger.Debug("Updating CleanTitle for all series"); - var series = _seriesRepository.All().ToList(); series.ForEach(s => diff --git a/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs b/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs index a059aa8f6..b5cd465d3 100644 --- a/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs +++ b/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using NLog; -using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; @@ -30,21 +29,20 @@ namespace NzbDrone.Core.Housekeeping { try { + _logger.Debug("Starting {0}", housekeeper.GetType().Name); housekeeper.Clean(); + _logger.Debug("Completed {0}", housekeeper.GetType().Name); + } catch (Exception ex) { - _logger.ErrorException("Error running housekeeping task: " + housekeeper.GetType().FullName, ex); + _logger.ErrorException("Error running housekeeping task: " + housekeeper.GetType().Name, ex); } } - //Only Vaccuum the DB in production - if (RuntimeInfoBase.IsProduction) - { - // Vacuuming the log db isn't needed since that's done hourly at the TrimLogCommand. - _logger.Debug("Compressing main database after housekeeping"); - _mainDb.Vacuum(); - } + // Vacuuming the log db isn't needed since that's done hourly at the TrimLogCommand. + _logger.Debug("Compressing main database after housekeeping"); + _mainDb.Vacuum(); } public void Execute(HousekeepingCommand message) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 21c9c4d43..5b41ce309 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -415,8 +415,8 @@ + -