diff --git a/src/NzbDrone.Api/Series/MovieDiscoverModule.cs b/src/NzbDrone.Api/Series/MovieDiscoverModule.cs index e99de8ecd..7d6400d5c 100644 --- a/src/NzbDrone.Api/Series/MovieDiscoverModule.cs +++ b/src/NzbDrone.Api/Series/MovieDiscoverModule.cs @@ -17,12 +17,12 @@ namespace NzbDrone.Api.Movie : base("/movies/discover") { _searchProxy = searchProxy; - Get["/"] = x => Search(); + Get["/{action?recommendations}"] = x => Search(x.action); } - private Response Search() + private Response Search(string action) { - var imdbResults = _searchProxy.DiscoverNewMovies(); + var imdbResults = _searchProxy.DiscoverNewMovies(action); return MapToResource(imdbResults).AsResponse(); } diff --git a/src/NzbDrone.Core/MetadataSource/IDiscoverNewMovies.cs b/src/NzbDrone.Core/MetadataSource/IDiscoverNewMovies.cs index 4a04e47d9..108d8e1a4 100644 --- a/src/NzbDrone.Core/MetadataSource/IDiscoverNewMovies.cs +++ b/src/NzbDrone.Core/MetadataSource/IDiscoverNewMovies.cs @@ -5,6 +5,6 @@ namespace NzbDrone.Core.MetadataSource { public interface IDiscoverNewMovies { - List DiscoverNewMovies(); + List DiscoverNewMovies(string action); } } \ No newline at end of file diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index c656c02a6..d52cbc4b5 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -349,31 +349,57 @@ namespace NzbDrone.Core.MetadataSource.SkyHook return resources.movie_results.SelectList(MapMovie).FirstOrDefault(); } - public List DiscoverNewMovies() + public List DiscoverNewMovies(string action) { string allIds = string.Join(",", _movieService.GetAllMovies().Select(m => m.TmdbId)); - var request = new HttpRequestBuilder("https://radarr.video/recommendations/api.php").Build(); - - request.AllowAutoRedirect = true; - request.Method = HttpMethod.POST; - request.Headers.ContentType = "application/x-www-form-urlencoded"; - request.SetContent($"tmdbids={allIds}"); + HttpRequest request; + List results; - var response = _httpClient.Post>(request); - if (response.StatusCode != HttpStatusCode.OK) + if (action == "upcoming") { - throw new HttpException(request, response); - } + var lastWeek = DateTime.Now.AddDays(-7); + var threeWeeks = DateTime.Now.AddDays(7 * 3); - if (response.Headers.ContentType != HttpAccept.Json.Value) - { - throw new HttpException(request, response); + request = _movieBuilder.Create().SetSegment("route", "discover") + .SetSegment("id", "movie") + .SetSegment("secondaryRoute", "") + .AddQueryParam("region", "us") + .AddQueryParam("with_release_type", "5|4|6") + .AddQueryParam("release_date.gte", lastWeek.ToString("yyyy-MM-dd")) + .AddQueryParam("sort_by", "popularity.desc") + .AddQueryParam("release_date.lte", threeWeeks.ToString("yyyy-MM-dd")).Build(); + + + var response = _httpClient.Get(request); + + if (response.StatusCode != HttpStatusCode.OK) + { + throw new HttpException(request, response); + } + + results = response.Resource.results.ToList(); } + else + { + request = new HttpRequestBuilder("https://radarr.video/api/{action}/").SetSegment("action", action).Build(); - var movieResults = response.Resource; + request.AllowAutoRedirect = true; + request.Method = HttpMethod.POST; + request.Headers.ContentType = "application/x-www-form-urlencoded"; + request.SetContent($"tmdbids={allIds}"); - return movieResults.SelectList(MapMovie); + var response = _httpClient.Post>(request); + + if (response.StatusCode != HttpStatusCode.OK) + { + throw new HttpException(request, response); + } + + results = response.Resource; + } + + return results.SelectList(MapMovie); } private string StripTrailingTheFromTitle(string title) diff --git a/src/UI/AddMovies/AddMoviesView.js b/src/UI/AddMovies/AddMoviesView.js index 51dda6128..c5f583803 100644 --- a/src/UI/AddMovies/AddMoviesView.js +++ b/src/UI/AddMovies/AddMoviesView.js @@ -21,11 +21,18 @@ module.exports = Marionette.Layout.extend({ moviesSearch : '.x-movies-search', searchBar : '.x-search-bar', loadMore : '.x-load-more', - discoverHeader : ".x-discover-header" + discoverHeader : ".x-discover-header", + discoverBefore : ".x-discover-before", + discoverRecos : ".x-recommendations-tab", + discoverPopular : ".x-popular-tab" , + discoverUpcoming : ".x-upcoming-tab" }, events : { - 'click .x-load-more' : '_onLoadMore' + 'click .x-load-more' : '_onLoadMore', + "click .x-recommendations-tab" : "_discoverRecos", + "click .x-popular-tab" : "_discoverPopular", + "click .x-upcoming-tab" : "_discoverUpcoming" }, initialize : function(options) { @@ -56,11 +63,6 @@ module.exports = Marionette.Layout.extend({ this.search({term: options.query}); } else if (options.action == "discover") { this.isDiscover = true; - if (FullMovieCollection.length > 0) { - this._discover(); - } else { - this.listenTo(FullMovieCollection, "sync", this._discover); - } } }, @@ -110,6 +112,11 @@ module.exports = Marionette.Layout.extend({ if (this.isDiscover) { this.ui.searchBar.hide(); + if (FullMovieCollection.length > 0) { + this._discoverRecos(); + } else { + this.listenTo(FullMovieCollection, "sync", this._discover); + } if (this.collection.length == 0) { this.searchResult.show(new LoadingView()); } @@ -117,10 +124,10 @@ module.exports = Marionette.Layout.extend({ }, onShow : function() { - this.ui.discoverHeader.hide(); + this.ui.discoverBefore.hide(); this.ui.moviesSearch.focus(); if (this.isDiscover) { - this.ui.discoverHeader.show(); + this.ui.discoverBefore.show(); } }, @@ -213,7 +220,34 @@ module.exports = Marionette.Layout.extend({ } }, - _discover : function() { - this.collection.fetch() - } + _discover : function(action) { + if (this.collection.action === action) { + return + } + this.searchResult.show(new LoadingView()); + this.collection.action = action; + this.collection.fetch({ + data : { action : action } + }); + }, + + _discoverRecos : function() { + this.ui.discoverRecos.tab("show"); + this.ui.discoverHeader.html("Recommendations by The Movie Database for you"); + this._discover("recommendations"); + }, + + _discoverPopular : function() { + this.ui.discoverPopular.tab("show"); + this.ui.discoverHeader.html("Currently Popular Movies"); + this._discover("popular"); + }, + + _discoverUpcoming : function() { + this.ui.discoverUpcoming.tab("show"); + this.ui.discoverHeader.html("Movies coming to Blu-Ray in the next weeks"); + this._discover("upcoming"); + }, + + }); diff --git a/src/UI/AddMovies/AddMoviesViewTemplate.hbs b/src/UI/AddMovies/AddMoviesViewTemplate.hbs index 2fc612744..6fb4e54b2 100644 --- a/src/UI/AddMovies/AddMoviesViewTemplate.hbs +++ b/src/UI/AddMovies/AddMoviesViewTemplate.hbs @@ -4,9 +4,18 @@ {{folder.path}} {{/if}} -

- Recommendations by The Movie Database based on your library: -

+ +
+ +

+ Recommendations by The Movie Database based on your library: +

+
+