From b6299f00675100d48cb554427bec18ae08808438 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 26 Jan 2017 11:44:21 +0000 Subject: [PATCH 1/9] Debug info around the notifications --- .../Notification/NotificationEngine.cs | 18 ++++++++++++++++++ Ombi.Store/RequestedModel.cs | 10 +--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Ombi.Services/Notification/NotificationEngine.cs b/Ombi.Services/Notification/NotificationEngine.cs index 01b50898b..49340ca1a 100644 --- a/Ombi.Services/Notification/NotificationEngine.cs +++ b/Ombi.Services/Notification/NotificationEngine.cs @@ -154,7 +154,25 @@ namespace Ombi.Services.Notification // Get the usernames or alias depending if they have an alias var userNamesWithFeature = users.Select(x => x.UsernameOrAlias).ToList(); + Log.Debug("Users with the feature count {0}", userNamesWithFeature.Count); + Log.Debug("Usernames: "); + foreach (var u in userNamesWithFeature) + { + Log.Debug(u); + } + Log.Debug("Users in the requested model count: {0}", model.AllUsers.Count); + Log.Debug("usernames from model: "); + foreach (var modelAllUser in model.AllUsers) + { + Log.Debug(modelAllUser); + } + + if (model.AllUsers == null || !model.AllUsers.Any()) + { + Log.Debug("There are no users in the model.AllUsers, no users to notify"); + return; + } var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase).ToList(); if (!usersToNotify.Any()) diff --git a/Ombi.Store/RequestedModel.cs b/Ombi.Store/RequestedModel.cs index 6d0342a14..c54d68e5c 100644 --- a/Ombi.Store/RequestedModel.cs +++ b/Ombi.Store/RequestedModel.cs @@ -27,9 +27,6 @@ namespace Ombi.Store public string Status { get; set; } public bool Approved { get; set; } - [Obsolete("Use RequestedUsers")] //TODO remove this obsolete property - public string RequestedBy { get; set; } - public DateTime RequestedDate { get; set; } public bool Available { get; set; } public IssueState Issues { get; set; } @@ -60,14 +57,9 @@ namespace Ombi.Store get { var u = new List(); - if (!string.IsNullOrEmpty(RequestedBy)) - { - u.Add(RequestedBy); - } - if (RequestedUsers != null && RequestedUsers.Any()) { - u.AddRange(RequestedUsers.Where(requestedUser => requestedUser != RequestedBy)); + u.AddRange(RequestedUsers); } return u; } From 16c94f2414a6937d51650977782fad77009e2746 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 26 Jan 2017 16:30:40 +0000 Subject: [PATCH 2/9] Additional movie information --- Ombi.Api.Models/Movie/TmdbMovieDetails.cs | 104 +++++++++++++++ Ombi.Api.Models/Ombi.Api.Models.csproj | 1 + Ombi.Api/MovieBase.cs | 4 +- Ombi.Api/TheMovieDbApi.cs | 30 ++++- Ombi.UI/Models/SearchMovieViewModel.cs | 3 + Ombi.UI/Modules/SearchModule.cs | 33 +++-- Ombi.UI/Views/Search/Index.cshtml | 155 +++++++++++++++++++++- 7 files changed, 316 insertions(+), 14 deletions(-) create mode 100644 Ombi.Api.Models/Movie/TmdbMovieDetails.cs diff --git a/Ombi.Api.Models/Movie/TmdbMovieDetails.cs b/Ombi.Api.Models/Movie/TmdbMovieDetails.cs new file mode 100644 index 000000000..4d987ac02 --- /dev/null +++ b/Ombi.Api.Models/Movie/TmdbMovieDetails.cs @@ -0,0 +1,104 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: TmdbMovieDetails.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion + +using System.Collections.Generic; + +namespace Ombi.Api.Models.Movie +{ + + public class Genre + { + public int id { get; set; } + public string name { get; set; } + } + + public class ProductionCompany + { + public string name { get; set; } + public int id { get; set; } + } + + public class ProductionCountry + { + public string iso_3166_1 { get; set; } + public string name { get; set; } + } + + public class SpokenLanguage + { + public string iso_639_1 { get; set; } + public string name { get; set; } + } + + public class Result + { + public string id { get; set; } + public string iso_639_1 { get; set; } + public string iso_3166_1 { get; set; } + public string key { get; set; } + public string name { get; set; } + public string site { get; set; } + public int size { get; set; } + public string type { get; set; } + } + + public class Videos + { + public List results { get; set; } + } + + public class TmdbMovieDetails + { + public bool adult { get; set; } + public string backdrop_path { get; set; } + public object belongs_to_collection { get; set; } + public int budget { get; set; } + public List genres { get; set; } + public string homepage { get; set; } + public int id { get; set; } + public string imdb_id { get; set; } + public string original_language { get; set; } + public string original_title { get; set; } + public string overview { get; set; } + public double popularity { get; set; } + public string poster_path { get; set; } + public List production_companies { get; set; } + public List production_countries { get; set; } + public string release_date { get; set; } + public int revenue { get; set; } + public int runtime { get; set; } + public List spoken_languages { get; set; } + public string status { get; set; } + public string tagline { get; set; } + public string title { get; set; } + public bool video { get; set; } + public double vote_average { get; set; } + public int vote_count { get; set; } + public Videos videos { get; set; } + } + +} \ No newline at end of file diff --git a/Ombi.Api.Models/Ombi.Api.Models.csproj b/Ombi.Api.Models/Ombi.Api.Models.csproj index c180f5624..39df12460 100644 --- a/Ombi.Api.Models/Ombi.Api.Models.csproj +++ b/Ombi.Api.Models/Ombi.Api.Models.csproj @@ -54,6 +54,7 @@ + diff --git a/Ombi.Api/MovieBase.cs b/Ombi.Api/MovieBase.cs index c21bfcbd2..5d4c820b7 100644 --- a/Ombi.Api/MovieBase.cs +++ b/Ombi.Api/MovieBase.cs @@ -32,6 +32,8 @@ namespace Ombi.Api public abstract class MovieBase { private static readonly string Encrypted = "0T3QNSseexLO7n7UPiJvl70Y+KKnvbeTlsusl7Kwq0hPH0BHOuFNGwksNCjkwqWedyDdI/MJeUR4wtL4bIl0Z+//uHXEaYM/4H2pjeLbH5EWdUe5TTj1AhaIR5PQweamvcienRyFD/3YPCC/+qL5mHkKXBkPumMod3Zb/4yN0Ik="; - protected string ApiKey = StringCipher.Decrypt(Encrypted, "ApiKey"); + private string _apiKey; + + protected string ApiKey => _apiKey ?? (_apiKey = StringCipher.Decrypt(Encrypted, "ApiKey")); } } diff --git a/Ombi.Api/TheMovieDbApi.cs b/Ombi.Api/TheMovieDbApi.cs index 6ccd775dd..cf9245b92 100644 --- a/Ombi.Api/TheMovieDbApi.cs +++ b/Ombi.Api/TheMovieDbApi.cs @@ -25,12 +25,17 @@ // ************************************************************************/ #endregion +using System; using System.Collections.Generic; using System.Threading.Tasks; +using NLog.Fluent; +using Ombi.Api.Models.Movie; +using RestSharp; using TMDbLib.Client; using TMDbLib.Objects.General; using TMDbLib.Objects.Movies; using TMDbLib.Objects.Search; +using Movie = TMDbLib.Objects.Movies.Movie; namespace Ombi.Api { @@ -39,9 +44,12 @@ namespace Ombi.Api public TheMovieDbApi() { Client = new TMDbClient(ApiKey); + Api = new ApiRequest(); } + private ApiRequest Api { get; } public TMDbClient Client { get; set; } + private const string BaseUrl = "https://api.themoviedb.org/3/"; public async Task> SearchMovie(string searchTerm) { var results = await Client.SearchMovie(searchTerm); @@ -56,7 +64,27 @@ namespace Ombi.Api public async Task> GetUpcomingMovies() { var movies = await Client.GetMovieList(MovieListType.Upcoming); - return movies?.Results ?? new List(); + return movies?.Results ?? new List(); + } + + public TmdbMovieDetails GetMovieInformationWithVideos(int tmdbId) + { + var request = new RestRequest { Resource = "movie/{movieId}", Method = Method.GET }; + request.AddUrlSegment("movieId", tmdbId.ToString()); + request.AddQueryParameter("api_key", ApiKey); + request.AddQueryParameter("append_to_response", "videos"); // Get the videos + + try + { + + var obj = Api.ExecuteJson(request, new Uri(BaseUrl)); + return obj; + } + catch (Exception e) + { + Log.Error(e); + return null; + } } public async Task GetMovieInformation(int tmdbId) diff --git a/Ombi.UI/Models/SearchMovieViewModel.cs b/Ombi.UI/Models/SearchMovieViewModel.cs index d0d71bfd9..445f8b3b4 100644 --- a/Ombi.UI/Models/SearchMovieViewModel.cs +++ b/Ombi.UI/Models/SearchMovieViewModel.cs @@ -47,5 +47,8 @@ namespace Ombi.UI.Models public double VoteAverage { get; set; } public int VoteCount { get; set; } public bool AlreadyInCp { get; set; } + public string Trailer { get; set; } + public string Homepage { get; set; } + public string ImdbId { get; set; } } } \ No newline at end of file diff --git a/Ombi.UI/Modules/SearchModule.cs b/Ombi.UI/Modules/SearchModule.cs index fb95ea1e0..36bc608d7 100644 --- a/Ombi.UI/Modules/SearchModule.cs +++ b/Ombi.UI/Modules/SearchModule.cs @@ -266,17 +266,6 @@ namespace Ombi.UI.Modules var counter = 0; foreach (var movie in apiMovies) { - var imdbId = string.Empty; - if (counter <= 5) // Let's only do it for the first 5 items - { - var movieInfoTask = await MovieApi.GetMovieInformation(movie.Id).ConfigureAwait(false); - - // TODO needs to be careful about this, it's adding extra time to search... - // https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2 - imdbId = movieInfoTask?.ImdbId; - counter++; - } - var viewMovie = new SearchMovieViewModel { Adult = movie.Adult, @@ -294,6 +283,28 @@ namespace Ombi.UI.Modules VoteAverage = movie.VoteAverage, VoteCount = movie.VoteCount }; + + var imdbId = string.Empty; + if (counter <= 5) // Let's only do it for the first 5 items + { + var movieInfo = MovieApi.GetMovieInformationWithVideos(movie.Id); + + // TODO needs to be careful about this, it's adding extra time to search... + // https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2 + viewMovie.ImdbId = movieInfo?.imdb_id; + viewMovie.Homepage = movieInfo?.homepage; + var videoId = movieInfo?.video ?? false + ? movieInfo?.videos?.results?.FirstOrDefault()?.key + : string.Empty; + + viewMovie.Trailer = string.IsNullOrEmpty(videoId) + ? string.Empty + : $"https://www.youtube.com/watch?v={videoId}"; + + counter++; + } + + var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies); var plexMovie = Checker.GetMovie(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString(), imdbId); diff --git a/Ombi.UI/Views/Search/Index.cshtml b/Ombi.UI/Views/Search/Index.cshtml index efb9228ad..0c5b90930 100644 --- a/Ombi.UI/Views/Search/Index.cshtml +++ b/Ombi.UI/Views/Search/Index.cshtml @@ -117,8 +117,161 @@ } - + + + + - -