mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
Got tv working on the popout cards !wip
This commit is contained in:
parent
f3e781d576
commit
71ec151de1
20 changed files with 674 additions and 46 deletions
129
src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
Normal file
129
src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
Normal file
|
@ -0,0 +1,129 @@
|
|||
using AutoMapper;
|
||||
|
||||
using Ombi.Api.Trakt;
|
||||
using Ombi.Api.TvMaze;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Models.Search.V2;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Core.Settings.Models.External;
|
||||
using Ombi.Store.Repository;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Settings.Settings.Models;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Core.Engine.V2
|
||||
{
|
||||
public class TvSearchEngineV2 : BaseMediaEngine, ITVSearchEngineV2
|
||||
{
|
||||
public TvSearchEngineV2(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper, ISettingsService<PlexSettings> plexSettings,
|
||||
ISettingsService<EmbySettings> embySettings, IPlexContentRepository repo, IEmbyContentRepository embyRepo, ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um,
|
||||
ICacheService memCache, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub)
|
||||
: base(identity, service, r, um, memCache, s, sub)
|
||||
{
|
||||
TvMazeApi = tvMaze;
|
||||
Mapper = mapper;
|
||||
PlexSettings = plexSettings;
|
||||
EmbySettings = embySettings;
|
||||
PlexContentRepo = repo;
|
||||
TraktApi = trakt;
|
||||
EmbyContentRepo = embyRepo;
|
||||
}
|
||||
|
||||
private ITvMazeApi TvMazeApi { get; }
|
||||
private IMapper Mapper { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||||
private IPlexContentRepository PlexContentRepo { get; }
|
||||
private IEmbyContentRepository EmbyContentRepo { get; }
|
||||
private ITraktApi TraktApi { get; }
|
||||
|
||||
|
||||
public async Task<SearchFullInfoTvShowViewModel> GetShowInformation(int tvdbid)
|
||||
{
|
||||
var tvdbshow = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid);
|
||||
var show = await TvMazeApi.GetTvFullInformation(tvdbshow.id);
|
||||
if (show == null)
|
||||
{
|
||||
// We don't have enough information
|
||||
return null;
|
||||
}
|
||||
|
||||
var mapped = Mapper.Map<SearchFullInfoTvShowViewModel>(show);
|
||||
|
||||
foreach (var e in show._embedded.episodes)
|
||||
{
|
||||
var season = mapped.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season);
|
||||
if (season == null)
|
||||
{
|
||||
var newSeason = new SeasonRequests
|
||||
{
|
||||
SeasonNumber = e.season,
|
||||
Episodes = new List<EpisodeRequests>()
|
||||
};
|
||||
newSeason.Episodes.Add(new EpisodeRequests
|
||||
{
|
||||
Url = e.url,
|
||||
Title = e.name,
|
||||
AirDate = e.airstamp,
|
||||
EpisodeNumber = e.number,
|
||||
|
||||
});
|
||||
mapped.SeasonRequests.Add(newSeason);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We already have the season, so just add the episode
|
||||
season.Episodes.Add(new EpisodeRequests
|
||||
{
|
||||
Url = e.url,
|
||||
Title = e.name,
|
||||
AirDate = e.airstamp,
|
||||
EpisodeNumber = e.number,
|
||||
});
|
||||
}
|
||||
}
|
||||
return await ProcessResult(mapped);
|
||||
}
|
||||
|
||||
private IEnumerable<SearchTvShowViewModel> ProcessResults<T>(IEnumerable<T> items)
|
||||
{
|
||||
var retVal = new List<SearchTvShowViewModel>();
|
||||
foreach (var tvMazeSearch in items)
|
||||
{
|
||||
retVal.Add(ProcessResult(tvMazeSearch));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private SearchTvShowViewModel ProcessResult<T>(T tvMazeSearch)
|
||||
{
|
||||
return Mapper.Map<SearchTvShowViewModel>(tvMazeSearch);
|
||||
}
|
||||
|
||||
private async Task<SearchFullInfoTvShowViewModel> ProcessResult(SearchFullInfoTvShowViewModel item)
|
||||
{
|
||||
item.TheTvDbId = item.Id.ToString();
|
||||
|
||||
var oldModel = Mapper.Map<SearchTvShowViewModel>(item);
|
||||
await RunSearchRules(oldModel);
|
||||
|
||||
item.Available = oldModel.Available;
|
||||
item.FullyAvailable = oldModel.FullyAvailable;
|
||||
item.PartlyAvailable = oldModel.PartlyAvailable;
|
||||
item.Requested = oldModel.Requested;
|
||||
item.Available = oldModel.Available;
|
||||
item.Approved = oldModel.Approved;
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue