mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 19:40:05 -07:00
We now show streaming information on the details page
This commit is contained in:
parent
88453f0a99
commit
ea7307ac07
38 changed files with 3267 additions and 154 deletions
|
@ -15,6 +15,8 @@ using Ombi.Core.Settings;
|
|||
using Ombi.Settings.Settings.Models;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
|
@ -179,6 +181,12 @@ namespace Ombi.Core.Engine
|
|||
return user.Language;
|
||||
}
|
||||
|
||||
protected async Task<List<StreamData>> GetUserWatchProvider(WatchProviders providers)
|
||||
{
|
||||
var user = await GetUser();
|
||||
return WatchProviderParser.GetUserWatchProviders(providers, user);
|
||||
}
|
||||
|
||||
private OmbiSettings ombiSettings;
|
||||
protected async Task<OmbiSettings> GetOmbiSettings()
|
||||
{
|
||||
|
|
|
@ -26,5 +26,6 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
int ResultLimit { get; set; }
|
||||
|
||||
Task<MovieFullInfoViewModel> GetMovieInfoByImdbId(string imdbId, CancellationToken requestAborted);
|
||||
Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Models.Search.V2;
|
||||
|
||||
namespace Ombi.Core
|
||||
|
@ -7,5 +9,6 @@ namespace Ombi.Core
|
|||
{
|
||||
Task<SearchFullInfoTvShowViewModel> GetShowInformation(int tvdbid);
|
||||
Task<SearchFullInfoTvShowViewModel> GetShowByRequest(int requestId);
|
||||
Task<IEnumerable<StreamingData>> GetStreamInformation(int tvDbId, int tvMazeId, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
|
@ -249,6 +249,26 @@ namespace Ombi.Core.Engine.V2
|
|||
return result;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId, CancellationToken cancellationToken)
|
||||
{
|
||||
var providers = await MovieApi.GetMovieWatchProviders(movieDbId, cancellationToken);
|
||||
var results = await GetUserWatchProvider(providers);
|
||||
|
||||
var data = new List<StreamingData>();
|
||||
|
||||
foreach (var result in results)
|
||||
{
|
||||
data.Add(new StreamingData
|
||||
{
|
||||
Logo = result.logo_path,
|
||||
Order = result.display_priority,
|
||||
StreamingProvider = result.provider_name
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
protected async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse(
|
||||
IEnumerable<MovieSearchResult> movies)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,8 @@ using Ombi.Core.Settings;
|
|||
using Ombi.Store.Repository;
|
||||
using TraktSharp.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading;
|
||||
using Ombi.Api.TheMovieDb;
|
||||
|
||||
namespace Ombi.Core.Engine.V2
|
||||
{
|
||||
|
@ -27,15 +29,17 @@ namespace Ombi.Core.Engine.V2
|
|||
private readonly ITvMazeApi _tvMaze;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ITraktApi _traktApi;
|
||||
private readonly IMovieDbApi _movieApi;
|
||||
|
||||
public TvSearchEngineV2(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache, ISettingsService<OmbiSettings> s,
|
||||
IRepository<RequestSubscription> sub)
|
||||
IRepository<RequestSubscription> sub, IMovieDbApi movieApi)
|
||||
: base(identity, service, r, um, memCache, s, sub)
|
||||
{
|
||||
_tvMaze = tvMaze;
|
||||
_mapper = mapper;
|
||||
_traktApi = trakt;
|
||||
_movieApi = movieApi;
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,6 +110,39 @@ namespace Ombi.Core.Engine.V2
|
|||
return await ProcessResult(mapped, traktInfoTask);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<StreamingData>> GetStreamInformation(int tvDbId, int tvMazeId, CancellationToken cancellationToken)
|
||||
{
|
||||
var tvdbshow = await Cache.GetOrAdd(nameof(GetShowInformation) + tvMazeId,
|
||||
async () => await _tvMaze.ShowLookupByTheTvDbId(tvMazeId), DateTime.Now.AddHours(12));
|
||||
if (tvdbshow == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// this is a best effort guess since TV maze do not provide the TheMovieDbId
|
||||
var movieDbResults = await _movieApi.SearchTv(tvdbshow.name, tvdbshow.premiered.Substring(0, 4));
|
||||
var potential = movieDbResults.FirstOrDefault();
|
||||
tvDbId = potential.Id;
|
||||
// end guess
|
||||
|
||||
var providers = await _movieApi.GetTvWatchProviders(tvDbId, cancellationToken);
|
||||
var results = await GetUserWatchProvider(providers);
|
||||
|
||||
var data = new List<StreamingData>();
|
||||
|
||||
foreach (var result in results)
|
||||
{
|
||||
data.Add(new StreamingData
|
||||
{
|
||||
Logo = result.logo_path,
|
||||
Order = result.display_priority,
|
||||
StreamingProvider = result.provider_name
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private IEnumerable<SearchTvShowViewModel> ProcessResults<T>(IEnumerable<T> items)
|
||||
{
|
||||
var retVal = new List<SearchTvShowViewModel>();
|
||||
|
@ -141,7 +178,7 @@ namespace Ombi.Core.Engine.V2
|
|||
{
|
||||
item.Images.Medium = item.Images.Medium.ToHttpsUrl();
|
||||
}
|
||||
|
||||
|
||||
if (item.Cast?.Any() ?? false)
|
||||
{
|
||||
foreach (var cast in item.Cast)
|
||||
|
|
35
src/Ombi.Core/Helpers/WatchProviderParser.cs
Normal file
35
src/Ombi.Core/Helpers/WatchProviderParser.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Store.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ombi.Core.Helpers
|
||||
{
|
||||
public static class WatchProviderParser
|
||||
{
|
||||
public static List<StreamData> GetUserWatchProviders(WatchProviders providers, OmbiUser user)
|
||||
{
|
||||
var data = new List<StreamData>();
|
||||
|
||||
if (providers?.Results == null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
var resultsProp = providers.Results.GetType().GetProperties();
|
||||
var matchingStreamingCountry = resultsProp.FirstOrDefault(x => x.Name.Equals(user.StreamingCountry, StringComparison.InvariantCultureIgnoreCase));
|
||||
if (matchingStreamingCountry == null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
var result = (WatchProviderData)matchingStreamingCountry.GetValue(providers.Results);
|
||||
if (result == null || result.StreamInformation == null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
return result.StreamInformation;
|
||||
}
|
||||
}
|
||||
}
|
9
src/Ombi.Core/Models/Search/V2/StreamingData.cs
Normal file
9
src/Ombi.Core/Models/Search/V2/StreamingData.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace Ombi.Core.Models.Search.V2
|
||||
{
|
||||
public class StreamingData
|
||||
{
|
||||
public int Order { get; set; }
|
||||
public string StreamingProvider { get; set; }
|
||||
public string Logo { get; set; }
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ namespace Ombi.Core.Models.UI
|
|||
public UserType UserType { get; set; }
|
||||
public int MovieRequestLimit { get; set; }
|
||||
public int EpisodeRequestLimit { get; set; }
|
||||
public string StreamingCountry { get; set; }
|
||||
public RequestQuotaCountModel EpisodeRequestQuota { get; set; }
|
||||
public RequestQuotaCountModel MovieRequestQuota { get; set; }
|
||||
public RequestQuotaCountModel MusicRequestQuota { get; set; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue