mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02: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>
|
||||
<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 @@ public void UpdateMappings_should_add_all_mappings_to_database()
|
||||
{
|
||||
//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 @@ public void UpdateMappings_should_overwrite_existing_mappings()
|
||||
.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 @@ public void UpdateMappings_should_not_delete_if_csv_download_fails()
|
||||
.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 @@ public void UpdateIfEmpty_should_not_update_if_count_is_not_zero()
|
||||
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 @@ public void UpdateIfEmpty_should_update_if_count_is_zero()
|
||||
{
|
||||
//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 @@ public virtual bool UpdateMappings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mapping = _httpProvider.DownloadString("http://www.nzbdrone.com/SceneMappings.csv");
|
||||
var newMaps = new List<SceneMapping>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
const string url = "http://services.nzbdrone.com/SceneMapping/Active";
|
||||
|
||||
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 @@ public class SceneMapping
|
||||
{
|
||||
public string CleanTitle { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "Id")]
|
||||
public int SeriesId { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "Title")]
|
||||
public string SceneName { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user