mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Renamed SceneNameMapping to SceneMapping.
SceneMappingProvider moved to PetaPoco.
This commit is contained in:
parent
310c317361
commit
ab26d2dd61
@ -247,7 +247,7 @@ public void start_should_search_all_providers()
|
||||
mocker.GetMock<InventoryProvider>()
|
||||
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);
|
||||
|
||||
mocker.GetMock<SceneNameMappingProvider>()
|
||||
mocker.GetMock<SceneMappingProvider>()
|
||||
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
|
||||
|
||||
//Act
|
||||
@ -298,7 +298,7 @@ public void start_should_use_scene_name_to_search()
|
||||
mocker.GetMock<InventoryProvider>()
|
||||
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);
|
||||
|
||||
mocker.GetMock<SceneNameMappingProvider>()
|
||||
mocker.GetMock<SceneMappingProvider>()
|
||||
.Setup(s => s.GetSceneName(71256)).Returns("The Daily Show");
|
||||
|
||||
//Act
|
||||
@ -355,7 +355,7 @@ public void start_failed_indexer_should_not_break_job()
|
||||
mocker.GetMock<InventoryProvider>()
|
||||
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);;
|
||||
|
||||
mocker.GetMock<SceneNameMappingProvider>()
|
||||
mocker.GetMock<SceneMappingProvider>()
|
||||
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
|
||||
|
||||
//Act
|
||||
|
@ -19,25 +19,26 @@ namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class SceneNameHelperTest : TestBase
|
||||
public class SceneMappingTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void GetSceneName_exists()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.CleanTitle = "laworder")
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()))
|
||||
.Returns(fakeMap);
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var sceneName = mocker.Resolve<SceneNameMappingProvider>().GetSceneName(fakeMap.SeriesId);
|
||||
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(fakeMap.SceneName, sceneName);
|
||||
@ -47,7 +48,7 @@ public void GetSceneName_exists()
|
||||
public void GetSeriesId_exists()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.With(f => f.SceneName = "laworder")
|
||||
@ -55,12 +56,12 @@ public void GetSeriesId_exists()
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()))
|
||||
.Returns(fakeMap);
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var seriesId = mocker.Resolve<SceneNameMappingProvider>().GetSeriesId(fakeMap.SceneCleanName);
|
||||
var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId(fakeMap.CleanTitle);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(fakeMap.SeriesId, seriesId);
|
||||
@ -70,18 +71,20 @@ public void GetSeriesId_exists()
|
||||
public void GetSceneName_null()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.With(f => f.SceneName = "laworder")
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()));
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var sceneName = mocker.Resolve<SceneNameMappingProvider>().GetSceneName(fakeMap.SeriesId);
|
||||
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(54321);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(null, sceneName);
|
||||
@ -91,19 +94,20 @@ public void GetSceneName_null()
|
||||
public void GetSeriesId_null()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.With(f => f.SceneName = "laworder")
|
||||
.With(f => f.CleanTitle = "laworder")
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()));
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var seriesId = mocker.Resolve<SceneNameMappingProvider>().GetSeriesId(fakeMap.SceneCleanName);
|
||||
var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId("notlaworder");
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(null, seriesId);
|
@ -56,7 +56,12 @@ public void Up(IDatabase db)
|
||||
|
||||
db.CreateTable("Config")
|
||||
.WithNotNullableColumn("Key", DbType.String).Unique()
|
||||
.WithNotNullableColumn("Value", DbType.String);
|
||||
.WithNotNullableColumn("Value", DbType.String);
|
||||
|
||||
db.CreateTable("SceneMappings")
|
||||
.WithNotNullableColumn("CleanTitle", DbType.String).Unique()
|
||||
.WithNotNullableColumn("SeriesId", DbType.Int32)
|
||||
.WithNotNullableColumn("SceneName", DbType.String);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public static void ForceSubSonicMigration(IRepository repository)
|
||||
repository.Single<QualityProfile>(1);
|
||||
repository.Single<History>(1);
|
||||
repository.Single<IndexerSetting>(1);
|
||||
repository.Single<SceneNameMapping>(1);
|
||||
repository.Single<SceneMapping>(1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,7 +211,7 @@
|
||||
<Compile Include="Providers\Jobs\IJob.cs" />
|
||||
<Compile Include="Providers\Jobs\RssSyncJob.cs" />
|
||||
<Compile Include="Providers\Jobs\UpdateInfoJob.cs" />
|
||||
<Compile Include="Providers\SceneNameMappingProvider.cs" />
|
||||
<Compile Include="Providers\SceneMappingProvider.cs" />
|
||||
<Compile Include="Providers\StatsProvider.cs" />
|
||||
<Compile Include="Repository\ExternalNotificationSetting.cs" />
|
||||
<Compile Include="Repository\JobSetting.cs" />
|
||||
@ -254,7 +254,7 @@
|
||||
<Compile Include="Repository\Quality\QualityProfile.cs" />
|
||||
<Compile Include="Repository\RootDir.cs" />
|
||||
<Compile Include="Repository\Quality\QualityTypes.cs" />
|
||||
<Compile Include="Repository\SceneNameMapping.cs" />
|
||||
<Compile Include="Repository\SceneMapping.cs" />
|
||||
<Compile Include="Repository\Series.cs" />
|
||||
<Compile Include="CentralDispatch.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -17,13 +17,13 @@ public class EpisodeSearchJob : IJob
|
||||
private readonly DownloadProvider _downloadProvider;
|
||||
private readonly IndexerProvider _indexerProvider;
|
||||
private readonly EpisodeProvider _episodeProvider;
|
||||
private readonly SceneNameMappingProvider _sceneNameMappingProvider;
|
||||
private readonly SceneMappingProvider _sceneNameMappingProvider;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public EpisodeSearchJob(InventoryProvider inventoryProvider, DownloadProvider downloadProvider,
|
||||
IndexerProvider indexerProvider, EpisodeProvider episodeProvider,
|
||||
SceneNameMappingProvider sceneNameMappingProvider)
|
||||
SceneMappingProvider sceneNameMappingProvider)
|
||||
{
|
||||
_inventoryProvider = inventoryProvider;
|
||||
_downloadProvider = downloadProvider;
|
||||
|
@ -7,9 +7,9 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||
{
|
||||
public class UpdateSceneMappingsJob : IJob
|
||||
{
|
||||
private readonly SceneNameMappingProvider _sceneNameMappingProvider;
|
||||
private readonly SceneMappingProvider _sceneNameMappingProvider;
|
||||
|
||||
public UpdateSceneMappingsJob(SceneNameMappingProvider sceneNameMappingProvider)
|
||||
public UpdateSceneMappingsJob(SceneMappingProvider sceneNameMappingProvider)
|
||||
{
|
||||
_sceneNameMappingProvider = sceneNameMappingProvider;
|
||||
}
|
||||
|
@ -7,23 +7,24 @@
|
||||
using NLog;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class SceneNameMappingProvider
|
||||
public class SceneMappingProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IRepository _repository;
|
||||
private readonly IDatabase _database;
|
||||
private readonly HttpProvider _httpProvider;
|
||||
|
||||
public SceneNameMappingProvider(IRepository repository, HttpProvider httpProvider)
|
||||
public SceneMappingProvider(IDatabase database, HttpProvider httpProvider)
|
||||
{
|
||||
_repository = repository;
|
||||
_database = database;
|
||||
_httpProvider = httpProvider;
|
||||
}
|
||||
|
||||
public SceneNameMappingProvider()
|
||||
public SceneMappingProvider()
|
||||
{
|
||||
|
||||
}
|
||||
@ -32,8 +33,8 @@ public virtual bool UpdateMappings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneNameMappings.csv");
|
||||
var newMaps = new List<SceneNameMapping>();
|
||||
var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneMappings.csv");
|
||||
var newMaps = new List<SceneMapping>();
|
||||
|
||||
using (var reader = new StringReader(mapping))
|
||||
{
|
||||
@ -44,8 +45,8 @@ public virtual bool UpdateMappings()
|
||||
var seriesId = 0;
|
||||
Int32.TryParse(split[1], out seriesId);
|
||||
|
||||
var map = new SceneNameMapping();
|
||||
map.SceneCleanName = split[0];
|
||||
var map = new SceneMapping();
|
||||
map.CleanTitle = split[0];
|
||||
map.SeriesId = seriesId;
|
||||
map.SceneName = split[2];
|
||||
|
||||
@ -54,10 +55,10 @@ public virtual bool UpdateMappings()
|
||||
}
|
||||
|
||||
Logger.Debug("Deleting all existing Scene Mappings.");
|
||||
_repository.DeleteMany<SceneNameMapping>(GetAll());
|
||||
_database.Delete<SceneMapping>(String.Empty);
|
||||
|
||||
Logger.Debug("Adding Scene Mappings");
|
||||
_repository.AddMany(newMaps);
|
||||
_database.InsertMany(newMaps);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@ -68,14 +69,14 @@ public virtual bool UpdateMappings()
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual List<SceneNameMapping> GetAll()
|
||||
public virtual List<SceneMapping> GetAll()
|
||||
{
|
||||
return _repository.All<SceneNameMapping>().ToList();
|
||||
return _database.Fetch<SceneMapping>();
|
||||
}
|
||||
|
||||
public virtual string GetSceneName(int seriesId)
|
||||
{
|
||||
var item = _repository.Single<SceneNameMapping>(s => s.SeriesId == seriesId);
|
||||
var item = _database.SingleOrDefault<SceneMapping>("WHERE SeriesId = @0", seriesId);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
||||
@ -85,7 +86,7 @@ public virtual string GetSceneName(int seriesId)
|
||||
|
||||
public virtual Nullable<Int32> GetSeriesId(string cleanName)
|
||||
{
|
||||
var item = _repository.Single<SceneNameMapping>(s => s.SceneCleanName == cleanName);
|
||||
var item = _database.SingleOrDefault<SceneMapping>("WHERE CleanTitle = @0", cleanName);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
@ -18,11 +18,11 @@ public class SeriesProvider
|
||||
private readonly TvDbProvider _tvDbProvider;
|
||||
private readonly IDatabase _database;
|
||||
private readonly QualityProvider _qualityProvider;
|
||||
private readonly SceneNameMappingProvider _sceneNameMappingProvider;
|
||||
private readonly SceneMappingProvider _sceneNameMappingProvider;
|
||||
private static readonly Regex TimeRegex = new Regex(@"^(?<time>\d+:?\d*)\W*(?<meridiem>am|pm)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public SeriesProvider(IDatabase database, ConfigProvider configProviderProvider, QualityProvider qualityProvider,
|
||||
TvDbProvider tvDbProviderProvider, SceneNameMappingProvider sceneNameMappingProvider)
|
||||
TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider)
|
||||
{
|
||||
_database = database;
|
||||
_configProvider = configProviderProvider;
|
||||
|
@ -2,14 +2,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PetaPoco;
|
||||
using SubSonic.SqlGeneration.Schema;
|
||||
|
||||
namespace NzbDrone.Core.Repository
|
||||
{
|
||||
public class SceneNameMapping
|
||||
[TableName("SceneMappings")]
|
||||
[PrimaryKey("CleanTitle", autoIncrement = false)]
|
||||
public class SceneMapping
|
||||
{
|
||||
[SubSonicPrimaryKey]
|
||||
public virtual string SceneCleanName { get; set; }
|
||||
public virtual string CleanTitle { get; set; }
|
||||
|
||||
public virtual int SeriesId { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user