mirror of
https://github.com/Radarr/Radarr.git
synced 2024-07-03 02:36:39 +02:00
Compare commits
5 Commits
e4841a882d
...
ea1fe15ba4
Author | SHA1 | Date | |
---|---|---|---|
|
ea1fe15ba4 | ||
|
12f8312eec | ||
|
467ff799fc | ||
|
2b1838517c | ||
|
5f03093b38 |
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Languages;
|
using NzbDrone.Core.Languages;
|
||||||
|
@ -23,6 +24,11 @@ public class MovieLookupController : RestController<MovieResource>
|
||||||
private readonly IMapCoversToLocal _coverMapper;
|
private readonly IMapCoversToLocal _coverMapper;
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
|
|
||||||
|
private static readonly Regex ImdbIdRegex = new Regex(@"imdb\.com/title/(?<id>tt\d+)",
|
||||||
|
RegexOptions.Compiled);
|
||||||
|
private static readonly Regex TmdbIdRegex = new Regex(@"themoviedb\.org/movie/(?<id>\d+)",
|
||||||
|
RegexOptions.Compiled);
|
||||||
|
|
||||||
public MovieLookupController(ISearchForNewMovie searchProxy,
|
public MovieLookupController(ISearchForNewMovie searchProxy,
|
||||||
IProvideMovieInfo movieInfo,
|
IProvideMovieInfo movieInfo,
|
||||||
IBuildFileNames fileNameBuilder,
|
IBuildFileNames fileNameBuilder,
|
||||||
|
@ -71,11 +77,29 @@ public object SearchByImdbId(string imdbId)
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public object Search([FromQuery] string term)
|
public object Search([FromQuery] string term)
|
||||||
{
|
{
|
||||||
var searchResults = _searchProxy.SearchForNewMovie(term);
|
var convertedTerm = ConvertDbLinkToId(term);
|
||||||
|
var searchResults = _searchProxy.SearchForNewMovie(convertedTerm);
|
||||||
|
|
||||||
return MapToResource(searchResults);
|
return MapToResource(searchResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ConvertDbLinkToId(string title)
|
||||||
|
{
|
||||||
|
var match = ImdbIdRegex.Match(title);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
return "imdb:" + match.Groups["id"].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
match = TmdbIdRegex.Match(title);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
return "tmdb:" + match.Groups["id"].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies)
|
private IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies)
|
||||||
{
|
{
|
||||||
var movieInfoLanguage = (Language)_configService.MovieInfoLanguage;
|
var movieInfoLanguage = (Language)_configService.MovieInfoLanguage;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user