Added the ability to auto-ignore episodes for files that are deleted, good for people that delete after watching. Option is not exposed in the UI and is disabled by default (obviously).

pull/4/head
Mark McDowall 13 years ago
parent 0ecc62a6f7
commit 218059e08d

@ -1590,5 +1590,39 @@ namespace NzbDrone.Core.Test.ProviderTests
result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1);
result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse();
}
[Test]
public void SetPreviouslyDownloadedToIgnored_should_set_only_episodes_with_no_episode_file_and_postdownload_status_noError_to_ignored()
{
WithRealDb();
var postDownloadStatus = PostDownloadStatusType.NoError;
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
.All()
.With(c => c.Ignored = false)
.TheFirst(2)
.With(c => c.PostDownloadStatus = PostDownloadStatusType.NoError)
.With(c => c.EpisodeFileId = 0)
.TheNext(3)
.With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown)
.With(c => c.EpisodeFileId = 0)
.TheNext(4)
.With(c => c.PostDownloadStatus = PostDownloadStatusType.NoError)
.TheNext(1)
.With(c => c.PostDownloadStatus = PostDownloadStatusType.NoError)
.With(c => c.Ignored = true)
.Build();
Db.InsertMany(fakeEpisodes);
//Act
Mocker.Resolve<EpisodeProvider>().SetPreviouslyDownloadedToIgnored();
//Assert
var result = Db.Fetch<Episode>();
result.Should().HaveCount(10);
result.Where(e => e.Ignored).Count().Should().Be(3);
}
}
}

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Ninject;
using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Jobs
{
public class AutoIgnoreJob : IJob
{
private readonly ConfigProvider _configProvider;
private readonly EpisodeProvider _episodeProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public AutoIgnoreJob(ConfigProvider configProvider, EpisodeProvider episodeProvider)
{
_configProvider = configProvider;
_episodeProvider = episodeProvider;
}
public AutoIgnoreJob()
{
}
public string Name
{
get { return "Auto Ignore Episodes"; }
}
public TimeSpan DefaultInterval
{
get { return TimeSpan.FromTicks(0); }
}
public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{
if (_configProvider.AutoIgnorePreviouslyDownloadedEpisodes)
{
Logger.Info("Ignoring Previously Downloaded Episodes");
_episodeProvider.SetPreviouslyDownloadedToIgnored();
}
}
}
}

@ -6,6 +6,7 @@ using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Jobs
@ -14,13 +15,16 @@ namespace NzbDrone.Core.Jobs
{
private readonly SeriesProvider _seriesProvider;
private readonly DiskScanProvider _diskScanProvider;
private readonly AutoIgnoreJob _autoIgnoreJob;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public DiskScanJob(SeriesProvider seriesProvider, DiskScanProvider diskScanProvider)
public DiskScanJob(SeriesProvider seriesProvider, DiskScanProvider diskScanProvider,
AutoIgnoreJob autoIgnoreJob)
{
_seriesProvider = seriesProvider;
_diskScanProvider = diskScanProvider;
_autoIgnoreJob = autoIgnoreJob;
}
public DiskScanJob()
@ -62,6 +66,9 @@ namespace NzbDrone.Core.Jobs
Logger.ErrorException("An error has occurred while scanning " + series.Title, e);
}
}
//Start the Auto Ignore Job
_autoIgnoreJob.Start(notification, 0 , 0);
}
}
}

@ -225,6 +225,7 @@
<Compile Include="Instrumentation\DatabaseTarget.cs" />
<Compile Include="Instrumentation\NlogWriter.cs" />
<Compile Include="Datastore\PetaPoco\PetaPoco.cs" />
<Compile Include="Jobs\AutoIgnoreJob.cs" />
<Compile Include="Model\AtomicParsleyTitleType.cs" />
<Compile Include="Model\ConnectionInfoModel.cs" />
<Compile Include="Model\PostDownloadStatusType.cs" />

@ -402,6 +402,12 @@ namespace NzbDrone.Core.Providers.Core
set { SetValue("EnableBacklogSearching", value); }
}
public virtual bool AutoIgnorePreviouslyDownloadedEpisodes
{
get { return GetValueBoolean("AutoIgnorePreviouslyDownloadedEpisodes"); }
set { SetValue("AutoIgnorePreviouslyDownloadedEpisodes", value); }
}
private string GetValue(string key)
{
return GetValue(key, String.Empty);

@ -463,5 +463,13 @@ namespace NzbDrone.Core.Providers
Logger.Trace("Updating PostDownloadStatus for all episodeIds in {0}", episodeIdString);
_database.Execute(episodeIdQuery);
}
/// <summary>
/// Sets Ignored to true if the episode successfully downloaded (PostDownloadStatus = 5), but EpisodeFileId = 0
/// </summary>
public virtual void SetPreviouslyDownloadedToIgnored()
{
_database.Execute("UPDATE Episodes SET Ignored = 1, PostDownloadStatus = 0 WHERE PostDownloadStatus = 5 AND EpisodeFileId = 0");
}
}
}
Loading…
Cancel
Save