Skip to content

Commit

Permalink
#150 sonarr/sickrage cache checking. sickrage has a couple small item…
Browse files Browse the repository at this point in the history
…s left
  • Loading branch information
Drewster727 committed Apr 8, 2016
1 parent 35310d3 commit 5f67302
Show file tree
Hide file tree
Showing 17 changed files with 332 additions and 9 deletions.
2 changes: 2 additions & 0 deletions PlexRequests.Api.Interfaces/ISickRageApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ Task<SickRageTvAdd> AddSeries(int tvdbId, int seasoncount, int[] seasons, string
SickRagePing Ping(string apiKey, Uri baseUrl);

Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl);

Task<SickRageTvAdd> GetShows(string apiKey, Uri baseUrl);
}
}
2 changes: 2 additions & 0 deletions PlexRequests.Api.Interfaces/ISonarrApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFo
int seasonCount, int[] seasons, string apiKey, Uri baseUrl);

SystemStatus SystemStatus(string apiKey, Uri baseUrl);

List<Series> GetSeries(string apiKey, Uri baseUrl);
}
}
1 change: 1 addition & 0 deletions PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="SickRage\SickRageStatus.cs" />
<Compile Include="SickRage\SickRageTvAdd.cs" />
<Compile Include="Sonarr\SonarrAddSeries.cs" />
<Compile Include="Sonarr\SonarrAllSeries.cs" />
<Compile Include="Sonarr\SonarrError.cs" />
<Compile Include="Sonarr\SonarrProfile.cs" />
<Compile Include="Sonarr\SystemStatus.cs" />
Expand Down
15 changes: 12 additions & 3 deletions PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
using System.Collections.Generic;

using Newtonsoft.Json;
using System;

namespace PlexRequests.Api.Models.Sonarr
{
public class Season
{
public int seasonNumber { 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
Expand Down Expand Up @@ -35,7 +47,4 @@ public class AddOptions
public bool ignoreEpisodesWithoutFiles { get; set; }
public bool searchForMissingEpisodes { get; set; }
}



}
69 changes: 69 additions & 0 deletions PlexRequests.Api.Models/Sonarr/SonarrAllSeries.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
5 changes: 5 additions & 0 deletions PlexRequests.Api/Mocks/MockSonarrApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
{
throw new NotImplementedException();
}

public List<Series> GetSeries(string apiKey, Uri baseUrl)
{
throw new NotImplementedException();
}
}
}
21 changes: 21 additions & 0 deletions PlexRequests.Api/SickrageApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using PlexRequests.Api.Models.SickRage;
using PlexRequests.Helpers;
using RestSharp;
using Newtonsoft.Json.Linq;

namespace PlexRequests.Api
{
Expand Down Expand Up @@ -206,5 +207,25 @@ public async Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey
return result;
}).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);

This comment has been minimized.

Copy link
@Drewster727

Drewster727 Apr 8, 2016

Contributor

@tidusjar need to return an actual model (array of shows?) instead of a JObject. The call works, just need to deserialize.


//Log.Trace("Exiting `Execute<SickRageTvAdd>` and yeilding `Task<T>` result");
return null;
//}).ConfigureAwait(false);
}
}
}
9 changes: 9 additions & 0 deletions PlexRequests.Api/SonarrApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using PlexRequests.Helpers;

using RestSharp;
using Newtonsoft.Json.Linq;

namespace PlexRequests.Api
{
Expand Down Expand Up @@ -122,5 +123,13 @@ public SystemStatus SystemStatus(string apiKey, Uri baseUrl)

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);
}
}
}
4 changes: 4 additions & 0 deletions PlexRequests.Core/CacheKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ namespace PlexRequests.Core
public class CacheKeys
{
public const string TvDbToken = "TheTvDbApiToken";

public const string SonarrQualityProfiles = "SonarrQualityProfiles";
public const string SonarrQueued = "SonarrQueued";

public const string SickRageQualityProfiles = "SickRageQualityProfiles";
public const string SickRageQueued = "SickRageQueued";

public const string CouchPotatoQualityProfiles = "CouchPotatoQualityProfiles";
public const string CouchPotatoQueued = "CouchPotatoQueued";
Expand Down
8 changes: 8 additions & 0 deletions PlexRequests.Services/Interfaces/ISickRageCacher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace PlexRequests.Services.Interfaces
{
public interface ISickRageCacher
{
void Queued(long check);
int[] QueuedIds();
}
}
8 changes: 8 additions & 0 deletions PlexRequests.Services/Interfaces/ISonarrCacher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace PlexRequests.Services.Interfaces
{
public interface ISonarrCacher
{
void Queued(long check);
int[] QueuedIds();
}
}
8 changes: 8 additions & 0 deletions PlexRequests.Services/MediaCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ public MediaCacheService()

ConfigurationReader = new ConfigurationReader();
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);
}

private static Logger Log = LogManager.GetCurrentClassLogger();

private IConfigurationReader ConfigurationReader { get; }
private ICouchPotatoCacher CpCacher { get; }
private ISonarrCacher SonarrCacher { get; }
private ISickRageCacher SickRageCacher { get; }
private IDisposable UpdateSubscription { get; set; }

public void Start(Configuration c)
{
UpdateSubscription?.Dispose();

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(SonarrCacher.Queued);
UpdateSubscription = Observable.Interval(c.Intervals.Notification).Subscribe(SickRageCacher.Queued);
}

public void Execute()
Expand Down
4 changes: 4 additions & 0 deletions PlexRequests.Services/PlexRequests.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<Reference Include="System.Xml" />
</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="AvailabilityUpdateService.cs" />
<Compile Include="Configuration.cs" />
Expand Down
78 changes: 78 additions & 0 deletions PlexRequests.Services/SickRageCacher.cs
Original file line number Diff line number Diff line change
@@ -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

This comment has been minimized.

Copy link
@Drewster727

Drewster727 Apr 8, 2016

Contributor

@tidusjar need to return the actual data once we get the api call working (and deserializing)

}
}
}
Loading

0 comments on commit 5f67302

Please sign in to comment.