Made a start on adding tv shows for the recently added !wip

pull/2089/head
Jamie 7 years ago
parent 0e94270f84
commit df95962aa6

@ -8,5 +8,7 @@ namespace Ombi.Core.Engine
{
IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies();
IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies(DateTime from, DateTime to);
IEnumerable<RecentlyAddedTvModel> GetRecentlyAddedTv(DateTime from, DateTime to, bool groupBySeason);
IEnumerable<RecentlyAddedTvModel> GetRecentlyAddedTv(bool groupBySeason);
}
}

@ -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<RecentlyAddedMovieModel> GetRecentlyAddedMovies(DateTime from, DateTime to)
{
var model = new HashSet<RecentlyAddedMovieModel>();
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<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);
return GetRecentlyAddedMovies(plexMovies, embyMovies);
}
public IEnumerable<RecentlyAddedTvModel> 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<RecentlyAddedTvModel> 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<RecentlyAddedTvModel> GetRecentlyAddedTv(IQueryable<PlexServerContent> plexTv, IQueryable<EmbyContent> embyTv,
bool groupBySeason)
{
var model = new HashSet<RecentlyAddedTvModel>();
TransformPlexShows(plexTv, model);
TransformEmbyShows(embyTv, model);
if (groupBySeason)
{
return model.DistinctBy(x => x.SeasonNumber);
}
return model;
}
private IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies(IQueryable<PlexServerContent> plexMovies, IQueryable<EmbyContent> embyMovies)
{
var model = new HashSet<RecentlyAddedMovieModel>();
TransformPlexMovies(plexMovies, model);
TransformEmbyMovies(embyMovies, model);
@ -76,5 +109,50 @@ namespace Ombi.Core.Engine
});
}
}
private static void TransformPlexShows(IQueryable<PlexServerContent> plexShows, HashSet<RecentlyAddedTvModel> 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<EmbyContent> embyShows, HashSet<RecentlyAddedTvModel> 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
});
}
}
}
}
}

@ -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; }
}
}

@ -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;

@ -4,16 +4,26 @@
<p-calendar [(ngModel)]="range" showButtonBar="true" selectionMode="range" (onClose)="close()"></p-calendar>
<hr />
<ngu-carousel
[inputs]="carouselTile">
<ngu-carousel [inputs]="carouselTile">
<ngu-tile NguCarouselItem *ngFor="let movie of movies">
<img class="img-responsive poster" src="{{movie.posterPath}}" style="width: 300px" alt="poster">
<b>{{movie.title}}</b>
</ngu-tile>
<button NguCarouselPrev class='leftRs'>&lt;</button>
<button NguCarouselNext class='rightRs'>&gt;</button>
<button NguCarouselPrev class='leftRs'><i class="fa fa-arrow-left"></i></button>
<button NguCarouselNext class='rightRs'><i class="fa fa-arrow-right"></i></button>
</ngu-carousel>
<hr/>
<hr/>
<ngu-carousel [inputs]="carouselTile">
<ngu-tile NguCarouselItem *ngFor="let t of tv">
<img class="img-responsive poster" src="{{t.posterPath}}" style="width: 300px" alt="poster">
<b>{{t.title}}</b>
</ngu-tile>
<button NguCarouselPrev class='leftRs'><i class="fa fa-arrow-left"></i></button>
<button NguCarouselNext class='rightRs'><i class="fa fa-arrow-right"></i></button>
</ngu-carousel>

@ -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 = <IRecentlyAddedRangeModel>{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 = <IRecentlyAddedRangeModel>{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 = "";
}
});
});
}
}

@ -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<IRecentlyAddedMovies[]> {
return this.http.post<IRecentlyAddedMovies[]>(`${this.url}movies/`,JSON.stringify(model), {headers: this.headers});
public getRecentlyAddedMovies(): Observable<IRecentlyAddedMovies[]> {
return this.http.get<IRecentlyAddedMovies[]>(`${this.url}movies/`, {headers: this.headers});
}
public getRecentlyAddedTv(): Observable<IRecentlyAddedTvShows[]> {
return this.http.get<IRecentlyAddedTvShows[]>(`${this. url}tv/`, {headers: this.headers});
}
public getRecentlyAddedTvGrouped(): Observable<IRecentlyAddedTvShows[]> {
return this.http.get<IRecentlyAddedTvShows[]>(`${this.url}tv/grouped`, {headers: this.headers});
}
}

@ -140,4 +140,4 @@ const routes: Routes = [
],
})
export class SettingsModule { }
export class SettingsModule { }

@ -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;

@ -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;
/// <summary>
/// Returns the recently added movies between two dates
/// Returns the recently added movies for the past 7 days
/// </summary>
[HttpPost("movies")]
[HttpGet("movies")]
[ProducesResponseType(typeof(IEnumerable<RecentlyAddedMovieModel>), 200)]
public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies([FromBody] RecentlyAddedRangeModel model)
public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies()
{
return _recentlyAdded.GetRecentlyAddedMovies(model.From, model.To);
return _recentlyAdded.GetRecentlyAddedMovies(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow);
}
/// <summary>
/// Returns the recently added tv shows for the past 7 days
/// </summary>
[HttpGet("tv")]
[ProducesResponseType(typeof(IEnumerable<RecentlyAddedMovieModel>), 200)]
public IEnumerable<RecentlyAddedTvModel> GetRecentlyAddedShows()
{
return _recentlyAdded.GetRecentlyAddedTv(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow, false);
}
/// <summary>
/// Returns the recently added tv shows for the past 7 days and groups them by season
/// </summary>
[HttpGet("tv/grouped")]
[ProducesResponseType(typeof(IEnumerable<RecentlyAddedMovieModel>), 200)]
public IEnumerable<RecentlyAddedTvModel> GetRecentlyAddedShowsGrouped()
{
return _recentlyAdded.GetRecentlyAddedTv(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow, true);
}
}
}

@ -1,10 +0,0 @@
using System;
namespace Ombi.Models
{
public class RecentlyAddedRangeModel
{
public DateTime From { get; set; }
public DateTime To { get; set; }
}
}
Loading…
Cancel
Save