Add media proxy for collections, credits and discovery images

pull/9156/head
Bogdan 1 year ago
parent 9db0058114
commit 07cfbb59da

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

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

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

Loading…
Cancel
Save