From 20dbdfb344a2e0371a4625a6f572387088972eb7 Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Tue, 27 Dec 2016 18:31:38 +0100 Subject: [PATCH] Added first iteration of adding movies. Currently working: - Searching for new Movies on IMDb (very hacky) - Adding movie as a series with one season and episode (very hacky) - Rarbg.to indexer. (somewhat hacky) TODO: - Tweak release specifications so that they do not cause exceptions. - Add Movie struct so that searching for ones is not so hacky. - rework movies UI. --- .../DecisionEngine/DownloadDecisionMaker.cs | 8 +- .../Specifications/FullSeasonSpecification.cs | 2 +- .../Search/SeasonMatchSpecification.cs | 3 +- .../SingleEpisodeSearchMatchSpecification.cs | 6 +- .../Indexers/Rarbg/RarbgRequestGenerator.cs | 7 +- .../MetadataSource/SkyHook/SkyHookProxy.cs | 106 +++++++++++++++++- src/UI/Navbar/NavbarLayoutTemplate.hbs | 4 +- 7 files changed, 120 insertions(+), 16 deletions(-) diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index d86653478..5de2ae56d 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -80,7 +80,8 @@ namespace NzbDrone.Core.DecisionEngine if (remoteEpisode.Series == null) { - decision = new DownloadDecision(remoteEpisode, new Rejection("Unknown Series")); + remoteEpisode.DownloadAllowed = true; //Fuck you :) + decision = GetDecisionForReport(remoteEpisode, searchCriteria); } else if (remoteEpisode.Episodes.Empty()) { @@ -143,8 +144,9 @@ namespace NzbDrone.Core.DecisionEngine { e.Data.Add("report", remoteEpisode.Release.ToJson()); e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo.ToJson()); - _logger.Error(e, "Couldn't evaluate decision on " + remoteEpisode.Release.Title); - return new Rejection(string.Format("{0}: {1}", spec.GetType().Name, e.Message)); + _logger.Error(e, "Couldn't evaluate decision on " + remoteEpisode.Release.Title + ", with spec: " + spec.GetType().Name); + //return new Rejection(string.Format("{0}: {1}", spec.GetType().Name, e.Message));//TODO UPDATE SPECS! + //return null; } return null; diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/FullSeasonSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/FullSeasonSpecification.cs index 023b6be60..c2d86afe8 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/FullSeasonSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/FullSeasonSpecification.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications if (subject.Episodes.Any(e => !e.AirDateUtc.HasValue || e.AirDateUtc.Value.After(DateTime.UtcNow))) { _logger.Debug("Full season release {0} rejected. All episodes haven't aired yet.", subject.Release.Title); - return Decision.Reject("Full season release rejected. All episodes haven't aired yet."); + //return Decision.Reject("Full season release rejected. All episodes haven't aired yet."); } } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeasonMatchSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeasonMatchSpecification.cs index b09d888ec..56e986e19 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeasonMatchSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeasonMatchSpecification.cs @@ -28,7 +28,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber) { _logger.Debug("Season number does not match searched season number, skipping."); - return Decision.Reject("Wrong season"); + //return Decision.Reject("Wrong season"); + //Unnecessary for Movies } return Decision.Accept(); diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SingleEpisodeSearchMatchSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SingleEpisodeSearchMatchSpecification.cs index fb056734f..dfaa711ff 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SingleEpisodeSearchMatchSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SingleEpisodeSearchMatchSpecification.cs @@ -29,19 +29,19 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber) { _logger.Debug("Season number does not match searched season number, skipping."); - return Decision.Reject("Wrong season"); + //return Decision.Reject("Wrong season"); } if (!remoteEpisode.ParsedEpisodeInfo.EpisodeNumbers.Any()) { _logger.Debug("Full season result during single episode search, skipping."); - return Decision.Reject("Full season pack"); + //return Decision.Reject("Full season pack"); } if (!remoteEpisode.ParsedEpisodeInfo.EpisodeNumbers.Contains(singleEpisodeSpec.EpisodeNumber)) { _logger.Debug("Episode number does not match searched episode number, skipping."); - return Decision.Reject("Wrong episode"); + //return Decision.Reject("Wrong episode"); } return Decision.Accept(); diff --git a/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs index 3b43e0f35..798d8ec4e 100644 --- a/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs @@ -88,12 +88,13 @@ namespace NzbDrone.Core.Indexers.Rarbg if (tvdbId.HasValue) { - requestBuilder.AddQueryParam("search_tvdb", tvdbId.Value); + string imdbId = string.Format("tt{0:D7}", tvdbId); + requestBuilder.AddQueryParam("search_imdb", imdbId); } if (query.IsNotNullOrWhiteSpace()) { - requestBuilder.AddQueryParam("search_string", string.Format(query, args)); + //requestBuilder.AddQueryParam("search_string", string.Format(query, args)); } if (!Settings.RankedOnly) @@ -101,7 +102,7 @@ namespace NzbDrone.Core.Indexers.Rarbg requestBuilder.AddQueryParam("ranked", "0"); } - requestBuilder.AddQueryParam("category", "18;41"); + requestBuilder.AddQueryParam("category", "movies"); requestBuilder.AddQueryParam("limit", "100"); requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings)); requestBuilder.AddQueryParam("format", "json_extended"); diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 3c1ca6740..3aaaf41aa 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -10,6 +10,7 @@ using NzbDrone.Core.Exceptions; using NzbDrone.Core.MediaCover; using NzbDrone.Core.MetadataSource.SkyHook.Resource; using NzbDrone.Core.Tv; +using Newtonsoft.Json; namespace NzbDrone.Core.MetadataSource.SkyHook { @@ -37,7 +38,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook httpRequest.AllowAutoRedirect = true; httpRequest.SuppressHttpError = true; - var httpResponse = _httpClient.Get(httpRequest); + string imdbId = string.Format("tt{0:D7}", tvdbSeriesId); + + var imdbRequest = new HttpRequest("http://www.omdbapi.com/?i="+ imdbId + "&plot=full&r=json"); + + var httpResponse = _httpClient.Get(imdbRequest); if (httpResponse.HasHttpError) { @@ -51,8 +56,43 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } } - var episodes = httpResponse.Resource.Episodes.Select(MapEpisode); - var series = MapSeries(httpResponse.Resource); + var response = httpResponse.Content; + + dynamic json = JsonConvert.DeserializeObject(response); + + var series = new Series(); + + series.Title = json.Title; + series.TitleSlug = series.Title.ToLower().Replace(" ", "-"); + series.Overview = json.Plot; + series.CleanTitle = series.Title; + series.TvdbId = tvdbSeriesId; + string airDateStr = json.Released; + DateTime airDate = DateTime.Parse(airDateStr); + series.FirstAired = airDate; + series.Year = airDate.Year; + series.ImdbId = imdbId; + series.Images = new List(); + string url = json.Poster; + var imdbPoster = new MediaCover.MediaCover(MediaCoverTypes.Poster, url); + series.Images.Add(imdbPoster); + + var season = new Season(); + season.SeasonNumber = 1; + season.Monitored = true; + series.Seasons.Add(season); + + + var episode = new Episode(); + + episode.AirDate = airDate.ToShortTimeString(); + episode.Title = json.Title; + episode.SeasonNumber = 1; + episode.EpisodeNumber = 1; + episode.Overview = series.Overview; + episode.AirDate = airDate.ToShortDateString(); + + var episodes = new List { episode }; return new Tuple>(series, episodes.ToList()); } @@ -89,6 +129,66 @@ namespace NzbDrone.Core.MetadataSource.SkyHook .AddQueryParam("term", title.ToLower().Trim()) .Build(); + var searchTerm = lowerTitle.Replace("+", "_").Replace(" ", "_"); + + var firstChar = searchTerm.First(); + + var imdbRequest = new HttpRequest("https://v2.sg.media-imdb.com/suggests/"+firstChar+"/" + searchTerm + ".json"); + + var response = _httpClient.Get(imdbRequest); + + var imdbCallback = "imdb$" + searchTerm + "("; + + var responseCleaned = response.Content.Replace(imdbCallback, "").TrimEnd(")"); + + dynamic json = JsonConvert.DeserializeObject(responseCleaned); + + var imdbMovies = new List(); + + foreach (dynamic entry in json.d) + { + var imdbMovie = new Series(); + imdbMovie.ImdbId = entry.id; + string noTT = imdbMovie.ImdbId.Replace("tt", ""); + try + { + imdbMovie.TvdbId = (int)Double.Parse(noTT); + } + catch + { + imdbMovie.TvdbId = 0; + } + try + { + imdbMovie.SortTitle = entry.l; + imdbMovie.Title = entry.l; + string titleSlug = entry.l; + imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-"); + imdbMovie.Year = entry.y; + imdbMovie.Images = new List(); + try + { + string url = entry.i[0]; + var imdbPoster = new MediaCover.MediaCover(MediaCoverTypes.Poster, url); + imdbMovie.Images.Add(imdbPoster); + } + catch (Exception e) + { + _logger.Debug(entry); + continue; + } + + imdbMovies.Add(imdbMovie); + } + catch + { + + } + + } + + return imdbMovies; + var httpResponse = _httpClient.Get>(httpRequest); return httpResponse.Resource.SelectList(MapSeries); diff --git a/src/UI/Navbar/NavbarLayoutTemplate.hbs b/src/UI/Navbar/NavbarLayoutTemplate.hbs index 75cfc096f..c3c70d7f5 100644 --- a/src/UI/Navbar/NavbarLayoutTemplate.hbs +++ b/src/UI/Navbar/NavbarLayoutTemplate.hbs @@ -19,7 +19,7 @@ - \ No newline at end of file +