mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
SceneMapping will use the JSON API instead of CSV file now.
This commit is contained in:
parent
42554b815a
commit
afb8305c00
@ -1,5 +0,0 @@
|
|||||||
csinewyork,73696,CSI
|
|
||||||
csiny,73696,CSI
|
|
||||||
csi,72546,CSI
|
|
||||||
csilasvegas,72546,CSI
|
|
||||||
archer,110381,Archer
|
|
|
27
NzbDrone.Core.Test/Files/SceneMappings.json
Normal file
27
NzbDrone.Core.Test/Files/SceneMappings.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"CleanTitle": "csinewyork",
|
||||||
|
"Id": "73696",
|
||||||
|
"Title": "CSI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CleanTitle": "csiny",
|
||||||
|
"Id": "73696",
|
||||||
|
"Title": "CSI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CleanTitle": "csi",
|
||||||
|
"Id": "72546",
|
||||||
|
"Title": "CSI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CleanTitle": "csilasvegas",
|
||||||
|
"Id": "72546",
|
||||||
|
"Title": "CSI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CleanTitle": "archer",
|
||||||
|
"Id": "110381",
|
||||||
|
"Title": "Archer"
|
||||||
|
}
|
||||||
|
]
|
@ -235,7 +235,7 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<None Include="Files\SceneMappings.csv">
|
<None Include="Files\SceneMappings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="Files\TestArchive.zip">
|
<None Include="Files\TestArchive.zip">
|
||||||
|
@ -17,16 +17,16 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class SceneMappingProviderTest : CoreTest
|
public class SceneMappingProviderTest : CoreTest
|
||||||
{
|
{
|
||||||
private const string SceneMappingUrl = "http://www.nzbdrone.com/SceneMappings.csv";
|
private const string SceneMappingUrl = "http://services.nzbdrone.com/SceneMapping/Active";
|
||||||
|
|
||||||
private void WithValidCsv()
|
private void WithValidJson()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadString(SceneMappingUrl))
|
.Setup(s => s.DownloadString(SceneMappingUrl))
|
||||||
.Returns(File.ReadAllText(@".\Files\SceneMappings.csv"));
|
.Returns(File.ReadAllText(@".\Files\SceneMappings.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WithErrorDownloadingCsv()
|
private void WithErrorDownloadingJson()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadString(SceneMappingUrl))
|
.Setup(s => s.DownloadString(SceneMappingUrl))
|
||||||
@ -163,13 +163,13 @@ public void UpdateMappings_should_add_all_mappings_to_database()
|
|||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
WithValidCsv();
|
WithValidJson();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
|
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Once());
|
Mocker.Verify<HttpProvider>(v => v.DownloadString(SceneMappingUrl), Times.Once());
|
||||||
var result = Db.Fetch<SceneMapping>();
|
var result = Db.Fetch<SceneMapping>();
|
||||||
result.Should().HaveCount(5);
|
result.Should().HaveCount(5);
|
||||||
}
|
}
|
||||||
@ -185,14 +185,14 @@ public void UpdateMappings_should_overwrite_existing_mappings()
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
WithValidCsv();
|
WithValidJson();
|
||||||
Db.Insert(fakeMap);
|
Db.Insert(fakeMap);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
|
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Once());
|
Mocker.Verify<HttpProvider>(v => v.DownloadString(SceneMappingUrl), Times.Once());
|
||||||
var result = Db.Fetch<SceneMapping>();
|
var result = Db.Fetch<SceneMapping>();
|
||||||
result.Should().HaveCount(5);
|
result.Should().HaveCount(5);
|
||||||
}
|
}
|
||||||
@ -208,14 +208,14 @@ public void UpdateMappings_should_not_delete_if_csv_download_fails()
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
WithErrorDownloadingCsv();
|
WithErrorDownloadingJson();
|
||||||
Db.Insert(fakeMap);
|
Db.Insert(fakeMap);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
|
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Once());
|
Mocker.Verify<HttpProvider>(v => v.DownloadString(SceneMappingUrl), Times.Once());
|
||||||
var result = Db.Fetch<SceneMapping>();
|
var result = Db.Fetch<SceneMapping>();
|
||||||
result.Should().HaveCount(1);
|
result.Should().HaveCount(1);
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ public void UpdateIfEmpty_should_not_update_if_count_is_not_zero()
|
|||||||
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
|
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Never());
|
Mocker.Verify<HttpProvider>(v => v.DownloadString(SceneMappingUrl), Times.Never());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -245,7 +245,7 @@ public void UpdateIfEmpty_should_update_if_count_is_zero()
|
|||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
WithValidCsv();
|
WithValidJson();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
|
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
@ -29,32 +30,16 @@ public virtual bool UpdateMappings()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mapping = _httpProvider.DownloadString("http://www.nzbdrone.com/SceneMappings.csv");
|
const string url = "http://services.nzbdrone.com/SceneMapping/Active";
|
||||||
var newMaps = new List<SceneMapping>();
|
|
||||||
|
var mappingsJson = _httpProvider.DownloadString(url);
|
||||||
using (var reader = new StringReader(mapping))
|
var mappings = JsonConvert.DeserializeObject<List<SceneMapping>>(mappingsJson);
|
||||||
{
|
|
||||||
string line;
|
|
||||||
while ((line = reader.ReadLine()) != null)
|
|
||||||
{
|
|
||||||
var split = line.Split(',');
|
|
||||||
int seriesId;
|
|
||||||
Int32.TryParse(split[1], out seriesId);
|
|
||||||
|
|
||||||
var map = new SceneMapping();
|
|
||||||
map.CleanTitle = split[0];
|
|
||||||
map.SeriesId = seriesId;
|
|
||||||
map.SceneName = split[2];
|
|
||||||
|
|
||||||
newMaps.Add(map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Debug("Deleting all existing Scene Mappings.");
|
Logger.Debug("Deleting all existing Scene Mappings.");
|
||||||
_database.Delete<SceneMapping>(String.Empty);
|
_database.Delete<SceneMapping>(String.Empty);
|
||||||
|
|
||||||
Logger.Debug("Adding Scene Mappings");
|
Logger.Debug("Adding Scene Mappings");
|
||||||
_database.InsertMany(newMaps);
|
_database.InsertMany(mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using PetaPoco;
|
using Newtonsoft.Json;
|
||||||
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Repository
|
namespace NzbDrone.Core.Repository
|
||||||
{
|
{
|
||||||
@ -8,8 +9,10 @@ public class SceneMapping
|
|||||||
{
|
{
|
||||||
public string CleanTitle { get; set; }
|
public string CleanTitle { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "Id")]
|
||||||
public int SeriesId { get; set; }
|
public int SeriesId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "Title")]
|
||||||
public string SceneName { get; set; }
|
public string SceneName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user