SceneMapping will use the JSON API instead of CSV file now.

pull/4/head
Mark McDowall 13 years ago
parent 42554b815a
commit afb8305c00

@ -1,5 +0,0 @@
csinewyork,73696,CSI
csiny,73696,CSI
csi,72546,CSI
csilasvegas,72546,CSI
archer,110381,Archer
1 csinewyork 73696 CSI
2 csiny 73696 CSI
3 csi 72546 CSI
4 csilasvegas 72546 CSI
5 archer 110381 Archer

@ -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>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Files\SceneMappings.csv">
<None Include="Files\SceneMappings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Files\TestArchive.zip">

@ -17,16 +17,16 @@ namespace NzbDrone.Core.Test.ProviderTests
// ReSharper disable InconsistentNaming
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>()
.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>()
.Setup(s => s.DownloadString(SceneMappingUrl))
@ -163,13 +163,13 @@ namespace NzbDrone.Core.Test.ProviderTests
{
//Setup
WithRealDb();
WithValidCsv();
WithValidJson();
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
//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>();
result.Should().HaveCount(5);
}
@ -185,14 +185,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build();
WithRealDb();
WithValidCsv();
WithValidJson();
Db.Insert(fakeMap);
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
//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>();
result.Should().HaveCount(5);
}
@ -208,14 +208,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build();
WithRealDb();
WithErrorDownloadingCsv();
WithErrorDownloadingJson();
Db.Insert(fakeMap);
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateMappings();
//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>();
result.Should().HaveCount(1);
}
@ -237,7 +237,7 @@ namespace NzbDrone.Core.Test.ProviderTests
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();
//Assert
Mocker.Verify<HttpProvider>(v => v.DownloadString(It.IsAny<string>()), Times.Never());
Mocker.Verify<HttpProvider>(v => v.DownloadString(SceneMappingUrl), Times.Never());
}
[Test]
@ -245,7 +245,7 @@ namespace NzbDrone.Core.Test.ProviderTests
{
//Setup
WithRealDb();
WithValidCsv();
WithValidJson();
//Act
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using NLog;
using Newtonsoft.Json;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using PetaPoco;
@ -29,32 +30,16 @@ namespace NzbDrone.Core.Providers
{
try
{
var mapping = _httpProvider.DownloadString("http://www.nzbdrone.com/SceneMappings.csv");
var newMaps = new List<SceneMapping>();
const string url = "http://services.nzbdrone.com/SceneMapping/Active";
using (var reader = new StringReader(mapping))
{
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);
}
}
var mappingsJson = _httpProvider.DownloadString(url);
var mappings = JsonConvert.DeserializeObject<List<SceneMapping>>(mappingsJson);
Logger.Debug("Deleting all existing Scene Mappings.");
_database.Delete<SceneMapping>(String.Empty);
Logger.Debug("Adding Scene Mappings");
_database.InsertMany(newMaps);
_database.InsertMany(mappings);
}
catch (Exception ex)

@ -1,4 +1,5 @@
using PetaPoco;
using Newtonsoft.Json;
using PetaPoco;
namespace NzbDrone.Core.Repository
{
@ -8,8 +9,10 @@ namespace NzbDrone.Core.Repository
{
public string CleanTitle { get; set; }
[JsonProperty(PropertyName = "Id")]
public int SeriesId { get; set; }
[JsonProperty(PropertyName = "Title")]
public string SceneName { get; set; }
}
}
Loading…
Cancel
Save