Skip to content
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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/NzbDrone.Core/MetadataSource/ISearchForNewMovie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public interface ISearchForNewMovie
List<Movie> SearchForNewMovie(string title);

MovieMetadata MapMovieToTmdbMovie(MovieMetadata movie);

MovieMetadata GetMovieByImdbId(string imdbId);
}
}
48 changes: 38 additions & 10 deletions src/Radarr.Api.V3/Movies/MovieLookupController.cs
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;
Expand All @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we reformatting?

IBuildFileNames fileNameBuilder,
INamingConfigService namingService,
IMapCoversToLocal coverMapper,
IConfigService configService)
{
_movieInfo = movieInfo;
_searchProxy = searchProxy;
Expand All @@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}

Expand All @@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Expand All @@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

The 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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we reformatting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, this is unintended.
I'm gonna revert it

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;
Expand Down