mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 07:22:35 -07:00
#150 sonarr/sickrage cache checking. sickrage has a couple small items left
This commit is contained in:
parent
35310d35ed
commit
5f67302b32
17 changed files with 332 additions and 9 deletions
|
@ -39,5 +39,7 @@ namespace PlexRequests.Api.Interfaces
|
||||||
SickRagePing Ping(string apiKey, Uri baseUrl);
|
SickRagePing Ping(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl);
|
Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
|
Task<SickRageTvAdd> GetShows(string apiKey, Uri baseUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -39,5 +39,7 @@ namespace PlexRequests.Api.Interfaces
|
||||||
int seasonCount, int[] seasons, string apiKey, Uri baseUrl);
|
int seasonCount, int[] seasons, string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
|
List<Series> GetSeries(string apiKey, Uri baseUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -74,6 +74,7 @@
|
||||||
<Compile Include="SickRage\SickRageStatus.cs" />
|
<Compile Include="SickRage\SickRageStatus.cs" />
|
||||||
<Compile Include="SickRage\SickRageTvAdd.cs" />
|
<Compile Include="SickRage\SickRageTvAdd.cs" />
|
||||||
<Compile Include="Sonarr\SonarrAddSeries.cs" />
|
<Compile Include="Sonarr\SonarrAddSeries.cs" />
|
||||||
|
<Compile Include="Sonarr\SonarrAllSeries.cs" />
|
||||||
<Compile Include="Sonarr\SonarrError.cs" />
|
<Compile Include="Sonarr\SonarrError.cs" />
|
||||||
<Compile Include="Sonarr\SonarrProfile.cs" />
|
<Compile Include="Sonarr\SonarrProfile.cs" />
|
||||||
<Compile Include="Sonarr\SystemStatus.cs" />
|
<Compile Include="Sonarr\SystemStatus.cs" />
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace PlexRequests.Api.Models.Sonarr
|
namespace PlexRequests.Api.Models.Sonarr
|
||||||
{
|
{
|
||||||
|
@ -8,6 +9,17 @@ namespace PlexRequests.Api.Models.Sonarr
|
||||||
{
|
{
|
||||||
public int seasonNumber { get; set; }
|
public int seasonNumber { get; set; }
|
||||||
public bool monitored { get; set; }
|
public bool monitored { get; set; }
|
||||||
|
public Statistics statistics { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Statistics
|
||||||
|
{
|
||||||
|
public int episodeFileCount { get; set; }
|
||||||
|
public int episodeCount { get; set; }
|
||||||
|
public int totalEpisodeCount { get; set; }
|
||||||
|
public long sizeOnDisk { get; set; }
|
||||||
|
public float percentOfEpisodes { get; set; }
|
||||||
|
public DateTime previousAiring { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SonarrAddSeries
|
public class SonarrAddSeries
|
||||||
|
@ -35,7 +47,4 @@ namespace PlexRequests.Api.Models.Sonarr
|
||||||
public bool ignoreEpisodesWithoutFiles { get; set; }
|
public bool ignoreEpisodesWithoutFiles { get; set; }
|
||||||
public bool searchForMissingEpisodes { get; set; }
|
public bool searchForMissingEpisodes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
69
PlexRequests.Api.Models/Sonarr/SonarrAllSeries.cs
Normal file
69
PlexRequests.Api.Models/Sonarr/SonarrAllSeries.cs
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace PlexRequests.Api.Models.Sonarr
|
||||||
|
{
|
||||||
|
public class SonarrAllSeries
|
||||||
|
{
|
||||||
|
public List<Series> list { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Series
|
||||||
|
{
|
||||||
|
public string title { get; set; }
|
||||||
|
public List<Alternatetitle> alternateTitles { get; set; }
|
||||||
|
public string sortTitle { get; set; }
|
||||||
|
public int seasonCount { get; set; }
|
||||||
|
public int totalEpisodeCount { get; set; }
|
||||||
|
public int episodeCount { get; set; }
|
||||||
|
public int episodeFileCount { get; set; }
|
||||||
|
public long sizeOnDisk { get; set; }
|
||||||
|
public string status { get; set; }
|
||||||
|
public string overview { get; set; }
|
||||||
|
public DateTime previousAiring { get; set; }
|
||||||
|
public string network { get; set; }
|
||||||
|
public List<Image> images { get; set; }
|
||||||
|
public List<Season> seasons { get; set; }
|
||||||
|
public int year { get; set; }
|
||||||
|
public string path { get; set; }
|
||||||
|
public int profileId { get; set; }
|
||||||
|
public bool seasonFolder { get; set; }
|
||||||
|
public bool monitored { get; set; }
|
||||||
|
public bool useSceneNumbering { get; set; }
|
||||||
|
public int runtime { get; set; }
|
||||||
|
public int tvdbId { get; set; }
|
||||||
|
public int tvRageId { get; set; }
|
||||||
|
public int tvMazeId { get; set; }
|
||||||
|
public DateTime firstAired { get; set; }
|
||||||
|
public DateTime lastInfoSync { get; set; }
|
||||||
|
public string seriesType { get; set; }
|
||||||
|
public string cleanTitle { get; set; }
|
||||||
|
public string imdbId { get; set; }
|
||||||
|
public string titleSlug { get; set; }
|
||||||
|
public string certification { get; set; }
|
||||||
|
public List<string> genres { get; set; }
|
||||||
|
public List<object> tags { get; set; }
|
||||||
|
public DateTime added { get; set; }
|
||||||
|
public Ratings ratings { get; set; }
|
||||||
|
public int qualityProfileId { get; set; }
|
||||||
|
public int id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Ratings
|
||||||
|
{
|
||||||
|
public int votes { get; set; }
|
||||||
|
public float value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Alternatetitle
|
||||||
|
{
|
||||||
|
public string title { get; set; }
|
||||||
|
public int seasonNumber { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Image
|
||||||
|
{
|
||||||
|
public string coverType { get; set; }
|
||||||
|
public string url { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,5 +55,10 @@ namespace PlexRequests.Api.Mocks
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Series> GetSeries(string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,6 +38,7 @@ using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.SickRage;
|
using PlexRequests.Api.Models.SickRage;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace PlexRequests.Api
|
namespace PlexRequests.Api
|
||||||
{
|
{
|
||||||
|
@ -206,5 +207,25 @@ namespace PlexRequests.Api
|
||||||
return result;
|
return result;
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<SickRageTvAdd> GetShows(string apiKey, Uri baseUrl) // TODO: get the correct response/models from SR
|
||||||
|
{
|
||||||
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Resource = "/api/{apiKey}/?cmd=shows",
|
||||||
|
Method = Method.GET
|
||||||
|
};
|
||||||
|
request.AddUrlSegment("apiKey", apiKey);
|
||||||
|
|
||||||
|
//await Task.Run(() => Thread.Sleep(2000));
|
||||||
|
//return await Task.Run(() =>
|
||||||
|
//{
|
||||||
|
//Log.Trace("Entering `Execute<SickRageTvAdd>` in a new `Task<T>`");
|
||||||
|
var result = Api.ExecuteJson<JObject>(request, baseUrl);
|
||||||
|
|
||||||
|
//Log.Trace("Exiting `Execute<SickRageTvAdd>` and yeilding `Task<T>` result");
|
||||||
|
return null;
|
||||||
|
//}).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -36,6 +36,7 @@ using PlexRequests.Api.Models.Sonarr;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace PlexRequests.Api
|
namespace PlexRequests.Api
|
||||||
{
|
{
|
||||||
|
@ -122,5 +123,13 @@ namespace PlexRequests.Api
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Series> GetSeries(string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/series", Method = Method.GET };
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
|
||||||
|
return Api.Execute<List<Series>>(request, baseUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -29,8 +29,12 @@ namespace PlexRequests.Core
|
||||||
public class CacheKeys
|
public class CacheKeys
|
||||||
{
|
{
|
||||||
public const string TvDbToken = "TheTvDbApiToken";
|
public const string TvDbToken = "TheTvDbApiToken";
|
||||||
|
|
||||||
public const string SonarrQualityProfiles = "SonarrQualityProfiles";
|
public const string SonarrQualityProfiles = "SonarrQualityProfiles";
|
||||||
|
public const string SonarrQueued = "SonarrQueued";
|
||||||
|
|
||||||
public const string SickRageQualityProfiles = "SickRageQualityProfiles";
|
public const string SickRageQualityProfiles = "SickRageQualityProfiles";
|
||||||
|
public const string SickRageQueued = "SickRageQueued";
|
||||||
|
|
||||||
public const string CouchPotatoQualityProfiles = "CouchPotatoQualityProfiles";
|
public const string CouchPotatoQualityProfiles = "CouchPotatoQualityProfiles";
|
||||||
public const string CouchPotatoQueued = "CouchPotatoQueued";
|
public const string CouchPotatoQueued = "CouchPotatoQueued";
|
||||||
|
|
8
PlexRequests.Services/Interfaces/ISickRageCacher.cs
Normal file
8
PlexRequests.Services/Interfaces/ISickRageCacher.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace PlexRequests.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface ISickRageCacher
|
||||||
|
{
|
||||||
|
void Queued(long check);
|
||||||
|
int[] QueuedIds();
|
||||||
|
}
|
||||||
|
}
|
8
PlexRequests.Services/Interfaces/ISonarrCacher.cs
Normal file
8
PlexRequests.Services/Interfaces/ISonarrCacher.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace PlexRequests.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface ISonarrCacher
|
||||||
|
{
|
||||||
|
void Queued(long check);
|
||||||
|
int[] QueuedIds();
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,6 +55,8 @@ namespace PlexRequests.Services
|
||||||
|
|
||||||
ConfigurationReader = new ConfigurationReader();
|
ConfigurationReader = new ConfigurationReader();
|
||||||
CpCacher = new CouchPotatoCacher(new SettingsServiceV2<CouchPotatoSettings>(repo), new CouchPotatoApi(), memCache);
|
CpCacher = new CouchPotatoCacher(new SettingsServiceV2<CouchPotatoSettings>(repo), new CouchPotatoApi(), memCache);
|
||||||
|
SonarrCacher = new SonarrCacher(new SettingsServiceV2<SonarrSettings>(repo), new SonarrApi(), memCache);
|
||||||
|
SickRageCacher = new SickRageCacher(new SettingsServiceV2<SickRageSettings>(repo), new SickrageApi(), memCache);
|
||||||
HostingEnvironment.RegisterObject(this);
|
HostingEnvironment.RegisterObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +64,8 @@ namespace PlexRequests.Services
|
||||||
|
|
||||||
private IConfigurationReader ConfigurationReader { get; }
|
private IConfigurationReader ConfigurationReader { get; }
|
||||||
private ICouchPotatoCacher CpCacher { get; }
|
private ICouchPotatoCacher CpCacher { get; }
|
||||||
|
private ISonarrCacher SonarrCacher { get; }
|
||||||
|
private ISickRageCacher SickRageCacher { get; }
|
||||||
private IDisposable UpdateSubscription { get; set; }
|
private IDisposable UpdateSubscription { get; set; }
|
||||||
|
|
||||||
public void Start(Configuration c)
|
public void Start(Configuration c)
|
||||||
|
@ -69,7 +73,11 @@ namespace PlexRequests.Services
|
||||||
UpdateSubscription?.Dispose();
|
UpdateSubscription?.Dispose();
|
||||||
|
|
||||||
Task.Factory.StartNew(() => CpCacher.Queued(-1));
|
Task.Factory.StartNew(() => CpCacher.Queued(-1));
|
||||||
|
Task.Factory.StartNew(() => SonarrCacher.Queued(-1));
|
||||||
|
Task.Factory.StartNew(() => SickRageCacher.Queued(-1));
|
||||||
UpdateSubscription = Observable.Interval(c.Intervals.Notification).Subscribe(CpCacher.Queued);
|
UpdateSubscription = Observable.Interval(c.Intervals.Notification).Subscribe(CpCacher.Queued);
|
||||||
|
UpdateSubscription = Observable.Interval(c.Intervals.Notification).Subscribe(SonarrCacher.Queued);
|
||||||
|
UpdateSubscription = Observable.Interval(c.Intervals.Notification).Subscribe(SickRageCacher.Queued);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
|
|
|
@ -84,6 +84,10 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="SickRageCacher.cs" />
|
||||||
|
<Compile Include="Interfaces\ISickRageCacher.cs" />
|
||||||
|
<Compile Include="SonarrCacher.cs" />
|
||||||
|
<Compile Include="Interfaces\ISonarrCacher.cs" />
|
||||||
<Compile Include="MediaCacheService.cs" />
|
<Compile Include="MediaCacheService.cs" />
|
||||||
<Compile Include="AvailabilityUpdateService.cs" />
|
<Compile Include="AvailabilityUpdateService.cs" />
|
||||||
<Compile Include="Configuration.cs" />
|
<Compile Include="Configuration.cs" />
|
||||||
|
|
78
PlexRequests.Services/SickRageCacher.cs
Normal file
78
PlexRequests.Services/SickRageCacher.cs
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: PlexAvailabilityChecker.cs
|
||||||
|
// Created By: Jamie Rees
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
using PlexRequests.Api.Interfaces;
|
||||||
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
|
using PlexRequests.Helpers;
|
||||||
|
using PlexRequests.Services.Interfaces;
|
||||||
|
using PlexRequests.Api.Models.Movie;
|
||||||
|
using System.Linq;
|
||||||
|
using PlexRequests.Api.Models.SickRage;
|
||||||
|
|
||||||
|
namespace PlexRequests.Services
|
||||||
|
{
|
||||||
|
public class SickRageCacher : ISickRageCacher
|
||||||
|
{
|
||||||
|
public SickRageCacher(ISettingsService<SickRageSettings> srSettings, ISickRageApi srApi, ICacheProvider cache)
|
||||||
|
{
|
||||||
|
SrSettings = srSettings;
|
||||||
|
SrApi = srApi;
|
||||||
|
Cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISettingsService<SickRageSettings> SrSettings { get; }
|
||||||
|
private ICacheProvider Cache { get; }
|
||||||
|
private ISickRageApi SrApi { get; }
|
||||||
|
|
||||||
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public void Queued(long check)
|
||||||
|
{
|
||||||
|
Log.Trace("This is check no. {0}", check);
|
||||||
|
Log.Trace("Getting the settings");
|
||||||
|
|
||||||
|
var settings = SrSettings.GetSettings();
|
||||||
|
if (settings.Enabled)
|
||||||
|
{
|
||||||
|
Log.Trace("Getting all shows from SickRage");
|
||||||
|
var movies = SrApi.GetShows(settings.ApiKey, settings.FullUri);
|
||||||
|
Cache.Set(CacheKeys.SickRageQueued, movies, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we do not want to set here...
|
||||||
|
public int[] QueuedIds()
|
||||||
|
{
|
||||||
|
var tv = Cache.Get<SickRageTvAdd>(CacheKeys.SickRageQueued);
|
||||||
|
return new int[] { }; //tv != null ? tv.Select(x => x.info.tmdb_id).ToArray() : new int[] { }; // TODO: return the array of tvdb IDs from SR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
PlexRequests.Services/SonarrCacher.cs
Normal file
77
PlexRequests.Services/SonarrCacher.cs
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: PlexAvailabilityChecker.cs
|
||||||
|
// Created By: Jamie Rees
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
using PlexRequests.Api.Interfaces;
|
||||||
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
|
using PlexRequests.Helpers;
|
||||||
|
using PlexRequests.Services.Interfaces;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using PlexRequests.Api.Models.Sonarr;
|
||||||
|
|
||||||
|
namespace PlexRequests.Services
|
||||||
|
{
|
||||||
|
public class SonarrCacher : ISonarrCacher
|
||||||
|
{
|
||||||
|
public SonarrCacher(ISettingsService<SonarrSettings> sonarrSettings, ISonarrApi sonarrApi, ICacheProvider cache)
|
||||||
|
{
|
||||||
|
SonarrSettings = sonarrSettings;
|
||||||
|
SonarrApi = sonarrApi;
|
||||||
|
Cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||||
|
private ICacheProvider Cache { get; }
|
||||||
|
private ISonarrApi SonarrApi { get; }
|
||||||
|
|
||||||
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public void Queued(long check)
|
||||||
|
{
|
||||||
|
Log.Trace("This is check no. {0}", check);
|
||||||
|
Log.Trace("Getting the settings");
|
||||||
|
|
||||||
|
var settings = SonarrSettings.GetSettings();
|
||||||
|
if (settings.Enabled)
|
||||||
|
{
|
||||||
|
Log.Trace("Getting all tv series from Sonarr");
|
||||||
|
var series = SonarrApi.GetSeries(settings.ApiKey, settings.FullUri);
|
||||||
|
Cache.Set(CacheKeys.SonarrQueued, series, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we do not want to set here...
|
||||||
|
public int[] QueuedIds()
|
||||||
|
{
|
||||||
|
var series = Cache.Get<List<Series>>(CacheKeys.SonarrQueued);
|
||||||
|
return series != null ? series.Select(x => x.tvdbId).ToArray() : new int[] { };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,6 +89,8 @@ namespace PlexRequests.UI
|
||||||
// Services
|
// Services
|
||||||
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
|
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
|
||||||
container.Register<ICouchPotatoCacher, CouchPotatoCacher>();
|
container.Register<ICouchPotatoCacher, CouchPotatoCacher>();
|
||||||
|
container.Register<ISonarrCacher, SonarrCacher>();
|
||||||
|
container.Register<ISickRageCacher, SickRageCacher>();
|
||||||
container.Register<IConfigurationReader, ConfigurationReader>();
|
container.Register<IConfigurationReader, ConfigurationReader>();
|
||||||
container.Register<IIntervals, UpdateInterval>();
|
container.Register<IIntervals, UpdateInterval>();
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,8 @@ namespace PlexRequests.UI.Modules
|
||||||
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
|
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
|
||||||
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
|
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
|
||||||
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
|
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
|
||||||
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService, ICouchPotatoCacher cpCacher) : base("search")
|
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService,
|
||||||
|
ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher) : base("search")
|
||||||
{
|
{
|
||||||
CpService = cpSettings;
|
CpService = cpSettings;
|
||||||
PrService = prSettings;
|
PrService = prSettings;
|
||||||
|
@ -70,6 +71,8 @@ namespace PlexRequests.UI.Modules
|
||||||
Cache = cache;
|
Cache = cache;
|
||||||
Checker = checker;
|
Checker = checker;
|
||||||
CpCacher = cpCacher;
|
CpCacher = cpCacher;
|
||||||
|
SonarrCacher = sonarrCacher;
|
||||||
|
SickRageCacher = sickRageCacher;
|
||||||
RequestService = request;
|
RequestService = request;
|
||||||
SonarrApi = sonarrApi;
|
SonarrApi = sonarrApi;
|
||||||
SonarrService = sonarrSettings;
|
SonarrService = sonarrSettings;
|
||||||
|
@ -111,6 +114,8 @@ namespace PlexRequests.UI.Modules
|
||||||
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
|
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
|
||||||
private IAvailabilityChecker Checker { get; }
|
private IAvailabilityChecker Checker { get; }
|
||||||
private ICouchPotatoCacher CpCacher { get; }
|
private ICouchPotatoCacher CpCacher { get; }
|
||||||
|
private ISonarrCacher SonarrCacher { get; }
|
||||||
|
private ISickRageCacher SickRageCacher { get; }
|
||||||
private IMusicBrainzApi MusicBrainzApi { get; }
|
private IMusicBrainzApi MusicBrainzApi { get; }
|
||||||
private IHeadphonesApi HeadphonesApi { get; }
|
private IHeadphonesApi HeadphonesApi { get; }
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
@ -277,6 +282,8 @@ namespace PlexRequests.UI.Modules
|
||||||
return Response.AsJson("");
|
return Response.AsJson("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int[] sonarrCached = SonarrCacher.QueuedIds();
|
||||||
|
int[] sickRageCache = SickRageCacher.QueuedIds(); // consider just merging sonarr/sickrage arrays
|
||||||
|
|
||||||
var viewTv = new List<SearchTvShowViewModel>();
|
var viewTv = new List<SearchTvShowViewModel>();
|
||||||
foreach (var t in apiTv)
|
foreach (var t in apiTv)
|
||||||
|
@ -299,13 +306,22 @@ namespace PlexRequests.UI.Modules
|
||||||
Status = t.show.status
|
Status = t.show.status
|
||||||
};
|
};
|
||||||
|
|
||||||
if (t.show.externals.thetvdb != null && dbTv.ContainsKey((int)t.show.externals.thetvdb))
|
if (t.show.externals.thetvdb != null)
|
||||||
{
|
{
|
||||||
var dbt = dbTv[(int)t.show.externals.thetvdb];
|
int tvdbid = (int)t.show.externals.thetvdb;
|
||||||
|
|
||||||
viewT.Requested = true;
|
if (dbTv.ContainsKey(tvdbid))
|
||||||
viewT.Approved = dbt.Approved;
|
{
|
||||||
viewT.Available = dbt.Available;
|
var dbt = dbTv[tvdbid];
|
||||||
|
|
||||||
|
viewT.Requested = true;
|
||||||
|
viewT.Approved = dbt.Approved;
|
||||||
|
viewT.Available = dbt.Available;
|
||||||
|
}
|
||||||
|
else if (sonarrCached.Contains(tvdbid) || sickRageCache.Contains(tvdbid)) // compare to the sonarr/sickrage db
|
||||||
|
{
|
||||||
|
viewT.Requested = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewTv.Add(viewT);
|
viewTv.Add(viewT);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue