Added the recently added engine with some basic methods

pull/2089/head
Jamie 7 years ago
parent 5a22802663
commit 109f5317bb

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Ombi.Core.Models;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
namespace Ombi.Core.Engine
{
public class RecentlyAddedEngine
{
public RecentlyAddedEngine(IPlexContentRepository plex, IEmbyContentRepository emby)
{
_plex = plex;
_emby = emby;
}
private readonly IPlexContentRepository _plex;
private readonly IEmbyContentRepository _emby;
public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies(TimeSpan from)
{
var model = new HashSet<RecentlyAddedMovieModel>();
var plexMovies = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Movie && x.AddedAt.Subtract(from) <= x.AddedAt);
var embyMovies = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Movie && x.AddedAt.Subtract(from) <= x.AddedAt);
TransformPlexMovies(plexMovies, model);
TransformEmbyMovies(embyMovies, model);
return model;
}
public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies()
{
var model = new HashSet<RecentlyAddedMovieModel>();
var plexMovies = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Movie);
var embyMovies = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Movie);
TransformPlexMovies(plexMovies, model);
TransformEmbyMovies(embyMovies, model);
return model;
}
private static void TransformEmbyMovies(IQueryable<EmbyContent> embyMovies, HashSet<RecentlyAddedMovieModel> model)
{
foreach (var emby in embyMovies)
{
model.Add(new RecentlyAddedMovieModel
{
Id = emby.Id,
ImdbId = emby.ProviderId,
AddedAt = emby.AddedAt,
Title = emby.Title,
});
}
}
private static void TransformPlexMovies(IQueryable<PlexServerContent> plexMovies, HashSet<RecentlyAddedMovieModel> model)
{
foreach (var plex in plexMovies)
{
model.Add(new RecentlyAddedMovieModel
{
Id = plex.Id,
ImdbId = plex.ImdbId,
TheMovieDbId = plex.TheMovieDbId,
AddedAt = plex.AddedAt,
Title = plex.Title,
Quality = plex.Quality,
ReleaseYear = plex.ReleaseYear
});
}
}
}
}

@ -0,0 +1,23 @@
using System;
namespace Ombi.Core.Models
{
public class RecentlyAddedMovieModel
{
public int Id { get; set; }
public string Title { get; set; }
public string Overview { get; set; }
public string ImdbId { get; set; }
public string TvDbId { get; set; }
public string TheMovieDbId { get; set; }
public string ReleaseYear { get; set; }
public DateTime AddedAt { get; set; }
public string Quality { get; set; }
}
public enum RecentlyAddedType
{
Plex,
Emby
}
}

@ -45,9 +45,9 @@ namespace Ombi.Store.Repository
private IOmbiContext Db { get; }
public async Task<IEnumerable<EmbyContent>> GetAll()
public IQueryable<EmbyContent> GetAll()
{
return await Db.EmbyContent.ToListAsync();
return Db.EmbyContent.AsQueryable();
}
public async Task AddRange(IEnumerable<EmbyContent> content)

@ -13,7 +13,7 @@ namespace Ombi.Store.Repository
Task<bool> ContentExists(string providerId);
IQueryable<EmbyContent> Get();
Task<EmbyContent> Get(string providerId);
Task<IEnumerable<EmbyContent>> GetAll();
IQueryable<EmbyContent> GetAll();
Task<EmbyContent> GetByEmbyId(string embyId);
Task Update(EmbyContent existingContent);
IQueryable<EmbyEpisode> GetAllEpisodes();

@ -28,15 +28,19 @@
<ItemGroup>
<!-- Files not to show in IDE -->
<Compile Remove="Logs\**" />
<Compile Remove="Styles\**" />
<Compile Remove="wwwroot\dist\**" />
<!-- Files not to publish (note that the 'dist' subfolders are re-added below) -->
<Content Remove="ClientApp\**" />
<Content Remove="Logs\**" />
<Content Remove="Styles\**" />
<Content Remove="wwwroot\dist\**" />
<EmbeddedResource Remove="Logs\**" />
<EmbeddedResource Remove="Styles\**" />
<EmbeddedResource Remove="wwwroot\dist\**" />
<None Remove="Logs\**" />
<None Remove="Styles\**" />
<None Remove="wwwroot\dist\**" />
</ItemGroup>

Loading…
Cancel
Save