diff --git a/Ombi.Api/TraktApi.cs b/Ombi.Api/TraktApi.cs index ae2ff11b2..8ff89dfcf 100644 --- a/Ombi.Api/TraktApi.cs +++ b/Ombi.Api/TraktApi.cs @@ -17,7 +17,7 @@ namespace Ombi.Api { private TraktClient Client { get; } - private static readonly string Encrypted = "z/56wM/oEkkCWEvSIZCrzQyUvvqmafQ3njqf0UNK5xuKbNYh5Wz8ocoG2QDa5y1DBkozLaKsGxORmAB1XUvwbnom8DVNo9gE++9GTuwxmGlLDD318PXpRmYmpKqNwFSKRZgF6ewiY9qR4t3iG0pGQwPA08FK3+H7kpOKAGJNR9RMDP9wwB6Vl4DuOiZb9/DETjzZ+/zId0ZqimrbN+PLrg=="; + private static readonly string Encrypted = "134e568350f7427511e257a6534026660480cf9b93c77f7378f340603b67381d"; private readonly string _apiKey = StringCipher.Decrypt(Encrypted, "ApiKey"); public TraktApi() { diff --git a/Ombi/Ombi.Api.Trakt/ITraktApi.cs b/Ombi/Ombi.Api.Trakt/ITraktApi.cs new file mode 100644 index 000000000..ac466df7f --- /dev/null +++ b/Ombi/Ombi.Api.Trakt/ITraktApi.cs @@ -0,0 +1,16 @@ +//using System.Collections.Generic; +//using System.Threading.Tasks; +//using TraktApiSharp.Enums; +//using TraktApiSharp.Objects.Get.Shows; +//using TraktApiSharp.Objects.Get.Shows.Common; + +//namespace Ombi.Api.Trakt +//{ +// public interface ITraktApi +// { +// Task> GetAnticipatedShows(int? page = default(int?), int? limitPerPage = default(int?)); +// Task> GetMostWatchesShows(TraktTimePeriod period = null, int? page = default(int?), int? limitPerPage = default(int?)); +// Task> GetPopularShows(int? page = default(int?), int? limitPerPage = default(int?)); +// Task> GetTrendingShows(int? page = default(int?), int? limitPerPage = default(int?)); +// } +//} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj b/Ombi/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj new file mode 100644 index 000000000..c173d1dd7 --- /dev/null +++ b/Ombi/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj @@ -0,0 +1,12 @@ + + + + netstandard1.6 + + + + + + + + \ No newline at end of file diff --git a/Ombi/Ombi.Api.Trakt/TraktApi.cs b/Ombi/Ombi.Api.Trakt/TraktApi.cs new file mode 100644 index 000000000..8ee6fc20a --- /dev/null +++ b/Ombi/Ombi.Api.Trakt/TraktApi.cs @@ -0,0 +1,49 @@ +//using System; +//using System.Collections.Generic; +//using System.Threading.Tasks; +//using Ombi.Helpers; +//using TraktApiSharp; +//using TraktApiSharp.Enums; +//using TraktApiSharp.Objects.Get.Shows; +//using TraktApiSharp.Objects.Get.Shows.Common; +//using TraktApiSharp.Requests.Parameters; + +//namespace Ombi.Api.Trakt +//{ +// public class TraktApi : ITraktApi +// { +// private TraktClient Client { get; } + +// private static readonly string Encrypted = "MTM0ZTU2ODM1MGY3NDI3NTExZTI1N2E2NTM0MDI2NjYwNDgwY2Y5YjkzYzc3ZjczNzhmMzQwNjAzYjY3MzgxZA=="; +// private readonly string _apiKey = StringCipher.DecryptString(Encrypted, "ApiKey"); +// public TraktApi() +// { +// Client = new TraktClient(_apiKey); +// } + +// public async Task> GetPopularShows(int? page = null, int? limitPerPage = null) +// { +// var popular = await Client.Shows.GetPopularShowsAsync(new TraktExtendedInfo { Full = true }, null, page ?? 1, limitPerPage ?? 10); +// return popular.Value; +// } + +// public async Task> GetTrendingShows(int? page = null, int? limitPerPage = null) +// { +// var trendingShowsTop10 = await Client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo { Full = true }, null, page ?? 1, limitPerPage ?? 10); +// return trendingShowsTop10.Value; +// } + +// public async Task> GetAnticipatedShows(int? page = null, int? limitPerPage = null) +// { +// var anticipatedShows = await Client.Shows.GetMostAnticipatedShowsAsync(new TraktExtendedInfo { Full = true }, null, page ?? 1, limitPerPage ?? 10); +// return anticipatedShows.Value; +// } + +// public async Task> GetMostWatchesShows(TraktTimePeriod period = null, int? page = null, int? limitPerPage = null) +// { +// var anticipatedShows = await Client.Shows.GetMostWatchedShowsAsync(period ?? TraktTimePeriod.Monthly, new TraktExtendedInfo { Full = true }, null, page ?? 1, limitPerPage ?? 10); +// return anticipatedShows.Value; +// } +// } +//} + diff --git a/Ombi/Ombi.Api.TvMaze/TvMazeApi.cs b/Ombi/Ombi.Api.TvMaze/TvMazeApi.cs index ed2fdfe66..683e9096b 100644 --- a/Ombi/Ombi.Api.TvMaze/TvMazeApi.cs +++ b/Ombi/Ombi.Api.TvMaze/TvMazeApi.cs @@ -20,7 +20,6 @@ namespace Ombi.Api.TvMaze var request = new Request("search/shows", Uri, HttpMethod.Get); request.AddQueryString("q", searchTerm); - //request.ContentHeaders.Add("Content-Type", "application/json"); request.ContentHeaders.Add(new KeyValuePair("Content-Type","application/json")); return await Api.Request>(request); diff --git a/Ombi/Ombi.Core/Engine/BaseMediaEngine.cs b/Ombi/Ombi.Core/Engine/BaseMediaEngine.cs index 4a82ed040..1d971cbcc 100644 --- a/Ombi/Ombi.Core/Engine/BaseMediaEngine.cs +++ b/Ombi/Ombi.Core/Engine/BaseMediaEngine.cs @@ -5,76 +5,52 @@ using System.Security.Principal; using System.Threading.Tasks; using Ombi.Core.Claims; using Ombi.Core.Engine.Interfaces; -using Ombi.Core.IdentityResolver; using Ombi.Core.Models.Requests; using Ombi.Core.Requests.Models; using Ombi.Helpers; -using Ombi.Store.Entities; namespace Ombi.Core.Engine { public abstract class BaseMediaEngine : BaseEngine { - protected BaseMediaEngine(IPrincipal identity, IRequestService service) : base(identity) + protected BaseMediaEngine(IPrincipal identity, IRequestServiceMain requestService) : base(identity) { - RequestService = service; + RequestService = requestService; } - protected IRequestService RequestService { get; } + protected IRequestServiceMain RequestService { get; } + protected IRequestService MovieRequestService => RequestService.MovieRequestService; + protected IRequestService TvRequestService => RequestService.TvRequestService; - private long _dbMovieCacheTime = 0; - private Dictionary _dbMovies; - protected async Task> GetRequests(RequestType type) + private long _cacheTime = 0; + private Dictionary _dbMovies; + private Dictionary _dbTv; + protected async Task> GetMovieRequests() { long now = DateTime.Now.Ticks; - if (_dbMovies == null || (now - _dbMovieCacheTime) > 10000) + if (_dbMovies == null || (now - _cacheTime) > 10000) { - var allResults = await RequestService.GetAllAsync(); - allResults = allResults.Where(x => x.Type == type); + var allResults = await MovieRequestService.GetAllAsync(); var distinctResults = allResults.DistinctBy(x => x.ProviderId); _dbMovies = distinctResults.ToDictionary(x => x.ProviderId); - _dbMovieCacheTime = now; + _cacheTime = now; } return _dbMovies; } - public async Task> GetRequests() + protected async Task> GetTvRequests() { - var allRequests = await RequestService.GetAllAsync(); - var viewModel = MapToVm(allRequests); - return viewModel; - } - - - protected IEnumerable MapToVm(IEnumerable model) - { - return model.Select(movie => new RequestViewModel + long now = DateTime.Now.Ticks; + if (_dbTv == null || (now - _cacheTime) > 10000) { - ProviderId = movie.ProviderId, - Type = movie.Type, - Status = movie.Status, - ImdbId = movie.ImdbId, - Id = movie.Id, - PosterPath = movie.PosterPath, - ReleaseDate = movie.ReleaseDate, - RequestedDate = movie.RequestedDate, - Released = DateTime.Now > movie.ReleaseDate, - Approved = movie.Available || movie.Approved, - Title = movie.Title, - Overview = movie.Overview, - RequestedUsers = movie.AllUsers.ToArray(), - ReleaseYear = movie.ReleaseDate.Year.ToString(), - Available = movie.Available, - Admin = HasRole(OmbiClaims.Admin), - IssueId = movie.IssueId, - Denied = movie.Denied, - DeniedReason = movie.DeniedReason, - //Qualities = qualities.ToArray(), - //HasRootFolders = rootFolders.Any(), - //RootFolders = rootFolders.ToArray(), - //CurrentRootPath = radarr.Enabled ? GetRootPath(movie.RootFolderSelected, radarr).Result : null - }).ToList(); + var allResults = await TvRequestService.GetAllAsync(); + + var distinctResults = allResults.DistinctBy(x => x.ProviderId); + _dbTv = distinctResults.ToDictionary(x => x.ProviderId); + _cacheTime = now; + } + return _dbTv; } } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Engine/Interfaces/IRequestEngine.cs b/Ombi/Ombi.Core/Engine/Interfaces/IRequestEngine.cs index c8391d9c1..8f1bf6fc9 100644 --- a/Ombi/Ombi.Core/Engine/Interfaces/IRequestEngine.cs +++ b/Ombi/Ombi.Core/Engine/Interfaces/IRequestEngine.cs @@ -10,10 +10,9 @@ namespace Ombi.Core.Engine { Task RequestMovie(SearchMovieViewModel model); bool ShouldAutoApprove(RequestType requestType); - Task> GetRequests(); - Task> GetRequests(int count, int position); - Task> SearchRequest(string search); - Task RemoveRequest(int requestId); - Task UpdateRequest(RequestViewModel request); + Task> GetMovieRequests(int count, int position); + Task> SearchMovieRequest(string search); + Task RemoveMovieRequest(int requestId); + Task UpdateMovieRequest(MovieRequestModel request); } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs b/Ombi/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs index b726901cc..5e08ccb3d 100644 --- a/Ombi/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs +++ b/Ombi/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs @@ -7,5 +7,9 @@ namespace Ombi.Core.Engine public interface ITvSearchEngine { Task> Search(string searchTerm); + //Task> Popular(); + //Task> Anticipated(); + //Task> MostWatches(); + //Task> Trending(); } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Engine/MovieSearchEngine.cs b/Ombi/Ombi.Core/Engine/MovieSearchEngine.cs index cd77ee794..a9e72dcd3 100644 --- a/Ombi/Ombi.Core/Engine/MovieSearchEngine.cs +++ b/Ombi/Ombi.Core/Engine/MovieSearchEngine.cs @@ -19,7 +19,7 @@ namespace Ombi.Core.Engine public class MovieSearchEngine : BaseMediaEngine, IMovieEngine { - public MovieSearchEngine(IPrincipal identity, IRequestService service, IMovieDbApi movApi, IMapper mapper, ISettingsService plexSettings, ISettingsService embySettings, + public MovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper, ISettingsService plexSettings, ISettingsService embySettings, ILogger logger) : base(identity, service) { @@ -46,7 +46,7 @@ namespace Ombi.Core.Engine } var retVal = new List(); - Dictionary dbMovies = await GetRequests(RequestType.Movie); + Dictionary dbMovies = await GetMovieRequests(); var plexSettings = await PlexSettings.GetSettingsAsync(); @@ -120,7 +120,7 @@ namespace Ombi.Core.Engine private async Task> TransformMovieResultsToResponse(IEnumerable movies) { var viewMovies = new List(); - Dictionary dbMovies = await GetRequests(RequestType.Movie); + Dictionary dbMovies = await GetMovieRequests(); var plexSettings = await PlexSettings.GetSettingsAsync(); var embySettings = await EmbySettings.GetSettingsAsync(); @@ -134,7 +134,7 @@ namespace Ombi.Core.Engine } private async Task ProcessSingleMovie(SearchMovieViewModel viewMovie, - Dictionary existingRequests, PlexSettings plexSettings, EmbySettings embySettings) + Dictionary existingRequests, PlexSettings plexSettings, EmbySettings embySettings) { if (plexSettings.Enable) { @@ -176,7 +176,7 @@ namespace Ombi.Core.Engine return viewMovie; } - private async Task ProcessSingleMovie(MovieSearchResult movie, Dictionary existingRequests, PlexSettings plexSettings, EmbySettings embySettings) + private async Task ProcessSingleMovie(MovieSearchResult movie, Dictionary existingRequests, PlexSettings plexSettings, EmbySettings embySettings) { var viewMovie = Mapper.Map(movie); return await ProcessSingleMovie(viewMovie, existingRequests, plexSettings, embySettings); diff --git a/Ombi/Ombi.Core/Engine/RequestEngine.cs b/Ombi/Ombi.Core/Engine/RequestEngine.cs index c7d9d001c..7408c7319 100644 --- a/Ombi/Ombi.Core/Engine/RequestEngine.cs +++ b/Ombi/Ombi.Core/Engine/RequestEngine.cs @@ -6,6 +6,7 @@ using System.Security.Principal; using System.Threading.Tasks; using Hangfire; using Ombi.Api.TheMovieDb; +using Ombi.Api.TvMaze; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; using Ombi.Core.Requests.Models; @@ -18,13 +19,15 @@ namespace Ombi.Core.Engine { public class RequestEngine : BaseMediaEngine, IRequestEngine { - public RequestEngine(IMovieDbApi movieApi, IRequestService requestService, IPrincipal user, INotificationService notificationService) : base(user, requestService) + public RequestEngine(IMovieDbApi movieApi, ITvMazeApi tvApi, IRequestServiceMain requestService, IPrincipal user, INotificationService notificationService) : base(user, requestService) { MovieApi = movieApi; + TvApi = tvApi; NotificationService = notificationService; } private IMovieDbApi MovieApi { get; } private INotificationService NotificationService { get; } + private ITvMazeApi TvApi { get; } public async Task RequestMovie(SearchMovieViewModel model) { var movieInfo = await MovieApi.GetMovieInformation(model.Id); @@ -40,7 +43,7 @@ namespace Ombi.Core.Engine var fullMovieName = $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}"; - var existingRequest = await RequestService.CheckRequestAsync(model.Id); + var existingRequest = await MovieRequestService.CheckRequestAsync(model.Id); if (existingRequest != null) { return new RequestEngineResult @@ -78,7 +81,7 @@ namespace Ombi.Core.Engine // }); //} - var requestModel = new RequestModel + var requestModel = new MovieRequestModel { ProviderId = movieInfo.Id, Type = RequestType.Movie, @@ -130,9 +133,9 @@ namespace Ombi.Core.Engine } - return await AddRequest(requestModel, /*settings,*/ + return await AddMovieRequest(requestModel, /*settings,*/ $"{fullMovieName} has been successfully added!"); - + } catch (Exception e) { @@ -147,7 +150,7 @@ namespace Ombi.Core.Engine NotificationType = NotificationType.ItemAddedToFaultQueue }; BackgroundJob.Enqueue(() => NotificationService.Publish(notification).Wait()); - + //return Response.AsJson(new JsonResponseModel //{ // Result = true, @@ -158,10 +161,58 @@ namespace Ombi.Core.Engine return null; } + public async Task RequestTvShow(SearchTvShowViewModel tv) + { + + var showInfo = await TvApi.ShowLookupByTheTvDbId(tv.Id); + DateTime.TryParse(showInfo.premiered, out DateTime firstAir); + + string fullShowName = $"{showInfo.name} ({firstAir.Year})"; + // For some reason the poster path is always http + var posterPath = showInfo.image?.medium.Replace("http:", "https:"); + var model = new TvRequestModel + { + Type = RequestType.TvShow, + Overview = showInfo.summary.RemoveHtml(), + PosterPath = posterPath, + Title = showInfo.name, + ReleaseDate = firstAir, + Status = showInfo.status, + RequestedDate = DateTime.UtcNow, + Approved = false, + RequestedUsers = new List { Username }, + Issues = IssueState.None, + ImdbId = showInfo.externals?.imdb ?? string.Empty, + TvDbId = tv.Id.ToString(), + ProviderId = tv.Id, + SeasonsNumbersRequested = tv.SeasonNumbersRequested, + RequestAll = tv.RequestAll + }; + - private async Task AddRequest(RequestModel model, string message) + var existingRequest = await TvRequestService.CheckRequestAsync(model.Id); + existingRequest?.ChildRequests.Add(model); + + return null; + } + + private IEnumerable GetListDifferences(IEnumerable existing, IEnumerable request) { - await RequestService.AddRequestAsync(model); + var newRequest = request + .Select(r => + new EpisodesModel + { + SeasonNumber = r.SeasonNumber, + EpisodeNumber = r.EpisodeNumber + }).ToList(); + + return newRequest.Except(existing); + } + + + private async Task AddMovieRequest(MovieRequestModel model, string message) + { + await MovieRequestService.AddRequestAsync(model); if (ShouldSendNotification(model.Type)) { @@ -196,53 +247,46 @@ namespace Ombi.Core.Engine // await RequestLimitRepo.UpdateAsync(usersLimit); //} - return new RequestEngineResult{RequestAdded = true}; + return new RequestEngineResult { RequestAdded = true }; } - public async Task> GetRequests(int count, int position) + public async Task> GetMovieRequests(int count, int position) { - var allRequests = await RequestService.GetAllAsync(count, position); - var viewModel = MapToVm(allRequests); - return viewModel; + var allRequests = await MovieRequestService.GetAllAsync(count, position); + return allRequests; } - public async Task> SearchRequest(string search) + public async Task> SearchMovieRequest(string search) { - var allRequests = await RequestService.GetAllAsync(); + var allRequests = await MovieRequestService.GetAllAsync(); var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)); - var viewModel = MapToVm(results); - return viewModel; + return results; } - public async Task UpdateRequest(RequestViewModel request) + public async Task UpdateMovieRequest(MovieRequestModel request) { - var allRequests = await RequestService.GetAllAsync(); + var allRequests = await MovieRequestService.GetAllAsync(); var results = allRequests.FirstOrDefault(x => x.Id == request.Id); results.Approved = request.Approved; results.Available = request.Available; results.Denied = request.Denied; results.DeniedReason = request.DeniedReason; - //results.AdminNote = request.AdminNote; + results.AdminNote = request.AdminNote; results.ImdbId = request.ImdbId; - results.Episodes = request.Episodes?.ToList() ?? new List(); results.IssueId = request.IssueId; - //results.Issues = request.Issues; - //results.OtherMessage = request.OtherMessage; + results.Issues = request.Issues; + results.OtherMessage = request.OtherMessage; results.Overview = request.Overview; results.PosterPath = request.PosterPath; results.RequestedUsers = request.RequestedUsers?.ToList() ?? new List(); - //results.RootFolderSelected = request.RootFolderSelected; - var model = RequestService.UpdateRequest(results); - return MapToVm(new List{model}).FirstOrDefault(); + var model = MovieRequestService.UpdateRequest(results); + return model; } - public async Task RemoveRequest(int requestId) + public async Task RemoveMovieRequest(int requestId) { - await RequestService.DeleteRequestAsync(requestId); + await MovieRequestService.DeleteRequestAsync(requestId); } - - - } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Engine/TvSearchEngine.cs b/Ombi/Ombi.Core/Engine/TvSearchEngine.cs index d92d9a3f6..4f4d62be9 100644 --- a/Ombi/Ombi.Core/Engine/TvSearchEngine.cs +++ b/Ombi/Ombi.Core/Engine/TvSearchEngine.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Security.Principal; using System.Threading.Tasks; using AutoMapper; +//using Ombi.Api.Trakt; using Ombi.Api.TvMaze; -using Ombi.Api.TvMaze.Models; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; using Ombi.Core.Requests.Models; @@ -17,19 +17,22 @@ namespace Ombi.Core.Engine public class TvSearchEngine : BaseMediaEngine, ITvSearchEngine { - public TvSearchEngine(IPrincipal identity, IRequestService service, ITvMazeApi tvMaze, IMapper mapper, ISettingsService plexSettings, ISettingsService embySettings) + public TvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper, ISettingsService plexSettings, + ISettingsService embySettings/*, ITraktApi trakt*/) : base(identity, service) { TvMazeApi = tvMaze; Mapper = mapper; PlexSettings = plexSettings; EmbySettings = embySettings; + //TraktApi = trakt; } private ITvMazeApi TvMazeApi { get; } private IMapper Mapper { get; } private ISettingsService PlexSettings { get; } private ISettingsService EmbySettings { get; } + //private ITraktApi TraktApi { get; } public async Task> Search(string searchTerm) @@ -43,9 +46,31 @@ namespace Ombi.Core.Engine return null; } - private async Task> ProcessResults(IEnumerable items) + //public async Task> Popular() + //{ + // var result = await TraktApi.GetPopularShows(); + // return await ProcessResults(result); + //} + + //public async Task> Anticipated() + //{ + // var result = await TraktApi.GetAnticipatedShows(); + // return await ProcessResults(result); + //} + //public async Task> MostWatches() + //{ + // var result = await TraktApi.GetMostWatchesShows(); + // return await ProcessResults(result); + //} + //public async Task> Trending() + //{ + // var result = await TraktApi.GetTrendingShows(); + // return await ProcessResults(result); + //} + + private async Task> ProcessResults(IEnumerable items) { - var existingRequests = await GetRequests(RequestType.TvShow); + var existingRequests = await GetTvRequests(); var plexSettings = await PlexSettings.GetSettingsAsync(); var embySettings = await EmbySettings.GetSettingsAsync(); @@ -53,14 +78,14 @@ namespace Ombi.Core.Engine var retVal = new List(); foreach (var tvMazeSearch in items) { - retVal.Add(ProcessResult(tvMazeSearch, existingRequests, plexSettings, embySettings)); + var viewT = Mapper.Map(tvMazeSearch); + retVal.Add(ProcessResult(viewT, existingRequests, plexSettings, embySettings)); } return retVal; } - private SearchTvShowViewModel ProcessResult(TvMazeSearch item, Dictionary existingRequests, PlexSettings plexSettings, EmbySettings embySettings) + private SearchTvShowViewModel ProcessResult(SearchTvShowViewModel item, Dictionary existingRequests, PlexSettings plexSettings, EmbySettings embySettings) { - var viewT = Mapper.Map(item); if (embySettings.Enable) { //var embyShow = EmbyChecker.GetTvShow(embyCached.ToArray(), t.show.name, t.show.premiered?.Substring(0, 4), providerId); @@ -80,25 +105,25 @@ namespace Ombi.Core.Engine //} } - if (item.show?.externals?.thetvdb != null && !viewT.Available) + if (item.Id > 0 && item.Available) { - var tvdbid = (int)item.show.externals.thetvdb; + var tvdbid = item.Id; if (existingRequests.ContainsKey(tvdbid)) { var dbt = existingRequests[tvdbid]; - viewT.Requested = true; - viewT.Episodes = dbt.Episodes.ToList(); - viewT.Approved = dbt.Approved; + item.Requested = true; + item.EpisodesRequested = dbt.Episodes.ToList(); + item.Approved = dbt.Approved; } //if (sonarrCached.Select(x => x.TvdbId).Contains(tvdbid) || sickRageCache.Contains(tvdbid)) // // compare to the sonarr/sickrage db //{ - // viewT.Requested = true; + // item.Requested = true; //} } - return viewT; + return item; } } } diff --git a/Ombi/Ombi.Core/Models/Requests/BaseRequestModel.cs b/Ombi/Ombi.Core/Models/Requests/BaseRequestModel.cs new file mode 100644 index 000000000..41b044a6c --- /dev/null +++ b/Ombi/Ombi.Core/Models/Requests/BaseRequestModel.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Ombi.Store.Entities; + +namespace Ombi.Core.Models.Requests +{ + public class BaseRequestModel : Entity + { + public BaseRequestModel() + { + RequestedUsers = new List(); + } + public int ProviderId { get; set; } + public string Overview { get; set; } + public string Title { get; set; } + public string PosterPath { get; set; } + public DateTime ReleaseDate { get; set; } + public RequestType Type { get; set; } + public string Status { get; set; } + public bool Approved { get; set; } + public bool Admin { get; set; } + public DateTime RequestedDate { get; set; } + public bool Available { get; set; } + public IssueState Issues { get; set; } + public string OtherMessage { get; set; } + public string AdminNote { get; set; } + public List RequestedUsers { get; set; } + public int IssueId { get; set; } + public bool Denied { get; set; } + public string DeniedReason { get; set; } + + [JsonIgnore] + public bool Released => DateTime.UtcNow > ReleaseDate; + + [JsonIgnore] + public IEnumerable AllUsers + { + get + { + var u = new List(); + if (RequestedUsers != null && RequestedUsers.Any()) + { + u.AddRange(RequestedUsers); + } + return u; + } + } + + [JsonIgnore] + public bool CanApprove => !Approved && !Available; + + public bool UserHasRequested(string username) + { + return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase)); + } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Core/Models/Requests/IRequestService.cs b/Ombi/Ombi.Core/Models/Requests/IRequestService.cs index deb40703f..f78313027 100644 --- a/Ombi/Ombi.Core/Models/Requests/IRequestService.cs +++ b/Ombi/Ombi.Core/Models/Requests/IRequestService.cs @@ -5,24 +5,24 @@ using Ombi.Store.Entities; namespace Ombi.Core.Requests.Models { - public interface IRequestService + public interface IRequestService where T : BaseRequestModel { - int AddRequest(RequestModel model); - Task AddRequestAsync(RequestModel model); - void BatchDelete(IEnumerable model); - void BatchUpdate(IEnumerable model); - RequestModel CheckRequest(int providerId); - RequestModel CheckRequest(string musicId); - Task CheckRequestAsync(int providerId); - Task CheckRequestAsync(string musicId); - void DeleteRequest(RequestModel request); + int AddRequest(T model); + Task AddRequestAsync(T model); + void BatchDelete(IEnumerable model); + void BatchUpdate(IEnumerable model); + T CheckRequest(int providerId); + T CheckRequest(string musicId); + Task CheckRequestAsync(int providerId); + Task CheckRequestAsync(string musicId); + void DeleteRequest(T request); Task DeleteRequestAsync(int request); - Task DeleteRequestAsync(RequestModel request); - RequestModel Get(int id); - IEnumerable GetAll(); - Task> GetAllAsync(); - Task> GetAllAsync(int count, int position); - Task GetAsync(int id); - RequestModel UpdateRequest(RequestModel model); + Task DeleteRequestAsync(T request); + T Get(int id); + IEnumerable GetAll(); + Task> GetAllAsync(); + Task> GetAllAsync(int count, int position); + Task GetAsync(int id); + T UpdateRequest(T model); } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Models/Requests/JsonRequestService.cs b/Ombi/Ombi.Core/Models/Requests/JsonRequestService.cs index db741bac7..ab6ff5303 100644 --- a/Ombi/Ombi.Core/Models/Requests/JsonRequestService.cs +++ b/Ombi/Ombi.Core/Models/Requests/JsonRequestService.cs @@ -8,14 +8,14 @@ using Ombi.Store.Repository; namespace Ombi.Core.Models.Requests { - public class JsonRequestService : IRequestService + public class JsonRequestService : IRequestService where T:BaseRequestModel { public JsonRequestService(IRequestRepository repo) { Repo = repo; } private IRequestRepository Repo { get; } - public int AddRequest(RequestModel model) + public int AddRequest(T model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId }; var id = Repo.Insert(entity); @@ -23,7 +23,7 @@ namespace Ombi.Core.Models.Requests return id.Id; } - public async Task AddRequestAsync(RequestModel model) + public async Task AddRequestAsync(T model) { var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId }; var id = await Repo.InsertAsync(entity).ConfigureAwait(false); @@ -31,43 +31,43 @@ namespace Ombi.Core.Models.Requests return id.Id; } - public RequestModel CheckRequest(int providerId) + public T CheckRequest(int providerId) { var blobs = Repo.GetAll(); var blob = blobs.FirstOrDefault(x => x.ProviderId == providerId); if (blob == null) { return null; } - var model = ByteConverterHelper.ReturnObject(blob.Content); + var model = ByteConverterHelper.ReturnObject(blob.Content); model.Id = blob.Id; return model; } - public async Task CheckRequestAsync(int providerId) + public async Task CheckRequestAsync(int providerId) { var blobs = await Repo.GetAllAsync().ConfigureAwait(false); var blob = blobs.FirstOrDefault(x => x.ProviderId == providerId); if (blob == null) { return null; } - var model = ByteConverterHelper.ReturnObject(blob.Content); + var model = ByteConverterHelper.ReturnObject(blob.Content); model.Id = blob.Id; return model; } - public RequestModel CheckRequest(string musicId) + public T CheckRequest(string musicId) { var blobs = Repo.GetAll(); var blob = blobs.FirstOrDefault(x => x.MusicId == musicId); if (blob == null) { return null; } - var model = ByteConverterHelper.ReturnObject(blob.Content); + var model = ByteConverterHelper.ReturnObject(blob.Content); model.Id = blob.Id; return model; } - public async Task CheckRequestAsync(string musicId) + public async Task CheckRequestAsync(string musicId) { var blobs = await Repo.GetAllAsync().ConfigureAwait(false); var blob = blobs.FirstOrDefault(x => x.MusicId == musicId); @@ -76,18 +76,18 @@ namespace Ombi.Core.Models.Requests { return null; } - var model = ByteConverterHelper.ReturnObject(blob.Content); + var model = ByteConverterHelper.ReturnObject(blob.Content); model.Id = blob.Id; return model; } - public void DeleteRequest(RequestModel request) + public void DeleteRequest(T request) { var blob = Repo.Get(request.Id); Repo.Delete(blob); } - public async Task DeleteRequestAsync(RequestModel request) + public async Task DeleteRequestAsync(T request) { var blob = await Repo.GetAsync(request.Id).ConfigureAwait(false); Repo.Delete(blob); @@ -98,7 +98,7 @@ namespace Ombi.Core.Models.Requests Repo.Delete(blob); } - public RequestModel UpdateRequest(RequestModel model) + public T UpdateRequest(T model) { var b = Repo.Get(model.Id); b.Content = ByteConverterHelper.ReturnBytes(model); @@ -107,34 +107,34 @@ namespace Ombi.Core.Models.Requests } - public RequestModel Get(int id) + public T Get(int id) { var blob = Repo.Get(id); if (blob == null) { - return new RequestModel(); + return default(T); } - var model = ByteConverterHelper.ReturnObject(blob.Content); + var model = ByteConverterHelper.ReturnObject(blob.Content); model.Id = blob.Id; // They should always be the same, but for somereason a user didn't have it in the db https://github.com/tidusjar/Ombi/issues/862#issuecomment-269743847 return model; } - public async Task GetAsync(int id) + public async Task GetAsync(int id) { var blob = await Repo.GetAsync(id).ConfigureAwait(false); if (blob == null) { - return new RequestModel(); + return default(T); } - var model = ByteConverterHelper.ReturnObject(blob.Content); + var model = ByteConverterHelper.ReturnObject(blob.Content); model.Id = blob.Id; return model; } - public IEnumerable GetAll() + public IEnumerable GetAll() { var blobs = Repo.GetAll().ToList(); - var retVal = new List(); + var retVal = new List(); foreach (var b in blobs) { @@ -142,17 +142,17 @@ namespace Ombi.Core.Models.Requests { continue; } - var model = ByteConverterHelper.ReturnObject(b.Content); + var model = ByteConverterHelper.ReturnObject(b.Content); model.Id = b.Id; retVal.Add(model); } return retVal; } - public async Task> GetAllAsync() + public async Task> GetAllAsync() { var blobs = await Repo.GetAllAsync().ConfigureAwait(false); - var retVal = new List(); + var retVal = new List(); foreach (var b in blobs) { @@ -160,17 +160,17 @@ namespace Ombi.Core.Models.Requests { continue; } - var model = ByteConverterHelper.ReturnObject(b.Content); + var model = ByteConverterHelper.ReturnObject(b.Content); model.Id = b.Id; retVal.Add(model); } return retVal; } - public async Task> GetAllAsync(int count, int position) + public async Task> GetAllAsync(int count, int position) { var blobs = await Repo.GetAllAsync(count, position).ConfigureAwait(false); - var retVal = new List(); + var retVal = new List(); foreach (var b in blobs) { @@ -178,20 +178,20 @@ namespace Ombi.Core.Models.Requests { continue; } - var model = ByteConverterHelper.ReturnObject(b.Content); + var model = ByteConverterHelper.ReturnObject(b.Content); model.Id = b.Id; retVal.Add(model); } return retVal; } - public void BatchUpdate(IEnumerable model) + public void BatchUpdate(IEnumerable model) { var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ByteConverterHelper.ReturnBytes(m), ProviderId = m.ProviderId, Id = m.Id }).ToList(); Repo.UpdateAll(entities); } - public void BatchDelete(IEnumerable model) + public void BatchDelete(IEnumerable model) { var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ByteConverterHelper.ReturnBytes(m), ProviderId = m.ProviderId, Id = m.Id }).ToList(); Repo.DeleteAll(entities); diff --git a/Ombi/Ombi.Core/Models/Requests/Movie/MovieRequestModel.cs b/Ombi/Ombi.Core/Models/Requests/Movie/MovieRequestModel.cs new file mode 100644 index 000000000..d88d43953 --- /dev/null +++ b/Ombi/Ombi.Core/Models/Requests/Movie/MovieRequestModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Ombi.Store.Entities; + +namespace Ombi.Core.Models.Requests +{ + public class MovieRequestModel : BaseRequestModel + { + + public string ImdbId { get; set; } + + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Core/Models/Requests/RequestModel.cs b/Ombi/Ombi.Core/Models/Requests/RequestModel.cs index 92ca73a68..bae2c760c 100644 --- a/Ombi/Ombi.Core/Models/Requests/RequestModel.cs +++ b/Ombi/Ombi.Core/Models/Requests/RequestModel.cs @@ -1,78 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; using Ombi.Store.Entities; namespace Ombi.Core.Models.Requests { - public class RequestModel : Entity - { - public RequestModel() - { - RequestedUsers = new List(); - Episodes = new List(); - } - - public int ProviderId { get; set; } - public string ImdbId { get; set; } - public string TvDbId { get; set; } - public string Overview { get; set; } - public string Title { get; set; } - public string PosterPath { get; set; } - public DateTime ReleaseDate { get; set; } - public RequestType Type { get; set; } - public string Status { get; set; } - public bool Approved { get; set; } - - public DateTime RequestedDate { get; set; } - public bool Available { get; set; } - public IssueState Issues { get; set; } - public string OtherMessage { get; set; } - public string AdminNote { get; set; } - public int[] SeasonList { get; set; } - public int SeasonCount { get; set; } - public string SeasonsRequested { get; set; } - public List RequestedUsers { get; set; } - public int IssueId { get; set; } - public List Episodes { get; set; } - public bool Denied { get; set; } - public string DeniedReason { get; set; } - /// - /// For TV Shows with a custom root folder - /// - /// - /// The root folder selected. - /// - public int RootFolderSelected { get; set; } - - [JsonIgnore] - public List AllUsers - { - get - { - var u = new List(); - if (RequestedUsers != null && RequestedUsers.Any()) - { - u.AddRange(RequestedUsers); - } - return u; - } - } - - [JsonIgnore] - public bool CanApprove => !Approved && !Available; - - public string ReleaseId { get; set; } - - public bool UserHasRequested(string username) - { - return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase)); - } - } - - - public static class RequestTypeDisplay { public static string GetString(this RequestType type) diff --git a/Ombi/Ombi.Core/Models/Requests/RequestService.cs b/Ombi/Ombi.Core/Models/Requests/RequestService.cs new file mode 100644 index 000000000..412ebd084 --- /dev/null +++ b/Ombi/Ombi.Core/Models/Requests/RequestService.cs @@ -0,0 +1,16 @@ +using Ombi.Core.Requests.Models; + +namespace Ombi.Core.Models.Requests +{ + public class RequestService : IRequestServiceMain + { + public RequestService(IRequestService tv, IRequestService movie) + { + TvRequestService = tv; + MovieRequestService = movie; + } + + public IRequestService TvRequestService { get; } + public IRequestService MovieRequestService { get; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Core/Models/Requests/Tv/TvRequestModel.cs b/Ombi/Ombi.Core/Models/Requests/Tv/TvRequestModel.cs new file mode 100644 index 000000000..f3c8a28d1 --- /dev/null +++ b/Ombi/Ombi.Core/Models/Requests/Tv/TvRequestModel.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; + +namespace Ombi.Core.Models.Requests +{ + public class TvRequestModel : BaseRequestModel + { + public TvRequestModel() + { + Episodes = new List(); + ChildRequests = new List(); + } + + public string ImdbId { get; set; } + public string TvDbId { get; set; } + public bool RequestAll { get; set; } + public List SeasonsNumbersRequested { get; set; } + public List Episodes { get; set; } + + /// + /// This is for TV requests, If there is more than 1 request for a show then it should be a child + /// e.g. Request 1 is for Season 1, Request 2 is for season 5. There should be two child items. + /// + public List ChildRequests { get; set; } + + public bool HasChildRequests => ChildRequests.Count > 0; + + /// + /// For TV Shows with a custom root folder + /// + /// + /// The root folder selected. + /// + public int RootFolderSelected { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Core/Models/Search/SearchTvShowViewModel.cs b/Ombi/Ombi.Core/Models/Search/SearchTvShowViewModel.cs index b378a2926..4da0f1cdc 100644 --- a/Ombi/Ombi.Core/Models/Search/SearchTvShowViewModel.cs +++ b/Ombi/Ombi.Core/Models/Search/SearchTvShowViewModel.cs @@ -5,10 +5,6 @@ namespace Ombi.Core.Models.Search { public class SearchTvShowViewModel : SearchViewModel { - public SearchTvShowViewModel() - { - Episodes = new List(); - } public int Id { get; set; } public string SeriesName { get; set; } public List Aliases { get; set; } @@ -27,7 +23,6 @@ namespace Ombi.Core.Models.Search public string Rating { get; set; } public string ImdbId { get; set; } public int SiteRating { get; set; } - public List Episodes { get; set; } /// /// This is used from the Trakt API @@ -43,5 +38,23 @@ namespace Ombi.Core.Models.Search /// The trailer. /// public string Homepage { get; set; } + + /// + /// This is for when the users requests multiple seasons or a single season + /// + public List SeasonNumbersRequested { get; set; } = new List(); + + /// + /// If we have requested some episodes + /// + public List EpisodesRequested { get; set; } = new List(); + + /// + /// If we are requesting the entire series + /// + public bool RequestAll { get; set; } + + public bool SpecificSeasonsRequested => SeasonNumbersRequested.Count > 0; + public bool SpecificEpisodesRequested => EpisodesRequested.Count > 0; } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Ombi.Core.csproj b/Ombi/Ombi.Core/Ombi.Core.csproj index 7cc0d5958..6f02e21b2 100644 --- a/Ombi/Ombi.Core/Ombi.Core.csproj +++ b/Ombi/Ombi.Core/Ombi.Core.csproj @@ -17,6 +17,7 @@ + diff --git a/Ombi/Ombi.Core/Requests/Models/IRequestServiceMain.cs b/Ombi/Ombi.Core/Requests/Models/IRequestServiceMain.cs new file mode 100644 index 000000000..c07b05039 --- /dev/null +++ b/Ombi/Ombi.Core/Requests/Models/IRequestServiceMain.cs @@ -0,0 +1,10 @@ +using Ombi.Core.Requests.Models; + +namespace Ombi.Core.Models.Requests +{ + public interface IRequestServiceMain + { + IRequestService MovieRequestService { get; } + IRequestService TvRequestService { get; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.DependencyInjection/IocExtensions.cs b/Ombi/Ombi.DependencyInjection/IocExtensions.cs index 3e2c6929c..9f6fc7751 100644 --- a/Ombi/Ombi.DependencyInjection/IocExtensions.cs +++ b/Ombi/Ombi.DependencyInjection/IocExtensions.cs @@ -10,6 +10,7 @@ using Ombi.Api.Emby; using Ombi.Api.Plex; using Ombi.Api.Sonarr; using Ombi.Api.TheMovieDb; +//using Ombi.Api.Trakt; using Ombi.Api.TvMaze; using Ombi.Core; using Ombi.Core.Engine; @@ -57,6 +58,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + //services.AddTransient(); return services; } @@ -74,7 +76,9 @@ namespace Ombi.DependencyInjection } public static IServiceCollection RegisterServices(this IServiceCollection services) { - services.AddTransient(); + + services.AddTransient(); + services.AddTransient(typeof(IRequestService<>), typeof(JsonRequestService<>)); services.AddSingleton(); return services; diff --git a/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index fa95e654a..f89680a1b 100644 --- a/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -14,6 +14,7 @@ + diff --git a/Ombi/Ombi.Mapping/Profiles/TvProfile.cs b/Ombi/Ombi.Mapping/Profiles/TvProfile.cs index e40bb16e2..9ab3483f1 100644 --- a/Ombi/Ombi.Mapping/Profiles/TvProfile.cs +++ b/Ombi/Ombi.Mapping/Profiles/TvProfile.cs @@ -1,8 +1,11 @@ -using System.Globalization; +using System; +using System.Globalization; using AutoMapper; using Ombi.Api.TvMaze.Models; using Ombi.Core.Models.Search; using Ombi.Helpers; +//using TraktApiSharp.Objects.Get.Shows; +//using TraktApiSharp.Objects.Get.Shows.Common; namespace Ombi.Mapping.Profiles { @@ -23,6 +26,58 @@ namespace Ombi.Mapping.Profiles .ForMember(dest => dest.SeriesName, opts => opts.MapFrom(src => src.show.name)) .ForMember(dest => dest.Banner, opts => opts.MapFrom(src => !string.IsNullOrEmpty(src.show.image.medium) ? src.show.image.medium.Replace("http","https") : string.Empty)) .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.show.status)); + + //CreateMap() + // .ForMember(dest => dest.Id, opts => opts.MapFrom(src => Convert.ToInt32(src.Ids.Tvdb.ToString()))) + // .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.FirstAired.HasValue ? src.FirstAired.Value.ToString("yyyy-MM-ddTHH:mm:ss") : string.Empty)) + // .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.Ids.Imdb)) + // .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.Network)) + // .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Overview.RemoveHtml())) + // .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.Rating.ToString())) + // .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.Runtime.ToString())) + // .ForMember(dest => dest.SeriesName, opts => opts.MapFrom(src => src.Title)) + // .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.Status.DisplayName)) + // .ForMember(dest => dest.Trailer, opts => opts.MapFrom(src => src.Trailer)) + // .ForMember(dest => dest.Homepage, opts => opts.MapFrom(src => src.Homepage)); + + //CreateMap() + // .ForMember(dest => dest.Id, opts => opts.MapFrom(src => Convert.ToInt32(src.Show.Ids.Tvdb.ToString()))) + // .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.Show.FirstAired.HasValue ? src.Show.FirstAired.Value.ToString("yyyy-MM-ddTHH:mm:ss") : string.Empty)) + // .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.Show.Ids.Imdb)) + // .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.Show.Network)) + // .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Show.Overview.RemoveHtml())) + // .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.Show.Rating.ToString())) + // .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.Show.Runtime.ToString())) + // .ForMember(dest => dest.SeriesName, opts => opts.MapFrom(src => src.Show.Title)) + // .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.Show.Status.DisplayName)) + // .ForMember(dest => dest.Trailer, opts => opts.MapFrom(src => src.Show.Trailer)) + // .ForMember(dest => dest.Homepage, opts => opts.MapFrom(src => src.Show.Homepage)); + + //CreateMap() + // .ForMember(dest => dest.Id, opts => opts.MapFrom(src => Convert.ToInt32(src.Show.Ids.Tvdb.ToString()))) + // .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.Show.FirstAired.HasValue ? src.Show.FirstAired.Value.ToString("yyyy-MM-ddTHH:mm:ss") : string.Empty)) + // .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.Show.Ids.Imdb)) + // .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.Show.Network)) + // .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Show.Overview.RemoveHtml())) + // .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.Show.Rating.ToString())) + // .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.Show.Runtime.ToString())) + // .ForMember(dest => dest.SeriesName, opts => opts.MapFrom(src => src.Show.Title)) + // .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.Show.Status.DisplayName)) + // .ForMember(dest => dest.Trailer, opts => opts.MapFrom(src => src.Show.Trailer)) + // .ForMember(dest => dest.Homepage, opts => opts.MapFrom(src => src.Show.Homepage)); + + //CreateMap() + // .ForMember(dest => dest.Id, opts => opts.MapFrom(src => Convert.ToInt32(src.Show.Ids.Tvdb.ToString()))) + // .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.Show.FirstAired.HasValue ? src.Show.FirstAired.Value.ToString("yyyy-MM-ddTHH:mm:ss") : string.Empty)) + // .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.Show.Ids.Imdb)) + // .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.Show.Network)) + // .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Show.Overview.RemoveHtml())) + // .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.Show.Rating.ToString())) + // .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.Show.Runtime.ToString())) + // .ForMember(dest => dest.SeriesName, opts => opts.MapFrom(src => src.Show.Title)) + // .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.Show.Status.DisplayName)) + // .ForMember(dest => dest.Trailer, opts => opts.MapFrom(src => src.Show.Trailer)) + // .ForMember(dest => dest.Homepage, opts => opts.MapFrom(src => src.Show.Homepage)); } } } \ No newline at end of file diff --git a/Ombi/Ombi.sln b/Ombi/Ombi.sln index b1659baca..c3c621aaf 100644 --- a/Ombi/Ombi.sln +++ b/Ombi/Ombi.sln @@ -56,6 +56,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Tests.Core", "Ombi.Tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Settings", "Ombi.Settings\Ombi.Settings.csproj", "{AE3AA23D-5B66-42AF-B44E-B9B4D8856C6F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Trakt", "Ombi.Api.Trakt\Ombi.Api.Trakt.csproj", "{3880375C-1A7E-4D75-96EC-63B954C42FEA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -134,6 +136,10 @@ Global {AE3AA23D-5B66-42AF-B44E-B9B4D8856C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AE3AA23D-5B66-42AF-B44E-B9B4D8856C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AE3AA23D-5B66-42AF-B44E-B9B4D8856C6F}.Release|Any CPU.Build.0 = Release|Any CPU + {3880375C-1A7E-4D75-96EC-63B954C42FEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3880375C-1A7E-4D75-96EC-63B954C42FEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3880375C-1A7E-4D75-96EC-63B954C42FEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3880375C-1A7E-4D75-96EC-63B954C42FEA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -151,5 +157,6 @@ Global {72DB97D7-2D60-4B96-8C57-6C0E20E892EB} = {EA30DD15-6280-4687-B370-2956EC2E54E5} {6EE01B17-0966-4E11-8BC1-A5318A92AB1D} = {EA30DD15-6280-4687-B370-2956EC2E54E5} {627A27A7-8879-4851-8140-38F8F5ADD6CD} = {6F42AB98-9196-44C4-B888-D5E409F415A1} + {3880375C-1A7E-4D75-96EC-63B954C42FEA} = {9293CA11-360A-4C20-A674-B9E794431BF5} EndGlobalSection EndGlobal diff --git a/Ombi/Ombi/Auth/TokenProviderOptions.cs b/Ombi/Ombi/Auth/TokenProviderOptions.cs index 880c2fff3..1128ba086 100644 --- a/Ombi/Ombi/Auth/TokenProviderOptions.cs +++ b/Ombi/Ombi/Auth/TokenProviderOptions.cs @@ -31,7 +31,7 @@ namespace Ombi.Auth /// The expiration time for the generated tokens. /// /// The default is 7 Days. - public TimeSpan Expiration { get; set; } = TimeSpan.FromDays(7); + public TimeSpan Expiration { get; set; } = TimeSpan.FromDays(1); /// /// The signing key to use when generating tokens. diff --git a/Ombi/Ombi/Controllers/IdentityController.cs b/Ombi/Ombi/Controllers/IdentityController.cs index f4854b27d..a0802886b 100644 --- a/Ombi/Ombi/Controllers/IdentityController.cs +++ b/Ombi/Ombi/Controllers/IdentityController.cs @@ -27,9 +27,9 @@ namespace Ombi.Controllers private IMapper Mapper { get; } [HttpGet] - public async Task GetUser() + public async Task GetUser() { - return await IdentityManager.GetUser(this.HttpContext.User.Identity.Name); + return Mapper.Map(await IdentityManager.GetUser(this.HttpContext.User.Identity.Name)); } diff --git a/Ombi/Ombi/Controllers/RequestController.cs b/Ombi/Ombi/Controllers/RequestController.cs index 3b5135d85..6315af805 100644 --- a/Ombi/Ombi/Controllers/RequestController.cs +++ b/Ombi/Ombi/Controllers/RequestController.cs @@ -17,17 +17,12 @@ namespace Ombi.Controllers } private IRequestEngine RequestEngine { get; } + - [HttpGet] - public async Task> GetRequests() + [HttpGet("movie/{count:int}/{position:int}", Name = "GetRequestsByCount")] + public async Task> GetRequests(int count, int position) { - return await RequestEngine.GetRequests(); - } - - [HttpGet("{count:int}/{position:int}", Name = "GetRequestsByCount")] - public async Task> GetRequests(int count, int position) - { - return await RequestEngine.GetRequests(count, position); + return await RequestEngine.GetMovieRequests(count, position); } [HttpPost("movie")] @@ -36,23 +31,29 @@ namespace Ombi.Controllers return await RequestEngine.RequestMovie(movie); } - [HttpGet("search/{searchTerm}")] - public async Task> Search(string searchTerm) + //[HttpPost("tv")] + //public async Task RequestTv([FromBody]SearchTvShowViewModel tv) + //{ + // return await RequestEngine.RequestMovie(); + //} + + [HttpGet("movie/search/{searchTerm}")] + public async Task> Search(string searchTerm) { - return await RequestEngine.SearchRequest(searchTerm); + return await RequestEngine.SearchMovieRequest(searchTerm); } - [HttpDelete("{requestId:int}")] + [HttpDelete("movie/{requestId:int}")] public async Task DeleteRequest(int requestId) { - await RequestEngine.RemoveRequest(requestId); + await RequestEngine.RemoveMovieRequest(requestId); } - [HttpPost] - public async Task UpdateRequest([FromBody]RequestViewModel model) + [HttpPut("movie")] + public async Task UpdateRequest([FromBody]MovieRequestModel model) { - return await RequestEngine.UpdateRequest(model); + return await RequestEngine.UpdateMovieRequest(model); } } } diff --git a/Ombi/Ombi/Controllers/SearchController.cs b/Ombi/Ombi/Controllers/SearchController.cs index a0f7e254f..3ecccc264 100644 --- a/Ombi/Ombi/Controllers/SearchController.cs +++ b/Ombi/Ombi/Controllers/SearchController.cs @@ -64,5 +64,26 @@ namespace Ombi.Controllers { return await TvEngine.Search(searchTerm); } + + //[HttpGet("tv/popular")] + //public async Task> PopularTv() + //{ + // return await TvEngine.Popular(); + //} + //[HttpGet("tv/anticiplated")] + //public async Task> AnticiplatedTv() + //{ + // return await TvEngine.Anticipated(); + //} + //[HttpGet("tv/mostwatched")] + //public async Task> MostWatched() + //{ + // return await TvEngine.MostWatches(); + //} + //[HttpGet("tv/trending")] + //public async Task> Trending() + //{ + // return await TvEngine.Trending(); + //} } } diff --git a/Ombi/Ombi/package.json b/Ombi/Ombi/package.json index e0de6c4c5..a752a5410 100644 --- a/Ombi/Ombi/package.json +++ b/Ombi/Ombi/package.json @@ -16,7 +16,7 @@ "@angular/router": "^4.1.0", "@types/jquery": "^2.0.33", "@types/systemjs": "^0.20.2", - "angular2-jwt": "0.2.0", + "angular2-jwt": "^0.2.0", "angular2-moment": "^1.3.3", "bootstrap": "3.3.6", "core-js": "^2.4.1", diff --git a/Ombi/Ombi/wwwroot/app/app.component.html b/Ombi/Ombi/wwwroot/app/app.component.html index f8cf77a2e..c6be459a7 100644 --- a/Ombi/Ombi/wwwroot/app/app.component.html +++ b/Ombi/Ombi/wwwroot/app/app.component.html @@ -9,10 +9,11 @@ - -
- {{customizationSettings.applicationName}} - Ombi + @@ -26,7 +27,7 @@