Add media proxy for collections, credits and discovery images

This commit is contained in:
Bogdan 2023-09-10 20:24:42 +03:00
parent 9db0058114
commit 07cfbb59da
3 changed files with 40 additions and 10 deletions

View File

@ -3,6 +3,7 @@ using System.Linq;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies;
@ -28,6 +29,7 @@ namespace Radarr.Api.V3.Collections
private readonly IMovieMetadataService _movieMetadataService;
private readonly IBuildFileNames _fileNameBuilder;
private readonly INamingConfigService _namingService;
private readonly IMapCoversToLocal _coverMapper;
private readonly IManageCommandQueue _commandQueueManager;
public CollectionController(IBroadcastSignalRMessage signalRBroadcaster,
@ -36,6 +38,7 @@ namespace Radarr.Api.V3.Collections
IMovieMetadataService movieMetadataService,
IBuildFileNames fileNameBuilder,
INamingConfigService namingService,
IMapCoversToLocal coverMapper,
IManageCommandQueue commandQueueManager)
: base(signalRBroadcaster)
{
@ -44,6 +47,7 @@ namespace Radarr.Api.V3.Collections
_movieMetadataService = movieMetadataService;
_fileNameBuilder = fileNameBuilder;
_namingService = namingService;
_coverMapper = coverMapper;
_commandQueueManager = commandQueueManager;
}
@ -146,6 +150,8 @@ namespace Radarr.Api.V3.Collections
var movieResource = movie.ToResource();
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig);
_coverMapper.ConvertToLocalUrls(0, movieResource.Images);
if (!existingMoviesTmdbIds.Contains(movie.TmdbId))
{
resource.MissingMovies++;
@ -169,6 +175,8 @@ namespace Radarr.Api.V3.Collections
var movieResource = movie.ToResource();
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig);
_coverMapper.ConvertToLocalUrls(0, movieResource.Images);
if (!existingMoviesTmdbIds.Contains(movie.TmdbId))
{
resource.MissingMovies++;

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Credits;
using Radarr.Http;
@ -12,11 +13,13 @@ namespace Radarr.Api.V3.Credits
{
private readonly ICreditService _creditService;
private readonly IMovieService _movieService;
private readonly IMapCoversToLocal _coverMapper;
public CreditController(ICreditService creditService, IMovieService movieService)
public CreditController(ICreditService creditService, IMovieService movieService, IMapCoversToLocal coverMapper)
{
_creditService = creditService;
_movieService = movieService;
_coverMapper = coverMapper;
}
protected override CreditResource GetResourceById(int id)
@ -25,20 +28,32 @@ namespace Radarr.Api.V3.Credits
}
[HttpGet]
public List<CreditResource> GetCredits(int? movieId, int? movieMetadataId)
public object GetCredits(int? movieId, int? movieMetadataId)
{
if (movieMetadataId.HasValue)
{
return _creditService.GetAllCreditsForMovieMetadata(movieMetadataId.Value).ToResource();
return MapToResource(_creditService.GetAllCreditsForMovieMetadata(movieMetadataId.Value));
}
if (movieId.HasValue)
{
var movie = _movieService.GetMovie(movieId.Value);
return _creditService.GetAllCreditsForMovieMetadata(movie.MovieMetadataId).ToResource();
return MapToResource(_creditService.GetAllCreditsForMovieMetadata(movie.MovieMetadataId));
}
return _creditService.GetAllCredits().ToResource();
return MapToResource(_creditService.GetAllCredits());
}
private IEnumerable<CreditResource> MapToResource(IEnumerable<Credit> credits)
{
foreach (var currentCredits in credits)
{
var resource = currentCredits.ToResource();
_coverMapper.ConvertToLocalUrls(0, resource.Images);
yield return resource;
}
}
}
}

View File

@ -28,6 +28,7 @@ namespace Radarr.Api.V3.ImportLists
private readonly IImportExclusionsService _importExclusionService;
private readonly INamingConfigService _namingService;
private readonly IMovieTranslationService _movieTranslationService;
private readonly IMapCoversToLocal _coverMapper;
private readonly IConfigService _configService;
public ImportListMoviesController(IMovieService movieService,
@ -39,6 +40,7 @@ namespace Radarr.Api.V3.ImportLists
IImportExclusionsService importExclusionsService,
INamingConfigService namingService,
IMovieTranslationService movieTranslationService,
IMapCoversToLocal coverMapper,
IConfigService configService)
{
_movieService = movieService;
@ -50,13 +52,14 @@ namespace Radarr.Api.V3.ImportLists
_importExclusionService = importExclusionsService;
_namingService = namingService;
_movieTranslationService = movieTranslationService;
_coverMapper = coverMapper;
_configService = configService;
}
[HttpGet]
public object GetDiscoverMovies(bool includeRecommendations = false)
{
var movieLanguge = (Language)_configService.MovieInfoLanguage;
var movieLanguage = (Language)_configService.MovieInfoLanguage;
var realResults = new List<ImportListMoviesResource>();
var listExclusions = _importExclusionService.GetAllExclusions();
@ -73,11 +76,11 @@ namespace Radarr.Api.V3.ImportLists
mapped = _movieInfo.GetBulkMovieInfo(results).Select(m => new Movie { MovieMetadata = m }).ToList();
}
realResults.AddRange(MapToResource(mapped.Where(x => x != null), movieLanguge));
realResults.AddRange(MapToResource(mapped.Where(x => x != null), movieLanguage));
realResults.ForEach(x => x.IsRecommendation = true);
}
var listMovies = MapToResource(_listMovieService.GetAllForLists(_importListFactory.Enabled().Select(x => x.Definition.Id).ToList()), movieLanguge).ToList();
var listMovies = MapToResource(_listMovieService.GetAllForLists(_importListFactory.Enabled().Select(x => x.Definition.Id).ToList()), movieLanguage).ToList();
realResults.AddRange(listMovies);
@ -114,7 +117,9 @@ namespace Radarr.Api.V3.ImportLists
foreach (var currentMovie in movies)
{
var resource = DiscoverMoviesResourceMapper.ToResource(currentMovie);
var resource = currentMovie.ToResource();
_coverMapper.ConvertToLocalUrls(0, resource.Images);
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
if (poster != null)
{
@ -142,7 +147,9 @@ namespace Radarr.Api.V3.ImportLists
foreach (var currentMovie in movies)
{
var resource = DiscoverMoviesResourceMapper.ToResource(currentMovie);
var resource = currentMovie.ToResource();
_coverMapper.ConvertToLocalUrls(0, resource.Images);
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
if (poster != null)
{