parent
3e3b2a7784
commit
2d59192a9e
@ -0,0 +1,14 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(176)]
|
||||
public class movie_recommendations : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("Movies").AddColumn("Recommendations").AsString().WithDefaultValue("[]");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class RecommendationResource
|
||||
{
|
||||
public int TmdbId { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.NetImport.ImportExclusions;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace NzbDrone.Api.V3.Movies
|
||||
{
|
||||
public class DiscoverMoviesModule : RadarrRestModule<DiscoverMoviesResource>
|
||||
{
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IProvideMovieInfo _movieInfo;
|
||||
private readonly IBuildFileNames _fileNameBuilder;
|
||||
private readonly IImportExclusionsService _importExclusionService;
|
||||
|
||||
public DiscoverMoviesModule(IMovieService movieService, IProvideMovieInfo movieInfo, IBuildFileNames fileNameBuilder, IImportExclusionsService importExclusionsService)
|
||||
: base("/movies/discover")
|
||||
{
|
||||
_movieService = movieService;
|
||||
_movieInfo = movieInfo;
|
||||
_fileNameBuilder = fileNameBuilder;
|
||||
_importExclusionService = importExclusionsService;
|
||||
Get("/", x => GetDiscoverMovies());
|
||||
}
|
||||
|
||||
private object GetDiscoverMovies()
|
||||
{
|
||||
var results = _movieService.GetRecommendedMovies();
|
||||
|
||||
var mapped = new List<Movie>();
|
||||
|
||||
if (results.Count > 0)
|
||||
{
|
||||
mapped = _movieInfo.GetBulkMovieInfo(results.Select(m => m.TmdbId).ToList());
|
||||
}
|
||||
|
||||
var realResults = new List<Movie>();
|
||||
|
||||
realResults.AddRange(mapped.Where(x => x != null));
|
||||
|
||||
return MapToResource(realResults);
|
||||
}
|
||||
|
||||
private IEnumerable<DiscoverMoviesResource> MapToResource(IEnumerable<Movie> movies)
|
||||
{
|
||||
foreach (var currentMovie in movies)
|
||||
{
|
||||
var resource = currentMovie.ToResource(_movieService, _importExclusionService);
|
||||
var poster = currentMovie.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
|
||||
if (poster != null)
|
||||
{
|
||||
resource.RemotePoster = poster.Url;
|
||||
}
|
||||
|
||||
resource.Folder = _fileNameBuilder.GetMovieFolder(currentMovie);
|
||||
|
||||
yield return resource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.NetImport.ImportExclusions;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace NzbDrone.Api.V3.Movies
|
||||
{
|
||||
public class DiscoverMoviesResource : RestResource
|
||||
{
|
||||
//View Only
|
||||
public string Title { get; set; }
|
||||
public string SortTitle { get; set; }
|
||||
public string TitleSlug { get; set; }
|
||||
public MovieStatusType Status { get; set; }
|
||||
public string Overview { get; set; }
|
||||
public DateTime? InCinemas { get; set; }
|
||||
public DateTime? PhysicalRelease { get; set; }
|
||||
public List<MediaCover> Images { get; set; }
|
||||
public string Website { get; set; }
|
||||
public string RemotePoster { get; set; }
|
||||
public int Year { get; set; }
|
||||
public string YouTubeTrailerId { get; set; }
|
||||
public string Studio { get; set; }
|
||||
|
||||
public int Runtime { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
public int TmdbId { get; set; }
|
||||
public string Folder { get; set; }
|
||||
public string Certification { get; set; }
|
||||
public List<string> Genres { get; set; }
|
||||
public Ratings Ratings { get; set; }
|
||||
public MovieCollection Collection { get; set; }
|
||||
public bool IsExcluded { get; set; }
|
||||
public bool IsExisting { get; set; }
|
||||
}
|
||||
|
||||
public static class DiscoverMoviesResourceMapper
|
||||
{
|
||||
public static DiscoverMoviesResource ToResource(this Movie model, IMovieService movieService, IImportExclusionsService importExclusionService)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new DiscoverMoviesResource
|
||||
{
|
||||
TmdbId = model.TmdbId,
|
||||
Title = model.Title,
|
||||
SortTitle = model.SortTitle,
|
||||
TitleSlug = model.TitleSlug,
|
||||
InCinemas = model.InCinemas,
|
||||
PhysicalRelease = model.PhysicalRelease,
|
||||
|
||||
Status = model.Status,
|
||||
Overview = model.Overview,
|
||||
|
||||
Images = model.Images,
|
||||
|
||||
Year = model.Year,
|
||||
|
||||
Runtime = model.Runtime,
|
||||
ImdbId = model.ImdbId,
|
||||
Certification = model.Certification,
|
||||
Website = model.Website,
|
||||
Genres = model.Genres,
|
||||
Ratings = model.Ratings,
|
||||
YouTubeTrailerId = model.YouTubeTrailerId,
|
||||
Studio = model.Studio,
|
||||
Collection = model.Collection,
|
||||
IsExcluded = importExclusionService.IsMovieExcluded(model.TmdbId),
|
||||
IsExisting = movieService.FindByTmdbId(model.TmdbId) != null,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue