move tmdb/imdb link parsing logic to MovieLookupController.cs

This commit is contained in:
flb 2024-02-12 21:08:18 +01:00
parent 467ff799fc
commit 12f8312eec
2 changed files with 25 additions and 26 deletions

View File

@ -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;

View File

@ -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;