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 all 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);
}
}
24 changes: 23 additions & 1 deletion 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 Down Expand Up @@ -67,10 +69,30 @@ public object SearchByImdbId(string imdbId)
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 searchResults;
}

private IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies)
{
var movieInfoLanguage = (Language)_configService.MovieInfoLanguage;
Expand Down