diff --git a/src/Ombi.Core/Engine/IRecentlyAddedEngine.cs b/src/Ombi.Core/Engine/IRecentlyAddedEngine.cs index 5b2988c8e..c119abbb4 100644 --- a/src/Ombi.Core/Engine/IRecentlyAddedEngine.cs +++ b/src/Ombi.Core/Engine/IRecentlyAddedEngine.cs @@ -8,5 +8,7 @@ namespace Ombi.Core.Engine { IEnumerable GetRecentlyAddedMovies(); IEnumerable GetRecentlyAddedMovies(DateTime from, DateTime to); + IEnumerable GetRecentlyAddedTv(DateTime from, DateTime to, bool groupBySeason); + IEnumerable GetRecentlyAddedTv(bool groupBySeason); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/RecentlyAddedEngine.cs b/src/Ombi.Core/Engine/RecentlyAddedEngine.cs index bfea4dba2..b8cc0ee6b 100644 --- a/src/Ombi.Core/Engine/RecentlyAddedEngine.cs +++ b/src/Ombi.Core/Engine/RecentlyAddedEngine.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Ombi.Core.Models; +using Ombi.Helpers; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -24,22 +25,54 @@ namespace Ombi.Core.Engine public IEnumerable GetRecentlyAddedMovies(DateTime from, DateTime to) { - var model = new HashSet(); var plexMovies = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Movie && x.AddedAt > from && x.AddedAt < to); var embyMovies = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Movie && x.AddedAt > from && x.AddedAt < to); - - TransformPlexMovies(plexMovies, model); - TransformEmbyMovies(embyMovies, model); - - return model.Take(30); + + return GetRecentlyAddedMovies(plexMovies, embyMovies).Take(30); } public IEnumerable GetRecentlyAddedMovies() { - var model = new HashSet(); var plexMovies = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Movie); var embyMovies = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Movie); + return GetRecentlyAddedMovies(plexMovies, embyMovies); + } + + public IEnumerable GetRecentlyAddedTv(DateTime from, DateTime to, bool groupBySeason) + { + var plexTv = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Show && x.AddedAt > from && x.AddedAt < to); + var embyTv = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Series && x.AddedAt > from && x.AddedAt < to); + + return GetRecentlyAddedTv(plexTv, embyTv, groupBySeason).Take(30); + } + + + public IEnumerable GetRecentlyAddedTv(bool groupBySeason) + { + var plexTv = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Show); + var embyTv = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Series); + + return GetRecentlyAddedTv(plexTv, embyTv, groupBySeason); + } + + private IEnumerable GetRecentlyAddedTv(IQueryable plexTv, IQueryable embyTv, + bool groupBySeason) + { + var model = new HashSet(); + TransformPlexShows(plexTv, model); + TransformEmbyShows(embyTv, model); + + if (groupBySeason) + { + return model.DistinctBy(x => x.SeasonNumber); + } + + return model; + } + private IEnumerable GetRecentlyAddedMovies(IQueryable plexMovies, IQueryable embyMovies) + { + var model = new HashSet(); TransformPlexMovies(plexMovies, model); TransformEmbyMovies(embyMovies, model); @@ -76,5 +109,50 @@ namespace Ombi.Core.Engine }); } } + + private static void TransformPlexShows(IQueryable plexShows, HashSet model) + { + foreach (var plex in plexShows) + { + foreach (var season in plex.Seasons) + { + foreach (var episode in plex.Episodes) + { + model.Add(new RecentlyAddedTvModel + { + Id = plex.Id, + ImdbId = plex.ImdbId, + TheMovieDbId = plex.TheMovieDbId, + AddedAt = plex.AddedAt, + Title = plex.Title, + Quality = plex.Quality, + ReleaseYear = plex.ReleaseYear, + TvDbId = plex.TvDbId, + EpisodeNumber = episode.EpisodeNumber, + SeasonNumber = season.SeasonNumber + }); + } + } + } + } + + private static void TransformEmbyShows(IQueryable embyShows, HashSet model) + { + foreach (var emby in embyShows) + { + foreach (var episode in emby.Episodes) + { + model.Add(new RecentlyAddedTvModel + { + Id = emby.Id, + ImdbId = emby.ProviderId, + AddedAt = emby.AddedAt, + Title = emby.Title, + EpisodeNumber = episode.EpisodeNumber, + SeasonNumber = episode.SeasonNumber + }); + } + } + } } } diff --git a/src/Ombi.Core/Models/RecentlyAddedTvModel.cs b/src/Ombi.Core/Models/RecentlyAddedTvModel.cs new file mode 100644 index 000000000..dd485604d --- /dev/null +++ b/src/Ombi.Core/Models/RecentlyAddedTvModel.cs @@ -0,0 +1,19 @@ +using System; + +namespace Ombi.Core.Models +{ + public class RecentlyAddedTvModel + { + public int Id { get; set; } + public string Title { get; set; } // Series Title + 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 int SeasonNumber { get; set; } + public int EpisodeNumber { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/interfaces/IRecentlyAdded.ts b/src/Ombi/ClientApp/app/interfaces/IRecentlyAdded.ts index bce430f76..357a70d8b 100644 --- a/src/Ombi/ClientApp/app/interfaces/IRecentlyAdded.ts +++ b/src/Ombi/ClientApp/app/interfaces/IRecentlyAdded.ts @@ -12,6 +12,11 @@ export interface IRecentlyAddedMovies { posterPath: string; } +export interface IRecentlyAddedTvShows extends IRecentlyAddedMovies { + seasonNumber: number; + episodeNumber: number; +} + export interface IRecentlyAddedRangeModel { from: Date; to: Date; diff --git a/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.html b/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.html index 85c231a40..f9234f4a4 100644 --- a/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.html +++ b/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.html @@ -4,16 +4,26 @@
- - + poster + {{movie.title}} - - + + -
\ No newline at end of file + +
+ + + + poster + {{t.title}} + + + + + diff --git a/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.ts b/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.ts index 660a83d52..d540a6b2d 100644 --- a/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.ts +++ b/src/Ombi/ClientApp/app/recentlyAdded/recentlyAdded.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from "@angular/core"; import { NguCarousel } from "@ngu/carousel"; import { ImageService, RecentlyAddedService } from "../services"; -import { IRecentlyAddedMovies, IRecentlyAddedRangeModel } from "./../interfaces"; +import { IRecentlyAddedMovies, IRecentlyAddedTvShows } from "./../interfaces"; @Component({ templateUrl: "recentlyAdded.component.html", @@ -15,8 +15,9 @@ import { IRecentlyAddedMovies, IRecentlyAddedRangeModel } from "./../interfaces" width: 50px; height: 50px; box-shadow: 1px 2px 10px -1px rgba(0, 0, 0, .3); - border-radius: 999px; + border-radius: 100%; left: 0; + background: #df691a; } .rightRs { @@ -27,14 +28,16 @@ import { IRecentlyAddedMovies, IRecentlyAddedRangeModel } from "./../interfaces" width: 50px; height: 50px; box-shadow: 1px 2px 10px -1px rgba(0, 0, 0, .3); - border-radius: 999px; + border-radius: 100%; right: 0; + background: #df691a; } `], }) export class RecentlyAddedComponent implements OnInit { public movies: IRecentlyAddedMovies[]; + public tv: IRecentlyAddedTvShows[]; public range: Date[]; // https://github.com/sheikalthaf/ngu-carousel @@ -44,28 +47,8 @@ export class RecentlyAddedComponent implements OnInit { private imageService: ImageService) {} public ngOnInit() { - const weekAgo = new Date(); - weekAgo.setDate(weekAgo.getDate() - 7); - - const today =new Date(); - const initModel = {from: weekAgo, to: today}; - this.recentlyAddedService.getRecentlyAddedMovies(initModel).subscribe(x => { - this.movies = x; - - this.movies.forEach((movie) => { - if(movie.theMovieDbId) { - this.imageService.getMoviePoster(movie.theMovieDbId).subscribe(p => { - movie.posterPath = p; - }); - } else if(movie.imdbId) { - this.imageService.getMoviePoster(movie.imdbId).subscribe(p => { - movie.posterPath = p; - }); - } else { - movie.posterPath = ""; - } - }); - }); + this.getMovies(); + this.getShows(); this.carouselTile = { grid: {xs: 2, sm: 3, md: 3, lg: 5, all: 0}, @@ -89,12 +72,46 @@ export class RecentlyAddedComponent implements OnInit { // If we do not have a second date then just set it to now this.range[1] = new Date(); } - const initModel = {from: this.range[0], to: this.range[1]}; - this.recentlyAddedService.getRecentlyAddedMovies(initModel).subscribe(x => this.movies = x); + this.getMovies(); } - - public page(event: any) { - debugger; - console.log(event); + + private getShows() { + this.recentlyAddedService.getRecentlyAddedTv().subscribe(x => { + this.tv = x; + + this.tv.forEach((t) => { + if(t.theMovieDbId) { + this.imageService.getTvPoster(t.imdbId).subscribe(p => { + t.posterPath = p; + }); + } else if(t.imdbId) { + this.imageService.getMoviePoster(t.imdbId).subscribe(p => { + t.posterPath = p; + }); + } else { + t.posterPath = ""; + } + }); + }); + } + + private getMovies() { + this.recentlyAddedService.getRecentlyAddedMovies().subscribe(x => { + this.movies = x; + + this.movies.forEach((movie) => { + if(movie.theMovieDbId) { + this.imageService.getMoviePoster(movie.theMovieDbId).subscribe(p => { + movie.posterPath = p; + }); + } else if(movie.imdbId) { + this.imageService.getMoviePoster(movie.imdbId).subscribe(p => { + movie.posterPath = p; + }); + } else { + movie.posterPath = ""; + } + }); + }); } } diff --git a/src/Ombi/ClientApp/app/services/recentlyAdded.service.ts b/src/Ombi/ClientApp/app/services/recentlyAdded.service.ts index 55059ec76..366c6e583 100644 --- a/src/Ombi/ClientApp/app/services/recentlyAdded.service.ts +++ b/src/Ombi/ClientApp/app/services/recentlyAdded.service.ts @@ -4,7 +4,7 @@ import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; -import { IRecentlyAddedMovies, IRecentlyAddedRangeModel } from "./../interfaces"; +import { IRecentlyAddedMovies, IRecentlyAddedTvShows } from "./../interfaces"; import { ServiceHelpers } from "./service.helpers"; @Injectable() @@ -12,7 +12,14 @@ export class RecentlyAddedService extends ServiceHelpers { constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/recentlyadded/", platformLocation); } - public getRecentlyAddedMovies(model: IRecentlyAddedRangeModel): Observable { - return this.http.post(`${this.url}movies/`,JSON.stringify(model), {headers: this.headers}); + public getRecentlyAddedMovies(): Observable { + return this.http.get(`${this.url}movies/`, {headers: this.headers}); + } + + public getRecentlyAddedTv(): Observable { + return this.http.get(`${this. url}tv/`, {headers: this.headers}); + } + public getRecentlyAddedTvGrouped(): Observable { + return this.http.get(`${this.url}tv/grouped`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/settings/settings.module.ts b/src/Ombi/ClientApp/app/settings/settings.module.ts index c95aa4362..29866a273 100644 --- a/src/Ombi/ClientApp/app/settings/settings.module.ts +++ b/src/Ombi/ClientApp/app/settings/settings.module.ts @@ -140,4 +140,4 @@ const routes: Routes = [ ], }) -export class SettingsModule { } \ No newline at end of file +export class SettingsModule { } diff --git a/src/Ombi/Controllers/ImagesController.cs b/src/Ombi/Controllers/ImagesController.cs index 182fb9a3a..2cee60476 100644 --- a/src/Ombi/Controllers/ImagesController.cs +++ b/src/Ombi/Controllers/ImagesController.cs @@ -67,12 +67,17 @@ namespace Ombi.Controllers if (images.movieposter?.Any() ?? false) { - return images.movieposter.OrderBy(x => x.likes).Select(x => x.url).FirstOrDefault(); + var enImage = images.movieposter.Where(x => x.lang == "en").OrderByDescending(x => x.likes).Select(x => x.url).FirstOrDefault(); + if (enImage == null) + { + return images.movieposter.OrderByDescending(x => x.likes).Select(x => x.url).FirstOrDefault(); + } + return enImage; } - if (images.hdmovieclearart?.Any() ?? false) + if (images.moviethumb?.Any() ?? false) { - return images.hdmovieclearart.OrderBy(x => x.likes).Select(x => x.url).FirstOrDefault(); + return images.moviethumb.OrderBy(x => x.likes).Select(x => x.url).FirstOrDefault(); } return string.Empty; diff --git a/src/Ombi/Controllers/RecentlyAddedController.cs b/src/Ombi/Controllers/RecentlyAddedController.cs index c2574bee3..fb4446efd 100644 --- a/src/Ombi/Controllers/RecentlyAddedController.cs +++ b/src/Ombi/Controllers/RecentlyAddedController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -21,13 +22,33 @@ namespace Ombi.Controllers private readonly IRecentlyAddedEngine _recentlyAdded; /// - /// Returns the recently added movies between two dates + /// Returns the recently added movies for the past 7 days /// - [HttpPost("movies")] + [HttpGet("movies")] [ProducesResponseType(typeof(IEnumerable), 200)] - public IEnumerable GetRecentlyAddedMovies([FromBody] RecentlyAddedRangeModel model) + public IEnumerable GetRecentlyAddedMovies() { - return _recentlyAdded.GetRecentlyAddedMovies(model.From, model.To); + return _recentlyAdded.GetRecentlyAddedMovies(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow); + } + + /// + /// Returns the recently added tv shows for the past 7 days + /// + [HttpGet("tv")] + [ProducesResponseType(typeof(IEnumerable), 200)] + public IEnumerable GetRecentlyAddedShows() + { + return _recentlyAdded.GetRecentlyAddedTv(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow, false); + } + + /// + /// Returns the recently added tv shows for the past 7 days and groups them by season + /// + [HttpGet("tv/grouped")] + [ProducesResponseType(typeof(IEnumerable), 200)] + public IEnumerable GetRecentlyAddedShowsGrouped() + { + return _recentlyAdded.GetRecentlyAddedTv(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow, true); } } } \ No newline at end of file diff --git a/src/Ombi/Models/RecentlyAddedRangeModel.cs b/src/Ombi/Models/RecentlyAddedRangeModel.cs deleted file mode 100644 index 208f9cb49..000000000 --- a/src/Ombi/Models/RecentlyAddedRangeModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Ombi.Models -{ - public class RecentlyAddedRangeModel - { - public DateTime From { get; set; } - public DateTime To { get; set; } - } -} \ No newline at end of file