mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
parent
605f6f18fb
commit
14fddfc118
19 changed files with 953 additions and 541 deletions
|
@ -41,5 +41,7 @@ namespace PlexRequests.Api.Interfaces
|
|||
PlexLibraries GetLibrarySections(string authToken, Uri plexFullHost);
|
||||
PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId);
|
||||
PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId);
|
||||
PlexEpisodeMetadata GetEpisodeMetaData(string authToken, Uri host, string ratingKey);
|
||||
PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount);
|
||||
}
|
||||
}
|
81
PlexRequests.Api.Models/Plex/PlexEpisodeMetadata.cs
Normal file
81
PlexRequests.Api.Models/Plex/PlexEpisodeMetadata.cs
Normal file
|
@ -0,0 +1,81 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexEpisodeMetadata.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
|
||||
namespace PlexRequests.Api.Models.Plex
|
||||
{
|
||||
using System.Xml.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[XmlRoot(ElementName = "MediaContainer")]
|
||||
public class PlexEpisodeMetadata
|
||||
{
|
||||
[XmlElement(ElementName = "Video")]
|
||||
public List<Video> Video { get; set; }
|
||||
[XmlAttribute(AttributeName = "size")]
|
||||
public string Size { get; set; }
|
||||
[XmlAttribute(AttributeName = "allowSync")]
|
||||
public string AllowSync { get; set; }
|
||||
[XmlAttribute(AttributeName = "art")]
|
||||
public string Art { get; set; }
|
||||
[XmlAttribute(AttributeName = "banner")]
|
||||
public string Banner { get; set; }
|
||||
[XmlAttribute(AttributeName = "identifier")]
|
||||
public string Identifier { get; set; }
|
||||
[XmlAttribute(AttributeName = "key")]
|
||||
public string Key { get; set; }
|
||||
[XmlAttribute(AttributeName = "librarySectionID")]
|
||||
public string LibrarySectionID { get; set; }
|
||||
[XmlAttribute(AttributeName = "librarySectionTitle")]
|
||||
public string LibrarySectionTitle { get; set; }
|
||||
[XmlAttribute(AttributeName = "librarySectionUUID")]
|
||||
public string LibrarySectionUUID { get; set; }
|
||||
[XmlAttribute(AttributeName = "mediaTagPrefix")]
|
||||
public string MediaTagPrefix { get; set; }
|
||||
[XmlAttribute(AttributeName = "mediaTagVersion")]
|
||||
public string MediaTagVersion { get; set; }
|
||||
[XmlAttribute(AttributeName = "mixedParents")]
|
||||
public string MixedParents { get; set; }
|
||||
[XmlAttribute(AttributeName = "nocache")]
|
||||
public string Nocache { get; set; }
|
||||
[XmlAttribute(AttributeName = "parentIndex")]
|
||||
public string ParentIndex { get; set; }
|
||||
[XmlAttribute(AttributeName = "parentTitle")]
|
||||
public string ParentTitle { get; set; }
|
||||
[XmlAttribute(AttributeName = "parentYear")]
|
||||
public string ParentYear { get; set; }
|
||||
[XmlAttribute(AttributeName = "theme")]
|
||||
public string Theme { get; set; }
|
||||
[XmlAttribute(AttributeName = "title1")]
|
||||
public string Title1 { get; set; }
|
||||
[XmlAttribute(AttributeName = "title2")]
|
||||
public string Title2 { get; set; }
|
||||
[XmlAttribute(AttributeName = "viewGroup")]
|
||||
public string ViewGroup { get; set; }
|
||||
[XmlAttribute(AttributeName = "viewMode")]
|
||||
public string ViewMode { get; set; }
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,6 @@ namespace PlexRequests.Services
|
|||
{
|
||||
Movie,
|
||||
Show,
|
||||
Music // double check this one
|
||||
Artist
|
||||
}
|
||||
}
|
|
@ -326,6 +326,8 @@ namespace PlexRequests.Api.Models.Plex
|
|||
public List<Provider> Provider { get; set; }
|
||||
[XmlAttribute(AttributeName = "size")]
|
||||
public string Size { get; set; }
|
||||
[XmlAttribute(AttributeName = "totalSize")]
|
||||
public string TotalSize { get; set; }
|
||||
[XmlAttribute(AttributeName = "identifier")]
|
||||
public string Identifier { get; set; }
|
||||
[XmlAttribute(AttributeName = "mediaTagPrefix")]
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<Compile Include="Notifications\SlackNotificationBody.cs" />
|
||||
<Compile Include="Plex\PlexAccount.cs" />
|
||||
<Compile Include="Plex\PlexAuthentication.cs" />
|
||||
<Compile Include="Plex\PlexEpisodeMetadata.cs" />
|
||||
<Compile Include="Plex\PlexError.cs" />
|
||||
<Compile Include="Plex\PlexFriends.cs" />
|
||||
<Compile Include="Plex\PlexLibraries.cs" />
|
||||
|
|
|
@ -168,7 +168,7 @@ namespace PlexRequests.Api
|
|||
|
||||
try
|
||||
{
|
||||
var lib = RetryHandler.Execute<PlexLibraries>(() => Api.ExecuteXml<PlexLibraries> (request, plexFullHost),
|
||||
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexLibraries> (request, plexFullHost),
|
||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrarySections for Plex, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (5),
|
||||
TimeSpan.FromSeconds(10),
|
||||
|
@ -197,7 +197,7 @@ namespace PlexRequests.Api
|
|||
|
||||
try
|
||||
{
|
||||
var lib = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
|
||||
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
|
||||
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (5),
|
||||
TimeSpan.FromSeconds(10),
|
||||
|
@ -213,6 +213,65 @@ namespace PlexRequests.Api
|
|||
}
|
||||
}
|
||||
|
||||
public PlexEpisodeMetadata GetEpisodeMetaData(string authToken, Uri host, string ratingKey)
|
||||
{
|
||||
|
||||
//192.168.1.69:32400/library/metadata/3662/allLeaves
|
||||
// The metadata ratingkey should be in the Cache
|
||||
// Search for it and then call the above with the Directory.RatingKey
|
||||
// THEN! We need the episode metadata using result.Vide.Key ("/library/metadata/3664")
|
||||
// We then have the GUID which contains the TVDB ID plus the season and episode number: guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
|
||||
var request = new RestRequest
|
||||
{
|
||||
Method = Method.GET,
|
||||
Resource = "/library/metadata/{ratingKey}/allLeaves"
|
||||
};
|
||||
|
||||
request.AddUrlSegment("ratingKey", ratingKey);
|
||||
AddHeaders(ref request, authToken);
|
||||
|
||||
try
|
||||
{
|
||||
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexEpisodeMetadata>(request, host),
|
||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetEpisodeMetaData for Plex, Retrying {0}", timespan));
|
||||
|
||||
return lib;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "There has been a API Exception when attempting to get GetEpisodeMetaData");
|
||||
return new PlexEpisodeMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
public PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Method = Method.GET,
|
||||
Resource = "/library/sections/{section}/all"
|
||||
};
|
||||
|
||||
request.AddQueryParameter("type", 4.ToString());
|
||||
request.AddQueryParameter("X-Plex-Container-Start", startPage.ToString());
|
||||
request.AddQueryParameter("X-Plex-Container-Size", returnCount.ToString());
|
||||
request.AddUrlSegment("section", section);
|
||||
AddHeaders(ref request, authToken);
|
||||
|
||||
try
|
||||
{
|
||||
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexSearch>(request, host),
|
||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetAllEpisodes for Plex, Retrying {0}", timespan));
|
||||
|
||||
return lib;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "There has been a API Exception when attempting to get GetAllEpisodes");
|
||||
return new PlexSearch();
|
||||
}
|
||||
}
|
||||
|
||||
public PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId)
|
||||
{
|
||||
var request = new RestRequest
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace PlexRequests.Core
|
|||
}
|
||||
|
||||
public const string PlexLibaries = nameof(PlexLibaries);
|
||||
public const string PlexEpisodes = nameof(PlexEpisodes);
|
||||
|
||||
public const string TvDbToken = nameof(TvDbToken);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace PlexRequests.Core.SettingModels
|
|||
StoreBackup = 24;
|
||||
StoreCleanup = 24;
|
||||
UserRequestLimitResetter = 12;
|
||||
PlexEpisodeCacher = 20;
|
||||
}
|
||||
public int PlexAvailabilityChecker { get; set; }
|
||||
public int SickRageCacher { get; set; }
|
||||
|
@ -45,5 +46,6 @@ namespace PlexRequests.Core.SettingModels
|
|||
public int StoreBackup { get; set; }
|
||||
public int StoreCleanup { get; set; }
|
||||
public int UserRequestLimitResetter { get; set; }
|
||||
public int PlexEpisodeCacher { get; set; }
|
||||
}
|
||||
}
|
|
@ -36,11 +36,25 @@ namespace PlexRequests.Helpers.Tests
|
|||
public class PlexHelperTests
|
||||
{
|
||||
[TestCaseSource(nameof(PlexGuids))]
|
||||
public string CreateUriWithSubDir(string guid)
|
||||
public string GetProviderId(string guid)
|
||||
{
|
||||
return PlexHelper.GetProviderIdFromPlexGuid(guid);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(PlexTvEpisodeGuids))]
|
||||
public List<string> GetEpisodeAndSeasons(string guid)
|
||||
{
|
||||
var ep = PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(guid);
|
||||
var list = new List<string>
|
||||
{
|
||||
ep.ProviderId,
|
||||
ep.SeasonNumber.ToString(),
|
||||
ep.EpisodeNumber.ToString(),
|
||||
};
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<TestCaseData> PlexGuids
|
||||
{
|
||||
|
@ -56,6 +70,17 @@ namespace PlexRequests.Helpers.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> PlexTvEpisodeGuids
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData("com.plexapp.agents.thetvdb://269586/2/8?lang=en").Returns(new List<string> { "269586","2","8" })
|
||||
.SetName("Valid");
|
||||
yield return new TestCaseData("com.plexapp.agents.thetvdb://abc/112/388?lang=en").Returns(new List<string> { "abc", "112","388" })
|
||||
.SetName("Valid Long");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -43,5 +43,29 @@ namespace PlexRequests.Helpers
|
|||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static EpisodeModelHelper GetSeasonsAndEpisodesFromPlexGuid(string guid)
|
||||
{
|
||||
var ep = new EpisodeModelHelper();
|
||||
//guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
return null;
|
||||
|
||||
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (guidSplit.Length > 2)
|
||||
{
|
||||
ep.ProviderId = guidSplit[1];
|
||||
ep.SeasonNumber = int.Parse(guidSplit[2]);
|
||||
ep.EpisodeNumber = int.Parse(guidSplit[3]);
|
||||
}
|
||||
return ep;
|
||||
}
|
||||
}
|
||||
|
||||
public class EpisodeModelHelper
|
||||
{
|
||||
public string ProviderId { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public int EpisodeNumber { get; set; }
|
||||
}
|
||||
}
|
|
@ -38,5 +38,6 @@ namespace PlexRequests.Services.Interfaces
|
|||
bool IsTvShowAvailable(PlexTvShow[] plexShows, string title, string year, string providerId = null);
|
||||
List<PlexAlbum> GetPlexAlbums();
|
||||
bool IsAlbumAvailable(PlexAlbum[] plexAlbums, string title, string year, string artist);
|
||||
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
|
||||
}
|
||||
}
|
|
@ -35,5 +35,6 @@ namespace PlexRequests.Services.Jobs
|
|||
public const string PlexChecker = "Plex Availability Cacher";
|
||||
public const string StoreCleanup = "Database Cleanup";
|
||||
public const string RequestLimitReset = "Request Limit Reset";
|
||||
public const string EpisodeCacher = "Request Limit Reset";
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using NLog;
|
||||
|
||||
|
@ -238,6 +239,19 @@ namespace PlexRequests.Services.Jobs
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsEpisodeAvailable(string theTvDbId, int season, int episode)
|
||||
{
|
||||
var episodes = Cache.Get<List<PlexEpisodeModel>>(CacheKeys.PlexEpisodes);
|
||||
foreach (var result in episodes)
|
||||
{
|
||||
if (result.Episodes.ProviderId.Equals(theTvDbId) && result.Episodes.EpisodeNumber == episode && result.Episodes.SeasonNumber == season)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<PlexAlbum> GetPlexAlbums()
|
||||
{
|
||||
var albums = new List<PlexAlbum>();
|
||||
|
@ -246,7 +260,7 @@ namespace PlexRequests.Services.Jobs
|
|||
{
|
||||
var albumLibs = libs.Where(x =>
|
||||
x.Directory.Any(y =>
|
||||
y.Type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)
|
||||
y.Type.Equals(PlexMediaType.Artist.ToString(), StringComparison.CurrentCultureIgnoreCase)
|
||||
)
|
||||
).ToArray();
|
||||
|
||||
|
|
136
PlexRequests.Services/Jobs/PlexEpisodeCacher.cs
Normal file
136
PlexRequests.Services/Jobs/PlexEpisodeCacher.cs
Normal file
|
@ -0,0 +1,136 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexEpisodeCacher.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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Api.Models.Plex;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Models;
|
||||
|
||||
using Quartz;
|
||||
|
||||
namespace PlexRequests.Services.Jobs
|
||||
{
|
||||
public class PlexEpisodeCacher : IJob
|
||||
{
|
||||
public PlexEpisodeCacher(ISettingsService<PlexSettings> plexSettings, IPlexApi plex, ICacheProvider cache,
|
||||
IJobRecord rec)
|
||||
{
|
||||
Plex = plexSettings;
|
||||
PlexApi = plex;
|
||||
Cache = cache;
|
||||
Job = rec;
|
||||
}
|
||||
|
||||
private ISettingsService<PlexSettings> Plex { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
private IJobRecord Job { get; }
|
||||
private const int ResultCount = 25;
|
||||
|
||||
|
||||
public void CacheEpisodes()
|
||||
{
|
||||
var results = new List<PlexSearch>();
|
||||
var settings = Plex.GetSettings();
|
||||
var sections = PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri);
|
||||
var tvSection = sections.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase));
|
||||
var tvSectionId = tvSection?.Key;
|
||||
|
||||
var currentPosition = 0;
|
||||
int totalSize;
|
||||
|
||||
var episodes = PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount);
|
||||
results.Add(episodes);
|
||||
int.TryParse(episodes.TotalSize, out totalSize);
|
||||
|
||||
currentPosition += ResultCount;
|
||||
while (currentPosition < totalSize)
|
||||
{
|
||||
results.Add(PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount));
|
||||
currentPosition += ResultCount;
|
||||
}
|
||||
|
||||
|
||||
var episodesModel = new List<PlexEpisodeModel>();
|
||||
var metadataList = new List<PlexEpisodeMetadata>();
|
||||
foreach (var r in results)
|
||||
{
|
||||
foreach (var video in r.Video)
|
||||
{
|
||||
var ratingKey = video.RatingKey;
|
||||
var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, ratingKey);
|
||||
metadataList.Add(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var m in metadataList)
|
||||
{
|
||||
foreach (var video in m.Video)
|
||||
{
|
||||
episodesModel.Add(new PlexEpisodeModel
|
||||
{
|
||||
RatingKey = video.RatingKey,
|
||||
EpisodeTitle = video.Title,
|
||||
Guid = video.Guid,
|
||||
ShowTitle = video.GrandparentTitle
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (results.Any())
|
||||
{
|
||||
Cache.Set(CacheKeys.PlexEpisodes, episodesModel, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
CacheEpisodes();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Job.Record(JobNames.EpisodeCacher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
PlexRequests.Services/Models/PlexEpisodeModel.cs
Normal file
40
PlexRequests.Services/Models/PlexEpisodeModel.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexEpisodeModel.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 PlexRequests.Helpers;
|
||||
|
||||
namespace PlexRequests.Services.Models
|
||||
{
|
||||
public class PlexEpisodeModel
|
||||
{
|
||||
public EpisodeModelHelper Episodes => PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(Guid);
|
||||
public string Guid { get; set; }
|
||||
public string RatingKey { get; set; }
|
||||
public string EpisodeTitle { get; set; }
|
||||
public string ShowTitle { get; set; }
|
||||
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@
|
|||
<Compile Include="Interfaces\IJobRecord.cs" />
|
||||
<Compile Include="Jobs\JobRecord.cs" />
|
||||
<Compile Include="Jobs\JobNames.cs" />
|
||||
<Compile Include="Jobs\PlexEpisodeCacher.cs" />
|
||||
<Compile Include="Jobs\StoreBackup.cs" />
|
||||
<Compile Include="Jobs\StoreCleanup.cs" />
|
||||
<Compile Include="Jobs\CouchPotatoCacher.cs" />
|
||||
|
@ -81,6 +82,7 @@
|
|||
<Compile Include="Jobs\SonarrCacher.cs" />
|
||||
<Compile Include="Jobs\UserRequestLimitResetter.cs" />
|
||||
<Compile Include="Models\PlexAlbum.cs" />
|
||||
<Compile Include="Models\PlexEpisodeModel.cs" />
|
||||
<Compile Include="Models\PlexMovie.cs" />
|
||||
<Compile Include="Models\PlexTvShow.cs" />
|
||||
<Compile Include="Interfaces\ISickRageCacher.cs" />
|
||||
|
|
|
@ -56,21 +56,20 @@ namespace PlexRequests.UI.Jobs
|
|||
{
|
||||
var jobs = new List<IJobDetail>();
|
||||
|
||||
var plex = JobBuilder.Create<PlexAvailabilityChecker>().WithIdentity("PlexAvailabilityChecker", "Plex").Build();
|
||||
var sickrage = JobBuilder.Create<SickRageCacher>().WithIdentity("SickRageCacher", "Cache").Build();
|
||||
var sonarr = JobBuilder.Create<SonarrCacher>().WithIdentity("SonarrCacher", "Cache").Build();
|
||||
var cp = JobBuilder.Create<CouchPotatoCacher>().WithIdentity("CouchPotatoCacher", "Cache").Build();
|
||||
var store = JobBuilder.Create<StoreBackup>().WithIdentity("StoreBackup", "Database").Build();
|
||||
var storeClean = JobBuilder.Create<StoreCleanup>().WithIdentity("StoreCleanup", "Database").Build();
|
||||
var userRequestLimitReset = JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build();
|
||||
var jobList = new List<IJobDetail>
|
||||
{
|
||||
JobBuilder.Create<PlexAvailabilityChecker>().WithIdentity("PlexAvailabilityChecker", "Plex").Build(),
|
||||
JobBuilder.Create<PlexEpisodeCacher>().WithIdentity("PlexEpisodeCacher", "Cache").Build(),
|
||||
JobBuilder.Create<SickRageCacher>().WithIdentity("SickRageCacher", "Cache").Build(),
|
||||
JobBuilder.Create<SonarrCacher>().WithIdentity("SonarrCacher", "Cache").Build(),
|
||||
JobBuilder.Create<CouchPotatoCacher>().WithIdentity("CouchPotatoCacher", "Cache").Build(),
|
||||
JobBuilder.Create<StoreBackup>().WithIdentity("StoreBackup", "Database").Build(),
|
||||
JobBuilder.Create<StoreCleanup>().WithIdentity("StoreCleanup", "Database").Build(),
|
||||
JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build()
|
||||
};
|
||||
|
||||
jobs.Add(plex);
|
||||
jobs.Add(sickrage);
|
||||
jobs.Add(sonarr);
|
||||
jobs.Add(cp);
|
||||
jobs.Add(store);
|
||||
jobs.Add(storeClean);
|
||||
jobs.Add(userRequestLimitReset);
|
||||
|
||||
jobs.AddRange(jobList);
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
@ -159,6 +158,13 @@ namespace PlexRequests.UI.Jobs
|
|||
.WithSimpleSchedule(x => x.WithIntervalInHours(s.UserRequestLimitResetter).RepeatForever())
|
||||
.Build();
|
||||
|
||||
var plexEpCacher =
|
||||
TriggerBuilder.Create()
|
||||
.WithIdentity("PlexEpisodeCacher", "Cache")
|
||||
.StartAt(DateTimeOffset.Now.AddMinutes(2)) // Everything has started on application start, lets wait 5 minutes
|
||||
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.PlexEpisodeCacher).RepeatForever())
|
||||
.Build();
|
||||
|
||||
|
||||
triggers.Add(plexAvailabilityChecker);
|
||||
triggers.Add(srCacher);
|
||||
|
@ -167,6 +173,7 @@ namespace PlexRequests.UI.Jobs
|
|||
triggers.Add(storeBackup);
|
||||
triggers.Add(storeCleanup);
|
||||
triggers.Add(userRequestLimiter);
|
||||
triggers.Add(plexEpCacher);
|
||||
|
||||
return triggers;
|
||||
}
|
||||
|
|
|
@ -572,12 +572,14 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
|
||||
// check if the show/episodes have already been requested
|
||||
|
||||
var existingRequest = await RequestService.CheckRequestAsync(showId);
|
||||
var difference = new List<Store.EpisodesModel>();
|
||||
if (existingRequest != null)
|
||||
{
|
||||
if (episodeRequest)
|
||||
{
|
||||
var difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
|
||||
difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
|
||||
if (!difference.Any())
|
||||
{
|
||||
return await AddUserToRequest(existingRequest, settings, fullShowName);
|
||||
|
@ -601,7 +603,13 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
if (episodeRequest)
|
||||
{
|
||||
// TODO: If it's an episode request, check if the episode exists
|
||||
foreach (var d in difference)
|
||||
{
|
||||
if (Checker.IsEpisodeAvailable(providerId, d.SeasonNumber, d.EpisodeNumber))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} {d.SeasonNumber} - {d.EpisodeNumber} {Resources.UI.Search_AlreadyInPlex}" });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -949,14 +957,16 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
var requested = dbDbShow?.Episodes
|
||||
.Any(episodesModel =>
|
||||
ep.number == episodesModel.EpisodeNumber && ep.season == episodesModel.SeasonNumber);
|
||||
ep.number == episodesModel.EpisodeNumber && ep.season == episodesModel.SeasonNumber) ?? false;
|
||||
|
||||
var alreadyInPlex = Checker.IsEpisodeAvailable(seriesId.ToString(), ep.season, ep.number);
|
||||
|
||||
model.Add(new EpisodeListViewModel
|
||||
{
|
||||
Id = show.id,
|
||||
SeasonNumber = ep.season,
|
||||
EpisodeNumber = ep.number,
|
||||
Requested = requested ?? false,
|
||||
Requested = requested || alreadyInPlex,
|
||||
Name = ep.name,
|
||||
EpisodeId = ep.id
|
||||
});
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
<input type="text" class="form-control form-control-custom " id="CouchPotatoCacher" name="CouchPotatoCacher" value="@Model.CouchPotatoCacher">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="PlexEpisodeCacher" class="control-label">Plex Episode Cacher (min)</label>
|
||||
<input type="text" class="form-control form-control-custom " id="PlexEpisodeCacher" name="PlexEpisodeCacher" value="@Model.PlexEpisodeCacher">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="SonarrCacher" class="control-label">Sonarr Cacher (min)</label>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue