parent
6718d82432
commit
f1b1904e07
@ -1,33 +0,0 @@
|
|||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Core.DataAugmentation.Scene;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Test.Common.Categories;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
[IntegrationTest]
|
|
||||||
public class SceneMappingProxyFixture : CoreTest<SceneMappingProxy>
|
|
||||||
{
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
UseRealHttp();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void fetch_should_return_list_of_mappings()
|
|
||||||
{
|
|
||||||
var mappings = Subject.Fetch();
|
|
||||||
|
|
||||||
mappings.Should().NotBeEmpty();
|
|
||||||
|
|
||||||
mappings.Should().NotContain(c => c.SearchTerm.IsNullOrWhiteSpace());
|
|
||||||
mappings.Should().NotContain(c => c.Title.IsNullOrWhiteSpace());
|
|
||||||
mappings.Should().Contain(c => c.SeasonNumber > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,338 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.DataAugmentation.Scene;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Test.Common;
|
|
||||||
using FluentAssertions;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Core.DataAugmentation;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
|
|
||||||
public class SceneMappingServiceFixture : CoreTest<SceneMappingService>
|
|
||||||
{
|
|
||||||
private List<SceneMapping> _fakeMappings;
|
|
||||||
|
|
||||||
private Mock<ISceneMappingProvider> _provider1;
|
|
||||||
private Mock<ISceneMappingProvider> _provider2;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_fakeMappings = Builder<SceneMapping>.CreateListOfSize(5).BuildListOfNew();
|
|
||||||
|
|
||||||
_fakeMappings[0].SearchTerm = "Words";
|
|
||||||
_fakeMappings[1].SearchTerm = "That";
|
|
||||||
_fakeMappings[2].SearchTerm = "Can";
|
|
||||||
_fakeMappings[3].SearchTerm = "Be";
|
|
||||||
_fakeMappings[4].SearchTerm = "Cleaned";
|
|
||||||
|
|
||||||
_fakeMappings[0].ParseTerm = "Words";
|
|
||||||
_fakeMappings[1].ParseTerm = "That";
|
|
||||||
_fakeMappings[2].ParseTerm = "Can";
|
|
||||||
_fakeMappings[3].ParseTerm = "Be";
|
|
||||||
_fakeMappings[4].ParseTerm = "Cleaned";
|
|
||||||
|
|
||||||
_provider1 = new Mock<ISceneMappingProvider>();
|
|
||||||
_provider1.Setup(s => s.GetSceneMappings()).Returns(_fakeMappings);
|
|
||||||
|
|
||||||
_provider2 = new Mock<ISceneMappingProvider>();
|
|
||||||
_provider2.Setup(s => s.GetSceneMappings()).Returns(_fakeMappings);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenProviders(IEnumerable<Mock<ISceneMappingProvider>> providers)
|
|
||||||
{
|
|
||||||
Mocker.SetConstant<IEnumerable<ISceneMappingProvider>>(providers.Select(s => s.Object));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_purge_existing_mapping_and_add_new_ones()
|
|
||||||
{
|
|
||||||
GivenProviders(new [] { _provider1 });
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(_fakeMappings);
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
AssertMappingUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_delete_if_fetch_fails()
|
|
||||||
{
|
|
||||||
GivenProviders(new[] { _provider1 });
|
|
||||||
|
|
||||||
_provider1.Setup(c => c.GetSceneMappings()).Throws(new WebException());
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
AssertNoUpdate();
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedErrors(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_delete_if_fetch_returns_empty_list()
|
|
||||||
{
|
|
||||||
GivenProviders(new[] { _provider1 });
|
|
||||||
|
|
||||||
_provider1.Setup(c => c.GetSceneMappings()).Returns(new List<SceneMapping>());
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
AssertNoUpdate();
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_get_mappings_for_all_providers()
|
|
||||||
{
|
|
||||||
GivenProviders(new[] { _provider1, _provider2 });
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(_fakeMappings);
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
_provider1.Verify(c => c.GetSceneMappings(), Times.Once());
|
|
||||||
_provider2.Verify(c => c.GetSceneMappings(), Times.Once());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_refresh_cache_if_cache_is_empty_when_looking_for_tvdb_id()
|
|
||||||
{
|
|
||||||
Subject.FindTvdbId("title");
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>()
|
|
||||||
.Verify(v => v.All(), Times.Once());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_refresh_cache_if_cache_is_not_empty_when_looking_for_tvdb_id()
|
|
||||||
{
|
|
||||||
GivenProviders(new[] { _provider1 });
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>()
|
|
||||||
.Setup(s => s.All())
|
|
||||||
.Returns(Builder<SceneMapping>.CreateListOfSize(1).Build());
|
|
||||||
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>()
|
|
||||||
.Verify(v => v.All(), Times.Once());
|
|
||||||
|
|
||||||
Subject.FindTvdbId("title");
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>()
|
|
||||||
.Verify(v => v.All(), Times.Once());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_add_mapping_with_blank_title()
|
|
||||||
{
|
|
||||||
GivenProviders(new[] { _provider1 });
|
|
||||||
|
|
||||||
var fakeMappings = Builder<SceneMapping>.CreateListOfSize(2)
|
|
||||||
.TheLast(1)
|
|
||||||
.With(m => m.Title = null)
|
|
||||||
.Build()
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_provider1.Setup(s => s.GetSceneMappings()).Returns(fakeMappings);
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(_fakeMappings);
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(It.Is<IList<SceneMapping>>(m => !m.Any(s => s.Title.IsNullOrWhiteSpace()))), Times.Once());
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_add_mapping_with_blank_search_title()
|
|
||||||
{
|
|
||||||
GivenProviders(new[] { _provider1 });
|
|
||||||
|
|
||||||
var fakeMappings = Builder<SceneMapping>.CreateListOfSize(2)
|
|
||||||
.TheLast(1)
|
|
||||||
.With(m => m.SearchTerm = null)
|
|
||||||
.Build()
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_provider1.Setup(s => s.GetSceneMappings()).Returns(fakeMappings);
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(_fakeMappings);
|
|
||||||
|
|
||||||
Subject.Execute(new UpdateSceneMappingCommand());
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(It.Is<IList<SceneMapping>>(m => !m.Any(s => s. SearchTerm.IsNullOrWhiteSpace()))), Times.Once());
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[TestCase("Working!!", "Working!!", 1)]
|
|
||||||
[TestCase("Working`!!", "Working`!!", 2)]
|
|
||||||
[TestCase("Working!!!", "Working!!!", 3)]
|
|
||||||
[TestCase("Working!!!!", "Working!!!", 3)]
|
|
||||||
[TestCase("Working !!", "Working!!", 1)]
|
|
||||||
public void should_return_single_match(string parseTitle, string title, int expectedSeasonNumber)
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Working!!", ParseTerm = "working", SearchTerm = "Working!!", TvdbId = 100, SceneSeasonNumber = 1 },
|
|
||||||
new SceneMapping { Title = "Working`!!", ParseTerm = "working", SearchTerm = "Working`!!", TvdbId = 100, SceneSeasonNumber = 2 },
|
|
||||||
new SceneMapping { Title = "Working!!!", ParseTerm = "working", SearchTerm = "Working!!!", TvdbId = 100, SceneSeasonNumber = 3 },
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
var tvdbId = Subject.FindTvdbId(parseTitle);
|
|
||||||
var seasonNumber = Subject.GetSceneSeasonNumber(parseTitle);
|
|
||||||
|
|
||||||
tvdbId.Should().Be(100);
|
|
||||||
seasonNumber.Should().Be(expectedSeasonNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_return_alternate_title_for_global_season()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu 1", ParseTerm = "fudanshikoukouseikatsu1", SearchTerm = "Fudanshi Koukou Seikatsu 1", TvdbId = 100, SeasonNumber = null, SceneSeasonNumber = null },
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu 2", ParseTerm = "fudanshikoukouseikatsu2", SearchTerm = "Fudanshi Koukou Seikatsu 2", TvdbId = 100, SeasonNumber = -1, SceneSeasonNumber = null },
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu 3", ParseTerm = "fudanshikoukouseikatsu3", SearchTerm = "Fudanshi Koukou Seikatsu 3", TvdbId = 100, SeasonNumber = null, SceneSeasonNumber = -1 },
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu 4", ParseTerm = "fudanshikoukouseikatsu4", SearchTerm = "Fudanshi Koukou Seikatsu 4", TvdbId = 100, SeasonNumber = -1, SceneSeasonNumber = -1 },
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
var names = Subject.GetSceneNames(100, new List<int> { 10 }, new List<int> { 10 });
|
|
||||||
names.Should().HaveCount(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_return_alternate_title_for_season()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu", ParseTerm = "fudanshikoukouseikatsu", SearchTerm = "Fudanshi Koukou Seikatsu", TvdbId = 100, SeasonNumber = 1, SceneSeasonNumber = null }
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
var names = Subject.GetSceneNames(100, new List<int> { 1 }, new List<int> { 10 });
|
|
||||||
names.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_return_alternate_title_for_season()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu", ParseTerm = "fudanshikoukouseikatsu", SearchTerm = "Fudanshi Koukou Seikatsu", TvdbId = 100, SeasonNumber = 1, SceneSeasonNumber = null }
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
var names = Subject.GetSceneNames(100, new List<int> { 2 }, new List<int> { 10 });
|
|
||||||
names.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_return_alternate_title_for_sceneseason()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu", ParseTerm = "fudanshikoukouseikatsu", SearchTerm = "Fudanshi Koukou Seikatsu", TvdbId = 100, SeasonNumber = null, SceneSeasonNumber = 1 }
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
var names = Subject.GetSceneNames(100, new List<int> { 10 }, new List<int> { 1 });
|
|
||||||
names.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_return_alternate_title_for_sceneseason()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu", ParseTerm = "fudanshikoukouseikatsu", SearchTerm = "Fudanshi Koukou Seikatsu", TvdbId = 100, SeasonNumber = null, SceneSeasonNumber = 1 }
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
var names = Subject.GetSceneNames(100, new List<int> { 10 }, new List<int> { 2 });
|
|
||||||
names.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_return_alternate_title_for_fairy_tail()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fairy Tail S2", ParseTerm = "fairytails2", SearchTerm = "Fairy Tail S2", TvdbId = 100, SeasonNumber = null, SceneSeasonNumber = 2 }
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 4 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 5 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 6 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 7 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 20 }, new List<int> { 1 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 20 }, new List<int> { 2 }).Should().NotBeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 20 }, new List<int> { 3 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 20 }, new List<int> { 4 }).Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_return_alternate_title_for_fudanshi()
|
|
||||||
{
|
|
||||||
var mappings = new List<SceneMapping>
|
|
||||||
{
|
|
||||||
new SceneMapping { Title = "Fudanshi Koukou Seikatsu", ParseTerm = "fudanshikoukouseikatsu", SearchTerm = "Fudanshi Koukou Seikatsu", TvdbId = 100, SeasonNumber = null, SceneSeasonNumber = 1 }
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
|
||||||
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 1 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 2 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 3 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 4 }, new List<int> { 20 }).Should().BeEmpty();
|
|
||||||
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 1 }, new List<int> { 1 }).Should().NotBeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 2 }, new List<int> { 2 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 3 }, new List<int> { 3 }).Should().BeEmpty();
|
|
||||||
Subject.GetSceneNames(100, new List<int> { 4 }, new List<int> { 4 }).Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AssertNoUpdate()
|
|
||||||
{
|
|
||||||
_provider1.Verify(c => c.GetSceneMappings(), Times.Once());
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.Clear(It.IsAny<string>()), Times.Never());
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(_fakeMappings), Times.Never());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AssertMappingUpdated()
|
|
||||||
{
|
|
||||||
_provider1.Verify(c => c.GetSceneMappings(), Times.Once());
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.Clear(It.IsAny<string>()), Times.Once());
|
|
||||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(_fakeMappings), Times.Once());
|
|
||||||
|
|
||||||
foreach (var sceneMapping in _fakeMappings)
|
|
||||||
{
|
|
||||||
Subject.GetSceneNames(sceneMapping.TvdbId, _fakeMappings.Select(m => m.SeasonNumber.Value).Distinct().ToList(), new List<int>()).Should().Contain(sceneMapping.SearchTerm);
|
|
||||||
Subject.FindTvdbId(sceneMapping.ParseTerm).Should().Be(sceneMapping.TvdbId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Core.Datastore.Migration;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class force_lib_updateFixture : MigrationTest<force_lib_update>
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void should_not_fail_on_empty_db()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb();
|
|
||||||
|
|
||||||
db.Query("SELECT * FROM ScheduledTasks").Should().BeEmpty();
|
|
||||||
db.Query("SELECT * FROM Series").Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_reset_job_last_execution_time()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("ScheduledTasks").Row(new
|
|
||||||
{
|
|
||||||
TypeName = "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand",
|
|
||||||
Interval = 10,
|
|
||||||
LastExecution = "2000-01-01 00:00:00"
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("ScheduledTasks").Row(new
|
|
||||||
{
|
|
||||||
TypeName = "NzbDrone.Core.Backup.BackupCommand",
|
|
||||||
Interval = 10,
|
|
||||||
LastExecution = "2000-01-01 00:00:00"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var jobs = db.Query<ScheduledTasks75>("SELECT TypeName, LastExecution FROM ScheduledTasks");
|
|
||||||
|
|
||||||
jobs.Single(c => c.TypeName == "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand")
|
|
||||||
.LastExecution.Year.Should()
|
|
||||||
.Be(2014);
|
|
||||||
|
|
||||||
jobs.Single(c => c.TypeName == "NzbDrone.Core.Backup.BackupCommand")
|
|
||||||
.LastExecution.Year.Should()
|
|
||||||
.Be(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_reset_series_last_sync_time()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Profiles").Row(new
|
|
||||||
|
|
||||||
{
|
|
||||||
Name = "Profile1",
|
|
||||||
CutOff = 0,
|
|
||||||
Items = "[]",
|
|
||||||
Language = 1
|
|
||||||
});
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 1,
|
|
||||||
TvRageId = 1,
|
|
||||||
Title = "Title1",
|
|
||||||
CleanTitle = "CleanTitle1",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 2,
|
|
||||||
TvRageId = 2,
|
|
||||||
Title = "Title2",
|
|
||||||
CleanTitle = "CleanTitle2",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test2",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var series = db.Query<Series69>("SELECT LastInfoSync FROM Series");
|
|
||||||
|
|
||||||
series.Should().OnlyContain(c => c.LastInfoSync.Value.Year == 2014);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,244 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.Datastore.Migration;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class dedupe_tagsFixture : MigrationTest<dedupe_tags>
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void should_not_fail_if_series_tags_are_null()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Profiles").Row(new
|
|
||||||
|
|
||||||
{
|
|
||||||
Name = "Profile1",
|
|
||||||
CutOff = 0,
|
|
||||||
Items = "[]",
|
|
||||||
Language = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 1,
|
|
||||||
TvRageId = 1,
|
|
||||||
Title = "Title1",
|
|
||||||
CleanTitle = "CleanTitle1",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
|
||||||
tags.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_fail_if_series_tags_are_empty()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Profiles").Row(new
|
|
||||||
|
|
||||||
{
|
|
||||||
Name = "Profile1",
|
|
||||||
CutOff = 0,
|
|
||||||
Items = "[]",
|
|
||||||
Language = 1
|
|
||||||
});
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 1,
|
|
||||||
TvRageId = 1,
|
|
||||||
Title = "Title1",
|
|
||||||
CleanTitle = "CleanTitle1",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
Tags = "[]",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
|
||||||
tags.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_remove_duplicate_labels_from_tags()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
|
||||||
tags.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_allow_duplicate_tag_to_be_inserted()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Assert.That(() => db.Query("INSERT INTO Tags (Label) VALUES ('test')"), Throws.Exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_replace_duplicated_tag_with_proper_tag()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Profiles").Row(new
|
|
||||||
|
|
||||||
{
|
|
||||||
Name = "Profile1",
|
|
||||||
CutOff = 0,
|
|
||||||
Items = "[]",
|
|
||||||
Language = 1
|
|
||||||
});
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 1,
|
|
||||||
TvRageId = 1,
|
|
||||||
Title = "Title1",
|
|
||||||
CleanTitle = "CleanTitle1",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
Tags = "[2]",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var series = db.Query<Series69>("SELECT Tags FROM Series WHERE Id = 1").Single();
|
|
||||||
series.Tags.First().Should().Be(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_only_update_affected_series()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("Profiles").Row(new
|
|
||||||
|
|
||||||
{
|
|
||||||
Name = "Profile1",
|
|
||||||
CutOff = 0,
|
|
||||||
Items = "[]",
|
|
||||||
Language = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 1,
|
|
||||||
TvRageId = 1,
|
|
||||||
Title = "Title1",
|
|
||||||
CleanTitle = "CleanTitle1",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
Tags = "[2]",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Series").Row(new
|
|
||||||
{
|
|
||||||
Tvdbid = 2,
|
|
||||||
TvRageId = 2,
|
|
||||||
Title = "Title2",
|
|
||||||
CleanTitle = "CleanTitle2",
|
|
||||||
Status = 1,
|
|
||||||
Images = "",
|
|
||||||
Path = "c:\\test",
|
|
||||||
Monitored = 1,
|
|
||||||
SeasonFolder = 1,
|
|
||||||
Runtime = 0,
|
|
||||||
SeriesType = 0,
|
|
||||||
UseSceneNumbering = 0,
|
|
||||||
LastInfoSync = "2000-01-01 00:00:00",
|
|
||||||
Tags = "[]",
|
|
||||||
ProfileId = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
|
|
||||||
c.Insert.IntoTable("Tags").Row(new
|
|
||||||
{
|
|
||||||
Label = "test"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var series = db.Query<Series69>("SELECT Tags FROM Series WHERE Id = 2").Single();
|
|
||||||
series.Tags.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.Datastore.Migration;
|
|
||||||
using NzbDrone.Core.Parser;
|
|
||||||
using NzbDrone.Core.Languages;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class fix_extra_file_extensionsFixture : MigrationTest<fix_extra_file_extension>
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void should_extra_files_that_do_not_have_an_extension()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("ExtraFiles").Row(new
|
|
||||||
{
|
|
||||||
SeriesId = 1,
|
|
||||||
SeasonNumber = 1,
|
|
||||||
EpisodeFileId = 1,
|
|
||||||
RelativePath = "Series.Title.S01E01",
|
|
||||||
Added = "2016-05-30 20:23:02.3725923",
|
|
||||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
|
||||||
Extension = ""
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var items = db.Query("Select * from ExtraFiles");
|
|
||||||
|
|
||||||
items.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_fix_double_extension()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("SubtitleFiles").Row(new
|
|
||||||
{
|
|
||||||
SeriesId = 1,
|
|
||||||
SeasonNumber = 1,
|
|
||||||
EpisodeFileId = 1,
|
|
||||||
RelativePath = "Series.Title.S01E01.en.srt",
|
|
||||||
Added = "2016-05-30 20:23:02.3725923",
|
|
||||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
|
||||||
Language = Core.Languages.Language.English,
|
|
||||||
Extension = "en.srt"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var items = db.Query("Select * from SubtitleFiles");
|
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
|
||||||
items.First()["Extension"].Should().Be(".srt");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_fix_extension_missing_a_leading_period()
|
|
||||||
{
|
|
||||||
var db = WithMigrationTestDb(c =>
|
|
||||||
{
|
|
||||||
c.Insert.IntoTable("ExtraFiles").Row(new
|
|
||||||
{
|
|
||||||
SeriesId = 1,
|
|
||||||
SeasonNumber = 1,
|
|
||||||
EpisodeFileId = 1,
|
|
||||||
RelativePath = "Series.Title.S01E01.nfo-orig",
|
|
||||||
Added = "2016-05-30 20:23:02.3725923",
|
|
||||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
|
||||||
Extension = "nfo-orig"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var items = db.Query("Select * from ExtraFiles");
|
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
|
||||||
items.First()["Extension"].Should().Be(".nfo-orig");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using NzbDrone.Core.Datastore;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.DataAugmentation.Scene
|
|
||||||
{
|
|
||||||
public class SceneMapping : ModelBase
|
|
||||||
{
|
|
||||||
public string Title { get; set; }
|
|
||||||
public string ParseTerm { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("searchTitle")]
|
|
||||||
public string SearchTerm { get; set; }
|
|
||||||
|
|
||||||
public int TvdbId { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("season")]
|
|
||||||
public int? SeasonNumber { get; set; }
|
|
||||||
|
|
||||||
public int? SceneSeasonNumber { get; set; }
|
|
||||||
public string Type { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
using NzbDrone.Core.Datastore;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.DataAugmentation.Scene
|
|
||||||
{
|
|
||||||
public interface ISceneMappingRepository : IBasicRepository<SceneMapping>
|
|
||||||
{
|
|
||||||
List<SceneMapping> FindByTvdbid(int tvdbId);
|
|
||||||
void Clear(string type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository
|
|
||||||
{
|
|
||||||
public SceneMappingRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
|
||||||
: base(database, eventAggregator)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SceneMapping> FindByTvdbid(int tvdbId)
|
|
||||||
{
|
|
||||||
return Query.Where(x => x.TvdbId == tvdbId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear(string type)
|
|
||||||
{
|
|
||||||
Delete(s => s.Type == type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,252 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.Cache;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
|
||||||
using NzbDrone.Core.Parser;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.DataAugmentation.Scene
|
|
||||||
{
|
|
||||||
public interface ISceneMappingService
|
|
||||||
{
|
|
||||||
List<string> GetSceneNames(int tvdbId, List<int> seasonNumbers, List<int> sceneSeasonNumbers);
|
|
||||||
int? FindTvdbId(string title);
|
|
||||||
List<SceneMapping> FindByTvdbId(int tvdbId);
|
|
||||||
SceneMapping FindSceneMapping(string title);
|
|
||||||
int? GetSceneSeasonNumber(string title);
|
|
||||||
int? GetTvdbSeasonNumber(string title);
|
|
||||||
int? GetSceneSeasonNumber(int tvdbId, int seasonNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SceneMappingService : ISceneMappingService,
|
|
||||||
// IHandle<SeriesRefreshStartingEvent>,
|
|
||||||
IExecute<UpdateSceneMappingCommand>
|
|
||||||
{
|
|
||||||
private readonly ISceneMappingRepository _repository;
|
|
||||||
private readonly IEnumerable<ISceneMappingProvider> _sceneMappingProviders;
|
|
||||||
private readonly IEventAggregator _eventAggregator;
|
|
||||||
private readonly Logger _logger;
|
|
||||||
private readonly ICachedDictionary<List<SceneMapping>> _getTvdbIdCache;
|
|
||||||
private readonly ICachedDictionary<List<SceneMapping>> _findByTvdbIdCache;
|
|
||||||
|
|
||||||
public SceneMappingService(ISceneMappingRepository repository,
|
|
||||||
ICacheManager cacheManager,
|
|
||||||
IEnumerable<ISceneMappingProvider> sceneMappingProviders,
|
|
||||||
IEventAggregator eventAggregator,
|
|
||||||
Logger logger)
|
|
||||||
{
|
|
||||||
_repository = repository;
|
|
||||||
_sceneMappingProviders = sceneMappingProviders;
|
|
||||||
_eventAggregator = eventAggregator;
|
|
||||||
_logger = logger;
|
|
||||||
|
|
||||||
_getTvdbIdCache = cacheManager.GetCacheDictionary<List<SceneMapping>>(GetType(), "tvdb_id");
|
|
||||||
_findByTvdbIdCache = cacheManager.GetCacheDictionary<List<SceneMapping>>(GetType(), "find_tvdb_id");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> GetSceneNames(int tvdbId, List<int> seasonNumbers, List<int> sceneSeasonNumbers)
|
|
||||||
{
|
|
||||||
var mappings = FindByTvdbId(tvdbId);
|
|
||||||
|
|
||||||
if (mappings == null)
|
|
||||||
{
|
|
||||||
return new List<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var names = mappings.Where(n => n.SeasonNumber.HasValue && seasonNumbers.Contains(n.SeasonNumber.Value) ||
|
|
||||||
n.SceneSeasonNumber.HasValue && sceneSeasonNumbers.Contains(n.SceneSeasonNumber.Value) ||
|
|
||||||
(n.SeasonNumber ?? -1) == -1 && (n.SceneSeasonNumber ?? -1) == -1)
|
|
||||||
.Select(n => n.SearchTerm).Distinct().ToList();
|
|
||||||
|
|
||||||
return FilterNonEnglish(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int? FindTvdbId(string title)
|
|
||||||
{
|
|
||||||
var mapping = FindMapping(title);
|
|
||||||
|
|
||||||
if (mapping == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return mapping.TvdbId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SceneMapping> FindByTvdbId(int tvdbId)
|
|
||||||
{
|
|
||||||
if (_findByTvdbIdCache.Count == 0)
|
|
||||||
{
|
|
||||||
RefreshCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
var mappings = _findByTvdbIdCache.Find(tvdbId.ToString());
|
|
||||||
|
|
||||||
if (mappings == null)
|
|
||||||
{
|
|
||||||
return new List<SceneMapping>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return mappings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SceneMapping FindSceneMapping(string title)
|
|
||||||
{
|
|
||||||
return FindMapping(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int? GetSceneSeasonNumber(string title)
|
|
||||||
{
|
|
||||||
var mapping = FindMapping(title);
|
|
||||||
|
|
||||||
if (mapping == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapping.SceneSeasonNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int? GetTvdbSeasonNumber(string title)
|
|
||||||
{
|
|
||||||
var mapping = FindMapping(title);
|
|
||||||
|
|
||||||
if (mapping == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapping.SeasonNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int? GetSceneSeasonNumber(int tvdbId, int seasonNumber)
|
|
||||||
{
|
|
||||||
var mappings = FindByTvdbId(tvdbId);
|
|
||||||
|
|
||||||
if (mappings == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var mapping = mappings.FirstOrDefault(e => e.SeasonNumber == seasonNumber && e.SceneSeasonNumber.HasValue);
|
|
||||||
|
|
||||||
if (mapping == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapping.SceneSeasonNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateMappings()
|
|
||||||
{
|
|
||||||
_logger.Info("Updating Scene mappings");
|
|
||||||
|
|
||||||
foreach (var sceneMappingProvider in _sceneMappingProviders)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var mappings = sceneMappingProvider.GetSceneMappings();
|
|
||||||
|
|
||||||
if (mappings.Any())
|
|
||||||
{
|
|
||||||
_repository.Clear(sceneMappingProvider.GetType().Name);
|
|
||||||
|
|
||||||
mappings.RemoveAll(sceneMapping =>
|
|
||||||
{
|
|
||||||
if (sceneMapping.Title.IsNullOrWhiteSpace() ||
|
|
||||||
sceneMapping.SearchTerm.IsNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
_logger.Warn("Invalid scene mapping found for: {0}, skipping", sceneMapping.TvdbId);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var sceneMapping in mappings)
|
|
||||||
{
|
|
||||||
sceneMapping.ParseTerm = sceneMapping.Title.CleanSeriesTitle();
|
|
||||||
sceneMapping.Type = sceneMappingProvider.GetType().Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
_repository.InsertMany(mappings.ToList());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Warn("Received empty list of mapping. will not update.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex, "Failed to Update Scene Mappings.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RefreshCache();
|
|
||||||
|
|
||||||
_eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent());
|
|
||||||
}
|
|
||||||
|
|
||||||
private SceneMapping FindMapping(string title)
|
|
||||||
{
|
|
||||||
if (_getTvdbIdCache.Count == 0)
|
|
||||||
{
|
|
||||||
RefreshCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
var candidates = _getTvdbIdCache.Find(title.CleanSeriesTitle());
|
|
||||||
|
|
||||||
if (candidates == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (candidates.Count == 1)
|
|
||||||
{
|
|
||||||
return candidates.First();
|
|
||||||
}
|
|
||||||
|
|
||||||
var exactMatch = candidates.OrderByDescending(v => v.SeasonNumber)
|
|
||||||
.FirstOrDefault(v => v.Title == title);
|
|
||||||
|
|
||||||
if (exactMatch != null)
|
|
||||||
{
|
|
||||||
return exactMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
var closestMatch = candidates.OrderBy(v => title.LevenshteinDistance(v.Title, 10, 1, 10))
|
|
||||||
.ThenByDescending(v => v.SeasonNumber)
|
|
||||||
.First();
|
|
||||||
|
|
||||||
return closestMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RefreshCache()
|
|
||||||
{
|
|
||||||
var mappings = _repository.All().ToList();
|
|
||||||
|
|
||||||
_getTvdbIdCache.Update(mappings.GroupBy(v => v.ParseTerm).ToDictionary(v => v.Key, v => v.ToList()));
|
|
||||||
_findByTvdbIdCache.Update(mappings.GroupBy(v => v.TvdbId).ToDictionary(v => v.Key.ToString(), v => v.ToList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<string> FilterNonEnglish(List<string> titles)
|
|
||||||
{
|
|
||||||
return titles.Where(title => title.All(c => c <= 255)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
//public void Handle(SeriesRefreshStartingEvent message)
|
|
||||||
//{
|
|
||||||
// if (message.ManualTrigger && _findByTvdbIdCache.IsExpired(TimeSpan.FromMinutes(1)))
|
|
||||||
// {
|
|
||||||
// UpdateMappings();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void Execute(UpdateSceneMappingCommand message)
|
|
||||||
{
|
|
||||||
UpdateMappings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using NzbDrone.Core.Messaging.Commands;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.DataAugmentation.Scene
|
|
||||||
{
|
|
||||||
public class UpdateSceneMappingCommand : Command
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
using FluentMigrator;
|
|
||||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using NzbDrone.Common.Serializer;
|
|
||||||
using NzbDrone.Core.Profiles.Qualities;
|
|
||||||
using NzbDrone.Core.Qualities;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NzbDrone.Core.Datastore.Converters;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore.Migration
|
|
||||||
{
|
|
||||||
[Migration(36)]
|
|
||||||
public class update_with_quality_converters : NzbDroneMigrationBase
|
|
||||||
{
|
|
||||||
protected override void MainDbUpgrade()
|
|
||||||
{
|
|
||||||
if (!Schema.Table("QualityProfiles").Column("Items").Exists())
|
|
||||||
{
|
|
||||||
Alter.Table("QualityProfiles").AddColumn("Items").AsString().Nullable();
|
|
||||||
}
|
|
||||||
|
|
||||||
Execute.WithConnection(ConvertQualityProfiles);
|
|
||||||
Execute.WithConnection(ConvertQualityModels);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConvertQualityProfiles(IDbConnection conn, IDbTransaction tran)
|
|
||||||
{
|
|
||||||
var qualityProfileItemConverter = new EmbeddedDocumentConverter(new QualityIntConverter());
|
|
||||||
|
|
||||||
// Convert 'Allowed' column in QualityProfiles from Json List<object> to Json List<int> (int = Quality)
|
|
||||||
using (IDbCommand qualityProfileCmd = conn.CreateCommand())
|
|
||||||
{
|
|
||||||
qualityProfileCmd.Transaction = tran;
|
|
||||||
qualityProfileCmd.CommandText = @"SELECT Id, Allowed FROM QualityProfiles";
|
|
||||||
using (IDataReader qualityProfileReader = qualityProfileCmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
while (qualityProfileReader.Read())
|
|
||||||
{
|
|
||||||
var id = qualityProfileReader.GetInt32(0);
|
|
||||||
var allowedJson = qualityProfileReader.GetString(1);
|
|
||||||
|
|
||||||
var allowed = Json.Deserialize<List<Quality>>(allowedJson);
|
|
||||||
|
|
||||||
var items = Quality.DefaultQualityDefinitions.OrderBy(v => v.Weight).Select(v => new ProfileQualityItem { Quality = v.Quality, Allowed = allowed.Contains(v.Quality) }).ToList();
|
|
||||||
|
|
||||||
var allowedNewJson = qualityProfileItemConverter.ToDB(items);
|
|
||||||
|
|
||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
|
||||||
{
|
|
||||||
updateCmd.Transaction = tran;
|
|
||||||
updateCmd.CommandText = "UPDATE QualityProfiles SET Items = ? WHERE Id = ?";
|
|
||||||
updateCmd.AddParameter(allowedNewJson);
|
|
||||||
updateCmd.AddParameter(id);
|
|
||||||
|
|
||||||
updateCmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConvertQualityModels(IDbConnection conn, IDbTransaction tran)
|
|
||||||
{
|
|
||||||
// Converts the QualityModel JSON objects to their new format (only storing the QualityId instead of the entire object)
|
|
||||||
ConvertQualityModel(conn, tran, "Blacklist");
|
|
||||||
ConvertQualityModel(conn, tran, "EpisodeFiles");
|
|
||||||
ConvertQualityModel(conn, tran, "History");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConvertQualityModel(IDbConnection conn, IDbTransaction tran, string tableName)
|
|
||||||
{
|
|
||||||
var qualityModelConverter = new EmbeddedDocumentConverter(new QualityIntConverter());
|
|
||||||
|
|
||||||
using (IDbCommand qualityModelCmd = conn.CreateCommand())
|
|
||||||
{
|
|
||||||
qualityModelCmd.Transaction = tran;
|
|
||||||
qualityModelCmd.CommandText = @"SELECT Distinct Quality FROM " + tableName;
|
|
||||||
using (IDataReader qualityModelReader = qualityModelCmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
while (qualityModelReader.Read())
|
|
||||||
{
|
|
||||||
var qualityJson = qualityModelReader.GetString(0);
|
|
||||||
|
|
||||||
SourceQualityModel036 sourceQuality;
|
|
||||||
|
|
||||||
if (!Json.TryDeserialize<SourceQualityModel036>(qualityJson, out sourceQuality))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var qualityNewJson = qualityModelConverter.ToDB(new DestinationQualityModel036
|
|
||||||
{
|
|
||||||
Quality = sourceQuality.Quality.Id,
|
|
||||||
Proper = sourceQuality.Proper
|
|
||||||
});
|
|
||||||
|
|
||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
|
||||||
{
|
|
||||||
updateCmd.Transaction = tran;
|
|
||||||
updateCmd.CommandText = "UPDATE " + tableName + " SET Quality = ? WHERE Quality = ?";
|
|
||||||
updateCmd.AddParameter(qualityNewJson);
|
|
||||||
updateCmd.AddParameter(qualityJson);
|
|
||||||
|
|
||||||
updateCmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DestinationQualityModel036
|
|
||||||
{
|
|
||||||
public int Quality { get; set; }
|
|
||||||
public bool Proper { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SourceQualityModel036
|
|
||||||
{
|
|
||||||
public SourceQuality036 Quality { get; set; }
|
|
||||||
public bool Proper { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SourceQuality036
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue