mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-12 11:15:43 +02:00
Merge branch 'markus' into kay.one
Conflicts: NzbDrone.Core/Providers/SearchProvider.cs
This commit is contained in:
commit
68942e3c52
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
@ -164,5 +165,31 @@ public void ParentUriString_should_return_parent_url_when_url_with_query_strings
|
||||
//Resolve
|
||||
result.Should().Be("http://www.nzbdrone.com");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaxOrDefault_should_return_zero_when_collection_is_empty()
|
||||
{
|
||||
//Setup
|
||||
|
||||
|
||||
//Act
|
||||
var result = (new List<int>()).MaxOrDefault();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaxOrDefault_should_return_max_when_collection_is_not_empty()
|
||||
{
|
||||
//Setup
|
||||
var list = new List<int> {6, 4, 5, 3, 8, 10};
|
||||
|
||||
//Act
|
||||
var result = list.MaxOrDefault();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
83
NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs
Normal file
83
NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Jobs;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.JobTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RecentBacklogSearchJobTest : CoreTest
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void no_missing_epsiodes_should_not_trigger_any_search()
|
||||
{
|
||||
//Setup
|
||||
var episodes = new List<Episode>();
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, 0, 0);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(MockNotification, It.IsAny<int>(), 0),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_only_process_missing_episodes_from_the_last_30_days()
|
||||
{
|
||||
//Setup
|
||||
var episodes = Builder<Episode>.CreateListOfSize(50)
|
||||
.TheFirst(5)
|
||||
.With(e => e.AirDate = DateTime.Today)
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-1)) //Today
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-5)) //Yeserday
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-10))
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-15))
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-20))
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-25))
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-30))
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-31)) //31 Days
|
||||
.TheNext(5)
|
||||
.With(e => e.AirDate = DateTime.Today.AddDays(-35))
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<EpisodeSearchJob>().Setup(c => c.Start(It.IsAny<ProgressNotification>(), It.IsAny<int>(), 0));
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, 0, 0);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(It.IsAny<ProgressNotification>(), It.IsAny<int>(), 0),
|
||||
Times.Exactly(40));
|
||||
}
|
||||
}
|
||||
}
|
@ -96,6 +96,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
|
||||
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
|
||||
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
|
||||
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchProviderTests\PerformSearchFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchProviderTests\ProcessSearchResultsFixture.cs" />
|
||||
|
@ -326,6 +326,51 @@ public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null_for_existing_episodes()
|
||||
{
|
||||
//Arrange
|
||||
const int seriesId = 71663;
|
||||
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.TvDbEpisodeId = 12345)
|
||||
.With(e => e.AirDate = DateTime.Today)
|
||||
.Build();
|
||||
|
||||
var fakeTvDbEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
||||
c => c.Episodes =
|
||||
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(l => l.Language = new TvdbLanguage(0, "eng", "a")).And(e => e.FirstAired = DateTime.Now)
|
||||
.TheFirst(1).With(e => e.FirstAired = new DateTime(1800, 1, 1))
|
||||
.Build())
|
||||
).With(c => c.Id = seriesId).Build();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
var db = TestDbHelper.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
db.Insert(fakeSeries);
|
||||
db.Insert(fakeEpisode);
|
||||
|
||||
mocker.GetMock<TvDbProvider>()
|
||||
.Setup(c => c.GetSeries(seriesId, true))
|
||||
.Returns(fakeTvDbEpisodes);
|
||||
|
||||
//Act
|
||||
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
|
||||
|
||||
//Assert
|
||||
var storedEpisodes = mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId).ToList();
|
||||
storedEpisodes.Should().HaveCount(1);
|
||||
storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(1);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RefreshEpisodeInfo_ignore_episode_zero()
|
||||
{
|
||||
|
@ -1,16 +1,19 @@
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
{
|
||||
@ -255,6 +258,57 @@ public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_em
|
||||
episodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEpisodeParseResult_should_return_single_episode_when_air_date_is_provided()
|
||||
{
|
||||
//Setup
|
||||
var fakeEpisode = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.AirDate = DateTime.Today)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 1)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(fakeEpisode);
|
||||
|
||||
//Act
|
||||
var episodes = Mocker.Resolve<EpisodeProvider>()
|
||||
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, true);
|
||||
|
||||
//Assert
|
||||
episodes.Should().HaveCount(1);
|
||||
episodes.First().AirDate.Should().Be(DateTime.Today);
|
||||
|
||||
Mocker.GetMock<IDatabase>().Verify(v=> v.Insert(It.IsAny<Episode>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEpisodeParseResult_get_daily_should_add_new_episode()
|
||||
{
|
||||
//Setup
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 1)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Mocker.GetMock<IDatabase>().Setup(s => s.Insert(It.IsAny<Episode>()))
|
||||
.Returns(1);
|
||||
|
||||
//Act
|
||||
var episodes = Mocker.Resolve<EpisodeProvider>()
|
||||
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, true);
|
||||
|
||||
//Assert
|
||||
episodes.Should().HaveCount(1);
|
||||
episodes.First().AirDate.Should().Be(DateTime.Today);
|
||||
|
||||
Mocker.GetMock<IDatabase>().Verify(v => v.Insert(It.IsAny<Episode>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ public class InventoryProvider_IsMonitoredTest : CoreTest
|
||||
private Episode episode;
|
||||
private Episode episode2;
|
||||
private EpisodeParseResult parseResultSingle;
|
||||
private EpisodeParseResult parseResultDaily;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
@ -49,6 +50,14 @@ public void Setup()
|
||||
AirDate = DateTime.Now.AddDays(-12).Date,
|
||||
};
|
||||
|
||||
parseResultDaily = new EpisodeParseResult()
|
||||
{
|
||||
CleanTitle = "Title",
|
||||
Language = LanguageType.English,
|
||||
Quality = new Quality(QualityTypes.Bluray720p, true),
|
||||
AirDate = DateTime.Now.AddDays(-12).Date,
|
||||
};
|
||||
|
||||
|
||||
episode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[0])
|
||||
@ -239,6 +248,25 @@ public void IsMonitored_multi_no_episodes_ignored_should_return_true()
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsMonitored_daily_not_ignored_should_return_true()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.FindSeries(It.IsAny<String>()))
|
||||
.Returns(series);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
|
||||
.Returns(new List<Episode> { episode });
|
||||
|
||||
episode.Ignored = false;
|
||||
|
||||
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultDaily);
|
||||
|
||||
//Assert
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@ private void InitJobs()
|
||||
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
|
||||
Kernel.Bind<IJob>().To<AppUpdateJob>().InSingletonScope();
|
||||
Kernel.Bind<IJob>().To<TrimLogsJob>().InSingletonScope();
|
||||
Kernel.Bind<IJob>().To<RecentBacklogSearchJob>().InSingletonScope();
|
||||
|
||||
Kernel.Get<JobProvider>().Initialize();
|
||||
Kernel.Get<WebTimer>().StartTimer(30);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
@ -51,5 +52,15 @@ public static string ParentUriString(this Uri uri)
|
||||
{
|
||||
return uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - String.Join("", uri.Segments).Length - uri.Query.Length);
|
||||
}
|
||||
|
||||
public static int MaxOrDefault(this IEnumerable<int> ints)
|
||||
{
|
||||
var intList = ints.ToList();
|
||||
|
||||
if (intList.Count() == 0)
|
||||
return 0;
|
||||
|
||||
return intList.Max();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,6 +235,7 @@
|
||||
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
|
||||
<Compile Include="Providers\Converting\HandbrakeProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\Newznab.cs" />
|
||||
<Compile Include="Providers\Jobs\RecentBacklogSearchJob.cs" />
|
||||
<Compile Include="Providers\Jobs\TrimLogsJob.cs" />
|
||||
<Compile Include="Providers\NewznzbProvider.cs" />
|
||||
<Compile Include="Providers\ExternalNotification\Prowl.cs" />
|
||||
|
@ -125,6 +125,46 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
|
||||
{
|
||||
var result = new List<Episode>();
|
||||
|
||||
if (parseResult.AirDate.HasValue)
|
||||
{
|
||||
var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value);
|
||||
|
||||
//if still null we should add the temp episode
|
||||
if (episodeInfo == null && autoAddNew)
|
||||
{
|
||||
Logger.Debug("Episode {0} doesn't exist in db. adding it now.", parseResult);
|
||||
episodeInfo = new Episode
|
||||
{
|
||||
SeriesId = parseResult.Series.SeriesId,
|
||||
AirDate = parseResult.AirDate.Value,
|
||||
Title = "TBD",
|
||||
Overview = String.Empty
|
||||
};
|
||||
|
||||
var episodesInSeries = GetEpisodeBySeries(parseResult.Series.SeriesId);
|
||||
|
||||
//Find the current season number
|
||||
var maxSeasonNumber = episodesInSeries.Select(s => s.SeasonNumber).MaxOrDefault();
|
||||
|
||||
//Set the season number
|
||||
episodeInfo.SeasonNumber = (maxSeasonNumber == 0) ? 1 : maxSeasonNumber;
|
||||
|
||||
//Find the latest episode number
|
||||
var maxEpisodeNumber = episodesInSeries
|
||||
.Where(w => w.SeasonNumber == episodeInfo.SeasonNumber)
|
||||
.Select(s => s.EpisodeNumber).MaxOrDefault();
|
||||
|
||||
//Set the episode number to max + 1
|
||||
episodeInfo.EpisodeNumber = maxEpisodeNumber + 1;
|
||||
|
||||
AddEpisode(episodeInfo);
|
||||
}
|
||||
|
||||
//Add to Result and Return (There will only be one episode to return)
|
||||
result.Add(episodeInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (parseResult.EpisodeNumbers == null)
|
||||
return result;
|
||||
|
||||
@ -258,9 +298,10 @@ public virtual void RefreshEpisodeInfo(Series series)
|
||||
episodeToUpdate.Overview = episode.Overview;
|
||||
|
||||
if (episode.FirstAired.Year > 1900)
|
||||
{
|
||||
episodeToUpdate.AirDate = episode.FirstAired.Date;
|
||||
}
|
||||
|
||||
else
|
||||
episodeToUpdate.AirDate = null;
|
||||
|
||||
successCount++;
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ public void Start(ProgressNotification notification, int targetId, int secondary
|
||||
|
||||
var countInDb = _episodeProvider.GetEpisodeNumbersBySeason(seriesId, seasonNumber).Count;
|
||||
|
||||
//Todo: Download a full season if more than n% is missing?
|
||||
|
||||
if (count != countInDb)
|
||||
{
|
||||
//Add the episodes to be processed manually
|
||||
|
48
NzbDrone.Core/Providers/Jobs/RecentBacklogSearchJob.cs
Normal file
48
NzbDrone.Core/Providers/Jobs/RecentBacklogSearchJob.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Model.Search;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Jobs
|
||||
{
|
||||
public class RecentBacklogSearchJob : IJob
|
||||
{
|
||||
private readonly EpisodeProvider _episodeProvider;
|
||||
private readonly EpisodeSearchJob _episodeSearchJob;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RecentBacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob)
|
||||
{
|
||||
_episodeProvider = episodeProvider;
|
||||
_episodeSearchJob = episodeSearchJob;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Recent Backlog Search"; }
|
||||
}
|
||||
|
||||
public int DefaultInterval
|
||||
{
|
||||
get { return 1440; }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
||||
{
|
||||
//Get episodes that are considered missing and aired in the last 30 days
|
||||
var missingEpisodes = _episodeProvider.EpisodesWithoutFiles(true).Where(e => e.AirDate >= DateTime.Today.AddDays(-30));
|
||||
|
||||
Logger.Debug("Processing missing episodes from the last 30 days");
|
||||
//Process the list of remaining episodes, 1 by 1
|
||||
foreach (var episode in missingEpisodes)
|
||||
{
|
||||
_episodeSearchJob.Start(notification, episode.EpisodeId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -155,15 +155,12 @@ public virtual bool EpisodeSearch(ProgressNotification notification, int episode
|
||||
Logger.Debug("Finished searching all indexers. Total {0}", reports.Count);
|
||||
notification.CurrentMessage = "Processing search results";
|
||||
|
||||
if (ProcessSearchResults(notification, reports, series, episode.SeasonNumber, episode.EpisodeNumber).Count == 1)
|
||||
return true;
|
||||
|
||||
//TODO:fix this so when search returns more than one episode
|
||||
//its populated with more than the original episode.
|
||||
reports.ForEach(c =>
|
||||
{
|
||||
c.Series = series;
|
||||
});
|
||||
|
||||
return (ProcessSearchResults(notification, reports, series, episode.SeasonNumber, episode.EpisodeNumber).Count == 1);
|
||||
Logger.Warn("Unable to find {0} in any of indexers.", episode);
|
||||
notification.CurrentMessage = String.Format("Unable to find {0} in any of indexers.", episode);
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<EpisodeParseResult> PerformSearch(ProgressNotification notification, Series series, int seasonNumber, IList<Episode> episodes = null)
|
||||
|
@ -3,10 +3,19 @@
|
||||
cache: false
|
||||
});
|
||||
|
||||
bindAutoCompletes();
|
||||
});
|
||||
|
||||
//
|
||||
$('.folderLookup:not(.ui-autocomplete-input), .seriesLookup:not(.ui-autocomplete-input), .localSeriesLookup:not(.ui-autocomplete-input)').live('focus', function (event) {
|
||||
bindAutoCompletes();
|
||||
});
|
||||
|
||||
function bindAutoCompletes() {
|
||||
bindFolderAutoComplete(".folderLookup");
|
||||
bindSeriesAutoComplete(".seriesLookup");
|
||||
bindLocalSeriesAutoComplete(".localSeriesLookup");
|
||||
});
|
||||
}
|
||||
|
||||
function bindFolderAutoComplete(selector) {
|
||||
|
||||
|
@ -74,7 +74,7 @@ function refreshRoot() {
|
||||
$('#rootDirs').html(data);
|
||||
});
|
||||
reloadAddNew();
|
||||
reloadExistingSeries();
|
||||
reloadExistingSeries();
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,7 +85,7 @@ NzbDrone
|
||||
{
|
||||
commands.Edit().ButtonType(GridButtonType.Image);
|
||||
commands.Delete().ButtonType(GridButtonType.Image);
|
||||
}).Title("Actions").Width(80);
|
||||
}).Title("Actions").Width(90);
|
||||
|
||||
})
|
||||
.Editable(editor => editor.Mode(GridEditMode.PopUp))
|
||||
|
Loading…
Reference in New Issue
Block a user