-
-
Notifications
You must be signed in to change notification settings - Fork 956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: if search results empty, use GetMovieByImdbId #9810
base: develop
Are you sure you want to change the base?
Changes from 3 commits
c539f9f
123d90c
a1816c6
62eac3e
eb5ff08
9d5aadf
45a42ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NzbDrone.Core.Configuration; | ||
using NzbDrone.Core.Exceptions; | ||
using NzbDrone.Core.Languages; | ||
using NzbDrone.Core.MediaCover; | ||
using NzbDrone.Core.MetadataSource; | ||
|
@@ -24,11 +26,11 @@ public class MovieLookupController : RestController<MovieResource> | |
private readonly IConfigService _configService; | ||
|
||
public MovieLookupController(ISearchForNewMovie searchProxy, | ||
IProvideMovieInfo movieInfo, | ||
IBuildFileNames fileNameBuilder, | ||
INamingConfigService namingService, | ||
IMapCoversToLocal coverMapper, | ||
IConfigService configService) | ||
IProvideMovieInfo movieInfo, | ||
IBuildFileNames fileNameBuilder, | ||
INamingConfigService namingService, | ||
IMapCoversToLocal coverMapper, | ||
IConfigService configService) | ||
{ | ||
_movieInfo = movieInfo; | ||
_searchProxy = searchProxy; | ||
|
@@ -49,7 +51,9 @@ public object SearchByTmdbId(int tmdbId) | |
{ | ||
var availDelay = _configService.AvailabilityDelay; | ||
var result = new Movie { MovieMetadata = _movieInfo.GetMovieInfo(tmdbId).Item1 }; | ||
var translation = result.MovieMetadata.Value.Translations.FirstOrDefault(t => t.Language == (Language)_configService.MovieInfoLanguage); | ||
var translation = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we reformatting? |
||
result.MovieMetadata.Value.Translations.FirstOrDefault(t => | ||
t.Language == (Language)_configService.MovieInfoLanguage); | ||
return result.ToResource(availDelay, translation); | ||
} | ||
|
||
|
@@ -59,18 +63,40 @@ public object SearchByImdbId(string imdbId) | |
var result = new Movie { MovieMetadata = _movieInfo.GetMovieByImdbId(imdbId) }; | ||
|
||
var availDelay = _configService.AvailabilityDelay; | ||
var translation = result.MovieMetadata.Value.Translations.FirstOrDefault(t => t.Language == (Language)_configService.MovieInfoLanguage); | ||
var translation = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we reformatting? |
||
result.MovieMetadata.Value.Translations.FirstOrDefault(t => | ||
t.Language == (Language)_configService.MovieInfoLanguage); | ||
return result.ToResource(availDelay, translation); | ||
} | ||
|
||
[HttpGet] | ||
public object Search([FromQuery] string term) | ||
{ | ||
var searchResults = _searchProxy.SearchForNewMovie(term); | ||
|
||
searchResults = PopulateFromImdbIfEmpty(searchResults, term); | ||
return MapToResource(searchResults); | ||
} | ||
|
||
private List<Movie> PopulateFromImdbIfEmpty(List<Movie> searchResults, string imdbid) | ||
{ | ||
var regex = new Regex(@"^tt\d{7,8}$"); | ||
if (searchResults.Count == 0 && imdbid.StartsWith("tt") && regex.IsMatch(imdbid)) | ||
{ | ||
try | ||
{ | ||
var movieLookup = _searchProxy.GetMovieByImdbId(imdbid); | ||
var movies = new List<Movie> { new Movie { MovieMetadata = movieLookup } }; | ||
return movies; | ||
} | ||
catch (MovieNotFoundException) | ||
{ | ||
return new List<Movie>(); | ||
} | ||
} | ||
|
||
return new List<Movie>(); | ||
} | ||
|
||
private IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies) | ||
{ | ||
var movieInfoLanguage = (Language)_configService.MovieInfoLanguage; | ||
|
@@ -79,12 +105,14 @@ private IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies) | |
|
||
foreach (var currentMovie in movies) | ||
{ | ||
var translation = currentMovie.MovieMetadata.Value.Translations.FirstOrDefault(t => t.Language == movieInfoLanguage); | ||
var translation = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we reformatting? |
||
currentMovie.MovieMetadata.Value.Translations.FirstOrDefault(t => t.Language == movieInfoLanguage); | ||
var resource = currentMovie.ToResource(availDelay, translation); | ||
|
||
_coverMapper.ConvertToLocalUrls(resource.Id, resource.Images); | ||
|
||
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster); | ||
var poster = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we reformatting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ups, this is unintended. I think maybe automatic from the jetbrain IDE. Apologize for these one |
||
currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster); | ||
if (poster != null) | ||
{ | ||
resource.RemotePoster = poster.RemoteUrl; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we reformatting?