-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2655 from tidusjar/develop
Develop
- Loading branch information
Showing
21 changed files
with
363 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Ombi.Core/Rule/Rules/Request/ExistingPlexRequestRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Ombi.Core.Rule.Interfaces; | ||
using Ombi.Store.Entities; | ||
using Ombi.Store.Entities.Requests; | ||
using Ombi.Store.Repository; | ||
|
||
namespace Ombi.Core.Rule.Rules.Request | ||
{ | ||
public class ExistingPlexRequestRule : BaseRequestRule, IRules<BaseRequest> | ||
{ | ||
public ExistingPlexRequestRule(IPlexContentRepository rv) | ||
{ | ||
_plexContent = rv; | ||
} | ||
|
||
private readonly IPlexContentRepository _plexContent; | ||
|
||
/// <summary> | ||
/// We check if the request exists, if it does then we don't want to re-request it. | ||
/// </summary> | ||
/// <param name="obj">The object.</param> | ||
/// <returns></returns> | ||
public async Task<RuleResult> Execute(BaseRequest obj) | ||
{ | ||
if (obj.RequestType == RequestType.TvShow) | ||
{ | ||
var tvRequest = (ChildRequests) obj; | ||
|
||
var tvContent = _plexContent.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Show); | ||
// We need to do a check on the TVDBId | ||
var anyTvDbMatches = await tvContent.Include(x => x.Episodes).FirstOrDefaultAsync(x => x.HasTvDb && x.TvDbId.Equals(tvRequest.Id.ToString())); // the Id on the child is the tvdbid at this point | ||
if (anyTvDbMatches == null) | ||
{ | ||
// So we do not have a TVDB Id, that really sucks. | ||
// Let's try and match on the title and year of the show | ||
var titleAndYearMatch = await tvContent.Include(x=> x.Episodes).FirstOrDefaultAsync(x => | ||
x.Title.Equals(tvRequest.Title, StringComparison.InvariantCultureIgnoreCase) | ||
&& x.ReleaseYear == tvRequest.ReleaseYear.Year.ToString()); | ||
if (titleAndYearMatch != null) | ||
{ | ||
// We have a match! Suprise Motherfucker | ||
return CheckExistingContent(tvRequest, titleAndYearMatch); | ||
} | ||
|
||
// We do not have this | ||
return Success(); | ||
} | ||
// looks like we have a match on the TVDbID | ||
return CheckExistingContent(tvRequest, anyTvDbMatches); | ||
} | ||
return Success(); | ||
} | ||
|
||
|
||
private RuleResult CheckExistingContent(ChildRequests child, PlexServerContent content) | ||
{ | ||
foreach (var season in child.SeasonRequests) | ||
{ | ||
var currentSeasonRequest = | ||
content.Episodes.Where(x => x.SeasonNumber == season.SeasonNumber).ToList(); | ||
if (!currentSeasonRequest.Any()) | ||
{ | ||
continue; | ||
} | ||
foreach (var e in season.Episodes) | ||
{ | ||
var hasEpisode = currentSeasonRequest.Any(x => x.EpisodeNumber == e.EpisodeNumber); | ||
if (hasEpisode) | ||
{ | ||
return Fail($"We already have episodes requested from series {child.Title}"); | ||
} | ||
} | ||
} | ||
|
||
return Success(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Ombi.Core.Rule.Interfaces; | ||
using Ombi.Store.Entities; | ||
using Ombi.Store.Entities.Requests; | ||
using Ombi.Store.Repository.Requests; | ||
|
||
namespace Ombi.Core.Rule.Rules.Request | ||
{ | ||
public class ExistingTvRequestRule : BaseRequestRule, IRules<BaseRequest> | ||
{ | ||
public ExistingTvRequestRule(ITvRequestRepository rv) | ||
{ | ||
Tv = rv; | ||
} | ||
|
||
private ITvRequestRepository Tv { get; } | ||
|
||
/// <summary> | ||
/// We check if the request exists, if it does then we don't want to re-request it. | ||
/// </summary> | ||
/// <param name="obj">The object.</param> | ||
/// <returns></returns> | ||
public async Task<RuleResult> Execute(BaseRequest obj) | ||
{ | ||
if (obj.RequestType == RequestType.TvShow) | ||
{ | ||
var tv = (ChildRequests) obj; | ||
var tvRequests = Tv.GetChild(); | ||
var currentRequest = await tvRequests.FirstOrDefaultAsync(x => x.ParentRequest.TvDbId == tv.Id); // the Id on the child is the tvdbid at this point | ||
if (currentRequest == null) | ||
{ | ||
return Success(); | ||
} | ||
foreach (var season in tv.SeasonRequests) | ||
{ | ||
var currentSeasonRequest = | ||
currentRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber); | ||
if (currentSeasonRequest == null) | ||
{ | ||
continue; | ||
} | ||
foreach (var e in season.Episodes) | ||
{ | ||
var hasEpisode = currentSeasonRequest.Episodes.Any(x => x.EpisodeNumber == e.EpisodeNumber); | ||
if (hasEpisode) | ||
{ | ||
return Fail($"We already have episodes requested from series {tv.Title}"); | ||
} | ||
} | ||
} | ||
} | ||
return Success(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.