mirror of https://github.com/Radarr/Radarr
move tmdb/imdb link parsing logic to MovieLookupController.cs
This commit is contained in:
parent
467ff799fc
commit
12f8312eec
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cloud;
|
||||
|
@ -34,11 +33,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
private readonly IMovieMetadataService _movieMetadataService;
|
||||
private readonly IMovieTranslationService _movieTranslationService;
|
||||
|
||||
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 SkyHookProxy(IHttpClient httpClient,
|
||||
IRadarrCloudRequestBuilder requestBuilder,
|
||||
IConfigService configService,
|
||||
|
@ -407,31 +401,12 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public List<Movie> SearchForNewMovie(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerTitle = title.ToLower();
|
||||
|
||||
lowerTitle = ConvertDbLinkToId(lowerTitle);
|
||||
|
||||
lowerTitle = lowerTitle.Replace(".", "");
|
||||
|
||||
var parserTitle = lowerTitle;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Languages;
|
||||
|
@ -23,6 +24,11 @@ namespace Radarr.Api.V3.Movies
|
|||
private readonly IMapCoversToLocal _coverMapper;
|
||||
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,
|
||||
IProvideMovieInfo movieInfo,
|
||||
IBuildFileNames fileNameBuilder,
|
||||
|
@ -66,11 +72,29 @@ namespace Radarr.Api.V3.Movies
|
|||
[HttpGet]
|
||||
public object Search([FromQuery] string term)
|
||||
{
|
||||
var searchResults = _searchProxy.SearchForNewMovie(term);
|
||||
var convertedTerm = ConvertDbLinkToId(term);
|
||||
var searchResults = _searchProxy.SearchForNewMovie(convertedTerm);
|
||||
|
||||
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)
|
||||
{
|
||||
var movieInfoLanguage = (Language)_configService.MovieInfoLanguage;
|
||||
|
|
Loading…
Reference in New Issue