You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.5 KiB
96 lines
2.5 KiB
12 years ago
|
using System;
|
||
12 years ago
|
using System.Linq;
|
||
12 years ago
|
using NLog;
|
||
|
using NzbDrone.Core.Lifecycle;
|
||
12 years ago
|
using NzbDrone.Core.Tv;
|
||
12 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.DataAugmentation.Scene
|
||
12 years ago
|
{
|
||
12 years ago
|
public interface ISceneMappingService
|
||
|
{
|
||
|
void UpdateMappings();
|
||
12 years ago
|
string GetSceneName(int seriesId, int seasonNumber = -1);
|
||
12 years ago
|
Nullable<int> GetTvDbId(string cleanName);
|
||
12 years ago
|
string GetCleanName(int tvdbId);
|
||
|
}
|
||
|
|
||
|
public class SceneMappingService : IInitializable, ISceneMappingService
|
||
12 years ago
|
{
|
||
|
private readonly ISceneMappingRepository _repository;
|
||
|
private readonly ISceneMappingProxy _sceneMappingProxy;
|
||
12 years ago
|
private readonly ISeriesService _seriesService;
|
||
12 years ago
|
private readonly Logger _logger;
|
||
|
|
||
12 years ago
|
public SceneMappingService(ISceneMappingRepository repository, ISceneMappingProxy sceneMappingProxy, ISeriesService seriesService, Logger logger)
|
||
12 years ago
|
{
|
||
|
_repository = repository;
|
||
|
_sceneMappingProxy = sceneMappingProxy;
|
||
12 years ago
|
_seriesService = seriesService;
|
||
12 years ago
|
_logger = logger;
|
||
|
}
|
||
|
|
||
|
public void UpdateMappings()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var mappings = _sceneMappingProxy.Fetch();
|
||
|
|
||
12 years ago
|
if (mappings.Any())
|
||
|
{
|
||
|
_repository.Purge();
|
||
|
_repository.InsertMany(mappings);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_logger.Warn("Received empty list of mapping. will not update.");
|
||
|
}
|
||
12 years ago
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
12 years ago
|
_logger.ErrorException("Failed to Update Scene Mappings:", ex);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
public string GetSceneName(int seriesId, int seasonNumber = -1)
|
||
12 years ago
|
{
|
||
12 years ago
|
var tvDbId = _seriesService.FindByTvdbId(seriesId).TvDbId;
|
||
|
|
||
|
var mapping = _repository.FindByTvdbId(tvDbId);
|
||
12 years ago
|
|
||
12 years ago
|
if (mapping == null) return null;
|
||
12 years ago
|
|
||
|
return mapping.SceneName;
|
||
|
}
|
||
|
|
||
12 years ago
|
|
||
|
|
||
|
public Nullable<Int32> GetTvDbId(string cleanName)
|
||
12 years ago
|
{
|
||
|
var mapping = _repository.FindByCleanTitle(cleanName);
|
||
|
|
||
|
if (mapping == null)
|
||
|
return null;
|
||
|
|
||
|
return mapping.TvdbId;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
public string GetCleanName(int tvdbId)
|
||
12 years ago
|
{
|
||
|
var mapping = _repository.FindByTvdbId(tvdbId);
|
||
|
|
||
|
if (mapping == null) return null;
|
||
|
|
||
|
return mapping.CleanTitle;
|
||
|
}
|
||
|
|
||
|
public void Init()
|
||
|
{
|
||
|
if (!_repository.HasItems())
|
||
|
{
|
||
|
UpdateMappings();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|