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

This commit is contained in:
Mark McDowall 2012-01-12 19:22:28 -08:00
parent 42554b815a
commit afb8305c00
6 changed files with 50 additions and 40 deletions

View File

@ -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

View 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"
}
]

View File

@ -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">

View File

@ -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 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//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 @@ namespace NzbDrone.Core.Test.ProviderTests
.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 @@ namespace NzbDrone.Core.Test.ProviderTests
.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 @@ namespace NzbDrone.Core.Test.ProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
WithRealDb(); WithRealDb();
WithValidCsv(); WithValidJson();
//Act //Act
Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty(); Mocker.Resolve<SceneMappingProvider>().UpdateIfEmpty();

View File

@ -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 @@ namespace NzbDrone.Core.Providers
{ {
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)

View File

@ -1,4 +1,5 @@
using PetaPoco; using Newtonsoft.Json;
using PetaPoco;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
{ {
@ -8,8 +9,10 @@ namespace NzbDrone.Core.Repository
{ {
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; }
} }
} }