Skip to content

Commit

Permalink
Merge pull request #4104 from Ombi-app/feature/tvmaze-replacement
Browse files Browse the repository at this point in the history
Feature/tvmaze replacement
  • Loading branch information
tidusjar authored Mar 20, 2021
2 parents 1066344 + af81b7d commit b61c900
Show file tree
Hide file tree
Showing 139 changed files with 7,754 additions and 3,114 deletions.
10 changes: 3 additions & 7 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Add 'test' label to any change to *.spec.js files within the source dir
automation:
- tests/**/*
automation: tests/**/*

frontend:
- any: ['src/Ombi/ClientApp/**/*']
frontend: src/Ombi/ClientApp/**/*

backend:
- any: ['src/**/*.cs']
backend: src/**/*.cs
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Automation Tests

on:
push:
branches: [ feature/ui-automation, develop ]
branches: [ develop, feature/** ]
pull_request:
branches: [ feature/ui-automation, develop ]
branches: [ develop ]
schedule:
- cron: '0 0 * * *'

Expand Down
Binary file removed Tools/nuget.exe
Binary file not shown.
6 changes: 5 additions & 1 deletion src/Ombi.Api/OmbiHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ private async Task Setup()
_handler = await GetHandler();
}
_client = new HttpClient(_handler);
_client.DefaultRequestHeaders.Add("User-Agent",$"Ombi/{_runtimeVersion} (https://ombi.io/)");
_client.DefaultRequestHeaders.Add("User-Agent", $"Ombi/{_runtimeVersion} (https://ombi.io/)");
}
}

private async Task<HttpMessageHandler> GetHandler()
{
if (_cache == null)
{
return new HttpClientHandler();
}
var settings = await _cache.GetOrAdd(CacheKeys.OmbiSettings, async () => await _settings.GetSettingsAsync(), DateTime.Now.AddHours(1));
if (settings.IgnoreCertificateErrors)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Ombi.Core/Engine/BaseMediaEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ protected async Task<Dictionary<int, TvRequests>> GetTvRequests()
{
var allResults = await TvRepository.Get().ToListAsync();

var distinctResults = allResults.DistinctBy(x => x.TvDbId);
_dbTv = distinctResults.ToDictionary(x => x.TvDbId);
var distinctResults = allResults.DistinctBy(x => x.ExternalProviderId);
_dbTv = distinctResults.ToDictionary(x => x.ExternalProviderId);
_cacheTime = now;
}
return _dbTv;
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Core/Engine/Demo/DemoTvSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DemoTvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvM
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache,
ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub, IOptions<DemoLists> lists, IImageService imageService,
ISettingsService<CustomizationSettings> custom)
: base(identity, service, tvMaze, mapper, trakt, r, um, custom, memCache, s, sub, imageService)
: base(identity, service, tvMaze, mapper, trakt, r, um, custom, memCache, s, sub, imageService, null)
{
_demoLists = lists.Value;
}
Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public interface IMovieEngineV2

Task<MovieFullInfoViewModel> GetMovieInfoByImdbId(string imdbId, CancellationToken requestAborted);
Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId, CancellationToken cancellationToken);
Task<IEnumerable<SearchMovieViewModel>> RecentlyRequestedMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken);
}
}
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Task<RequestsViewModel<ChildRequests>> GetUnavailableRequests(int count, int pos
Task RemoveTvRequest(int requestId);
Task<TvRequests> GetTvRequest(int requestId);
Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv);
Task<RequestEngineResult> RequestTvShow(TvRequestViewModelV2 tv);
Task<RequestEngineResult> DenyChildRequest(int requestId, string reason);
Task<RequestsViewModel<TvRequests>> GetRequestsLite(int count, int position, OrderFilterModel type);
Task<IEnumerable<TvRequests>> SearchTvRequest(string search);
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Ombi.Core.Models.Search;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Ombi.Core.Engine.Interfaces
{
public interface ITvSearchEngine
{
Task<IEnumerable<SearchTvShowViewModel>> Search(string searchTerm);
Task<SearchTvShowViewModel> GetShowInformation(int tvdbid);
Task<SearchTvShowViewModel> GetShowInformation(string movieDbId, CancellationToken token);
Task<IEnumerable<SearchTvShowViewModel>> Popular();
Task<IEnumerable<SearchTvShowViewModel>> Popular(int currentlyLoaded, int amountToLoad, bool includeImages = false);
Task<IEnumerable<SearchTvShowViewModel>> Anticipated();
Expand Down
6 changes: 3 additions & 3 deletions src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Ombi.Core
{
public interface ITVSearchEngineV2
{
Task<SearchFullInfoTvShowViewModel> GetShowInformation(int tvdbid);
Task<SearchFullInfoTvShowViewModel> GetShowByRequest(int requestId);
Task<IEnumerable<StreamingData>> GetStreamInformation(int tvDbId, int tvMazeId, CancellationToken cancellationToken);
Task<SearchFullInfoTvShowViewModel> GetShowInformation(string tvdbid, CancellationToken token);
Task<SearchFullInfoTvShowViewModel> GetShowByRequest(int requestId, CancellationToken token);
Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId, CancellationToken cancellationToken);
}
}
4 changes: 2 additions & 2 deletions src/Ombi.Core/Engine/MovieSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies()
}

protected async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse(
IEnumerable<MovieSearchResult> movies)
IEnumerable<MovieDbSearchResult> movies)
{
var viewMovies = new List<SearchMovieViewModel>();
foreach (var movie in movies)
Expand Down Expand Up @@ -244,7 +244,7 @@ private async Task CheckForSubscription(SearchMovieViewModel viewModel)
}
}

private async Task<SearchMovieViewModel> ProcessSingleMovie(MovieSearchResult movie)
private async Task<SearchMovieViewModel> ProcessSingleMovie(MovieDbSearchResult movie)
{
var viewMovie = Mapper.Map<SearchMovieViewModel>(movie);
return await ProcessSingleMovie(viewMovie);
Expand Down
100 changes: 100 additions & 0 deletions src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,106 @@ public async Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
return await AddRequest(newRequest.NewRequest, tv.RequestOnBehalf);
}

public async Task<RequestEngineResult> RequestTvShow(TvRequestViewModelV2 tv)
{
var user = await GetUser();
var canRequestOnBehalf = false;

if (tv.RequestOnBehalf.HasValue())
{
canRequestOnBehalf = await UserManager.IsInRoleAsync(user, OmbiRoles.PowerUser) || await UserManager.IsInRoleAsync(user, OmbiRoles.Admin);

if (!canRequestOnBehalf)
{
return new RequestEngineResult
{
Result = false,
Message = "You do not have the correct permissions to request on behalf of users!",
ErrorMessage = $"You do not have the correct permissions to request on behalf of users!"
};
}
}

var tvBuilder = new TvShowRequestBuilderV2(MovieDbApi);
(await tvBuilder
.GetShowInfo(tv.TheMovieDbId))
.CreateTvList(tv)
.CreateChild(tv, canRequestOnBehalf ? tv.RequestOnBehalf : user.Id);

await tvBuilder.BuildEpisodes(tv);

var ruleResults = await RunRequestRules(tvBuilder.ChildRequest);
var results = ruleResults as RuleResult[] ?? ruleResults.ToArray();
if (results.Any(x => !x.Success))
{
return new RequestEngineResult
{
ErrorMessage = results.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message)).Message
};
}

// Check if we have auto approved the request, if we have then mark the episodes as approved
if (tvBuilder.ChildRequest.Approved)
{
foreach (var seasons in tvBuilder.ChildRequest.SeasonRequests)
{
foreach (var ep in seasons.Episodes)
{
ep.Approved = true;
ep.Requested = true;
}
}
}

var existingRequest = await TvRepository.Get().FirstOrDefaultAsync(x => x.ExternalProviderId == tv.TheMovieDbId);
if (existingRequest != null)
{
// Remove requests we already have, we just want new ones
foreach (var existingSeason in existingRequest.ChildRequests)
foreach (var existing in existingSeason.SeasonRequests)
{
var newChild = tvBuilder.ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == existing.SeasonNumber);
if (newChild != null)
{
// We have some requests in this season...
// Let's find the episodes.
foreach (var existingEp in existing.Episodes)
{
var duplicateEpisode = newChild.Episodes.FirstOrDefault(x => x.EpisodeNumber == existingEp.EpisodeNumber);
if (duplicateEpisode != null)
{
// Remove it.
newChild.Episodes.Remove(duplicateEpisode);
}
}
if (!newChild.Episodes.Any())
{
// We may have removed all episodes
tvBuilder.ChildRequest.SeasonRequests.Remove(newChild);
}
}
}

// Remove the ID since this is a new child
// This was a TVDBID for the request rules to run
tvBuilder.ChildRequest.Id = 0;
if (!tvBuilder.ChildRequest.SeasonRequests.Any())
{
// Looks like we have removed them all! They were all duplicates...
return new RequestEngineResult
{
Result = false,
ErrorMessage = "This has already been requested"
};
}
return await AddExistingRequest(tvBuilder.ChildRequest, existingRequest, tv.RequestOnBehalf);
}

// This is a new request
var newRequest = tvBuilder.CreateNewRequest(tv);
return await AddRequest(newRequest.NewRequest, tv.RequestOnBehalf);
}

public async Task<RequestsViewModel<TvRequests>> GetRequests(int count, int position, OrderFilterModel type)
{
var shouldHide = await HideFromOtherUsers();
Expand Down
Loading

0 comments on commit b61c900

Please sign in to comment.