mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
Renamed SceneNameMapping to SceneMapping.
SceneMappingProvider moved to PetaPoco.
This commit is contained in:
parent
310c317361
commit
ab26d2dd61
11 changed files with 63 additions and 50 deletions
97
NzbDrone.Core/Providers/SceneMappingProvider.cs
Normal file
97
NzbDrone.Core/Providers/SceneMappingProvider.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class SceneMappingProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IDatabase _database;
|
||||
private readonly HttpProvider _httpProvider;
|
||||
|
||||
public SceneMappingProvider(IDatabase database, HttpProvider httpProvider)
|
||||
{
|
||||
_database = database;
|
||||
_httpProvider = httpProvider;
|
||||
}
|
||||
|
||||
public SceneMappingProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool UpdateMappings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mapping = _httpProvider.DownloadString("http://vps.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(',');
|
||||
var seriesId = 0;
|
||||
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.");
|
||||
_database.Delete<SceneMapping>(String.Empty);
|
||||
|
||||
Logger.Debug("Adding Scene Mappings");
|
||||
_database.InsertMany(newMaps);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.InfoException("Failed to Update Scene Mappings", ex);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual List<SceneMapping> GetAll()
|
||||
{
|
||||
return _database.Fetch<SceneMapping>();
|
||||
}
|
||||
|
||||
public virtual string GetSceneName(int seriesId)
|
||||
{
|
||||
var item = _database.SingleOrDefault<SceneMapping>("WHERE SeriesId = @0", seriesId);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return item.SceneName;
|
||||
}
|
||||
|
||||
public virtual Nullable<Int32> GetSeriesId(string cleanName)
|
||||
{
|
||||
var item = _database.SingleOrDefault<SceneMapping>("WHERE CleanTitle = @0", cleanName);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return item.SeriesId;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue