mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
removed sqlce
This commit is contained in:
parent
b76c6329fe
commit
beb2f7c7fd
105 changed files with 410 additions and 5340 deletions
48
NzbDrone.Core/ReferenceData/DailySeriesDataProxy.cs
Normal file
48
NzbDrone.Core/ReferenceData/DailySeriesDataProxy.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.ReferenceData
|
||||
{
|
||||
|
||||
public interface IDailySeriesDataProxy
|
||||
{
|
||||
IEnumerable<int> GetDailySeriesIds();
|
||||
}
|
||||
|
||||
public class DailySeriesDataProxy : IDailySeriesDataProxy
|
||||
{
|
||||
private readonly HttpProvider _httpProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public DailySeriesDataProxy(HttpProvider httpProvider, IConfigService configService, Logger logger)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<int> GetDailySeriesIds()
|
||||
{
|
||||
try
|
||||
{
|
||||
var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds");
|
||||
|
||||
var seriesIds = JsonConvert.DeserializeObject<List<int>>(dailySeriesIds);
|
||||
|
||||
return seriesIds;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Failed to get Daily Series", ex);
|
||||
return new List<int>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using PetaPoco;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.ReferenceData
|
||||
{
|
||||
public class DailySeriesService
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
private readonly HttpProvider _httpProvider;
|
||||
private readonly ConfigProvider _configProvider;
|
||||
private readonly IDailySeriesDataProxy _proxy;
|
||||
private readonly ISeriesService _seriesService;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public DailySeriesService(IDatabase database, HttpProvider httpProvider, ConfigProvider configProvider)
|
||||
public DailySeriesService(IDailySeriesDataProxy proxy, ISeriesService seriesService)
|
||||
{
|
||||
_database = database;
|
||||
_httpProvider = httpProvider;
|
||||
_configProvider = configProvider;
|
||||
_proxy = proxy;
|
||||
_seriesService = seriesService;
|
||||
}
|
||||
|
||||
public virtual void UpdateDailySeries()
|
||||
{
|
||||
//Update all series in DB
|
||||
//DailySeries.csv
|
||||
var dailySeries = _proxy.GetDailySeriesIds();
|
||||
|
||||
var seriesIds = GetDailySeriesIds();
|
||||
|
||||
if (seriesIds.Any())
|
||||
foreach (var tvdbId in dailySeries)
|
||||
{
|
||||
var dailySeriesString = String.Join(", ", seriesIds);
|
||||
var sql = String.Format("UPDATE Series SET IsDaily = 1 WHERE SeriesId in ({0})", dailySeriesString);
|
||||
var series = _seriesService.FindByTvdbId(tvdbId);
|
||||
|
||||
_database.Execute(sql);
|
||||
if (series != null)
|
||||
{
|
||||
_seriesService.SetSeriesType(series.Id, SeriesType.Daily);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSeriesDaily(int seriesId)
|
||||
{
|
||||
return GetDailySeriesIds().Contains(seriesId);
|
||||
}
|
||||
|
||||
public List<int> GetDailySeriesIds()
|
||||
{
|
||||
try
|
||||
{
|
||||
var dailySeriesIds = _httpProvider.DownloadString(_configProvider.ServiceRootUrl + "/DailySeries/AllIds");
|
||||
|
||||
var seriesIds = JsonConvert.DeserializeObject<List<int>>(dailySeriesIds);
|
||||
|
||||
return seriesIds;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WarnException("Failed to get Daily Series", ex);
|
||||
return new List<int>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
NzbDrone.Core/ReferenceData/SceneMapping.cs
Normal file
13
NzbDrone.Core/ReferenceData/SceneMapping.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.ReferenceData
|
||||
{
|
||||
public class SceneMapping : ModelBase
|
||||
{
|
||||
public string CleanTitle { get; set; }
|
||||
public int TvdbId { get; set; }
|
||||
public string SceneName { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
}
|
||||
}
|
73
NzbDrone.Core/ReferenceData/SceneMappingProvider.cs
Normal file
73
NzbDrone.Core/ReferenceData/SceneMappingProvider.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
|
||||
namespace NzbDrone.Core.ReferenceData
|
||||
{
|
||||
public class SceneMappingService : IInitializable
|
||||
{
|
||||
private readonly ISceneMappingRepository _repository;
|
||||
private readonly ISceneMappingProxy _sceneMappingProxy;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SceneMappingService(ISceneMappingRepository repository, ISceneMappingProxy sceneMappingProxy, Logger logger)
|
||||
{
|
||||
_repository = repository;
|
||||
_sceneMappingProxy = sceneMappingProxy;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void UpdateMappings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mappings = _sceneMappingProxy.Fetch();
|
||||
|
||||
_repository.Purge();
|
||||
_repository.InsertMany(mappings);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.InfoException("Failed to Update Scene Mappings:", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string GetSceneName(int tvdbId, int seasonNumber = -1)
|
||||
{
|
||||
var mapping = _repository.FindByTvdbId(tvdbId);
|
||||
|
||||
if(mapping == null) return null;
|
||||
|
||||
return mapping.SceneName;
|
||||
}
|
||||
|
||||
public virtual Nullable<Int32> GetTvDbId(string cleanName)
|
||||
{
|
||||
var mapping = _repository.FindByCleanTitle(cleanName);
|
||||
|
||||
if (mapping == null)
|
||||
return null;
|
||||
|
||||
return mapping.TvdbId;
|
||||
}
|
||||
|
||||
|
||||
public virtual string GetCleanName(int tvdbId)
|
||||
{
|
||||
var mapping = _repository.FindByTvdbId(tvdbId);
|
||||
|
||||
if (mapping == null) return null;
|
||||
|
||||
return mapping.CleanTitle;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (!_repository.HasItems())
|
||||
{
|
||||
UpdateMappings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
NzbDrone.Core/ReferenceData/SceneMappingProxy.cs
Normal file
49
NzbDrone.Core/ReferenceData/SceneMappingProxy.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.ReferenceData
|
||||
{
|
||||
public interface ISceneMappingProxy
|
||||
{
|
||||
List<SceneMapping> Fetch();
|
||||
}
|
||||
|
||||
public class SceneMappingProxy : ISceneMappingProxy
|
||||
{
|
||||
private readonly HttpProvider _httpProvider;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public SceneMappingProxy(HttpProvider httpProvider, IConfigService configService)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
public List<SceneMapping> Fetch()
|
||||
{
|
||||
var mappingsJson = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/SceneMapping/Active");
|
||||
return JsonConvert.DeserializeObject<List<SceneMapping>>(mappingsJson);
|
||||
}
|
||||
|
||||
|
||||
/* public virtual bool SubmitMapping(int id, string postTitle)
|
||||
{
|
||||
Logger.Trace("Parsing example post");
|
||||
var episodeParseResult = Parser.ParseTitle(postTitle);
|
||||
var cleanTitle = episodeParseResult.CleanTitle;
|
||||
var title = episodeParseResult.SeriesTitle.Replace('.', ' ');
|
||||
Logger.Trace("Example post parsed. CleanTitle: {0}, Title: {1}", cleanTitle, title);
|
||||
|
||||
var newMapping = String.Format("/SceneMapping/AddPending?cleanTitle={0}&id={1}&title={2}", cleanTitle, id, title);
|
||||
var response = _httpProvider.DownloadString(_configService.ServiceRootUrl + newMapping);
|
||||
|
||||
if (JsonConvert.DeserializeObject<String>(response).Equals("Ok"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
}
|
30
NzbDrone.Core/ReferenceData/SceneMappingRepository.cs
Normal file
30
NzbDrone.Core/ReferenceData/SceneMappingRepository.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.ReferenceData
|
||||
{
|
||||
public interface ISceneMappingRepository : IBasicRepository<SceneMapping>
|
||||
{
|
||||
SceneMapping FindByTvdbId(int tvdbId);
|
||||
SceneMapping FindByCleanTitle(string cleanTitle);
|
||||
|
||||
}
|
||||
|
||||
public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository
|
||||
{
|
||||
public SceneMappingRepository(IObjectDatabase objectDatabase)
|
||||
: base(objectDatabase)
|
||||
{
|
||||
}
|
||||
|
||||
public SceneMapping FindByTvdbId(int tvdbId)
|
||||
{
|
||||
return Queryable.SingleOrDefault(c => c.TvdbId == tvdbId);
|
||||
}
|
||||
|
||||
public SceneMapping FindByCleanTitle(string cleanTitle)
|
||||
{
|
||||
return Queryable.SingleOrDefault(c => c.CleanTitle == cleanTitle);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue