1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-22 07:52:34 +00:00

Revert cover mapping for collections

This commit is contained in:
Qstick 2023-10-07 14:46:07 -05:00
parent 39d7320a75
commit 04b15f2178

View file

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NLog; using NLog;
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;
@ -32,7 +29,6 @@ public class CollectionController : RestControllerWithSignalR<CollectionResource
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;
private readonly Logger _logger; private readonly Logger _logger;
@ -42,7 +38,6 @@ public CollectionController(IBroadcastSignalRMessage signalRBroadcaster,
IMovieMetadataService movieMetadataService, IMovieMetadataService movieMetadataService,
IBuildFileNames fileNameBuilder, IBuildFileNames fileNameBuilder,
INamingConfigService namingService, INamingConfigService namingService,
IMapCoversToLocal coverMapper,
IManageCommandQueue commandQueueManager, IManageCommandQueue commandQueueManager,
Logger logger) Logger logger)
: base(signalRBroadcaster) : base(signalRBroadcaster)
@ -52,7 +47,6 @@ public CollectionController(IBroadcastSignalRMessage signalRBroadcaster,
_movieMetadataService = movieMetadataService; _movieMetadataService = movieMetadataService;
_fileNameBuilder = fileNameBuilder; _fileNameBuilder = fileNameBuilder;
_namingService = namingService; _namingService = namingService;
_coverMapper = coverMapper;
_commandQueueManager = commandQueueManager; _commandQueueManager = commandQueueManager;
_logger = logger; _logger = logger;
} }
@ -67,10 +61,6 @@ public List<CollectionResource> GetCollections(int? tmdbId)
{ {
var collectionResources = new List<CollectionResource>(); var collectionResources = new List<CollectionResource>();
_logger.Trace("Fetch Cover File Infos");
var coverFileInfos = _coverMapper.GetCoverFileInfos();
_logger.Trace("Finished fetching Cover File Infos");
if (tmdbId.HasValue) if (tmdbId.HasValue)
{ {
var collection = _collectionService.FindByTmdbId(tmdbId.Value); var collection = _collectionService.FindByTmdbId(tmdbId.Value);
@ -82,7 +72,7 @@ public List<CollectionResource> GetCollections(int? tmdbId)
} }
else else
{ {
collectionResources = MapToResource(_collectionService.GetAllCollections(), coverFileInfos).ToList(); collectionResources = MapToResource(_collectionService.GetAllCollections()).ToList();
} }
_logger.Trace("Returning Collections"); _logger.Trace("Returning Collections");
@ -146,15 +136,13 @@ public ActionResult UpdateCollections(CollectionUpdateResource resource)
return Accepted(updated); return Accepted(updated);
} }
private IEnumerable<CollectionResource> MapToResource(List<MovieCollection> collections, Dictionary<string, FileInfo> coverFileInfos) private IEnumerable<CollectionResource> MapToResource(List<MovieCollection> collections)
{ {
// Avoid calling for naming spec on every movie in filenamebuilder // Avoid calling for naming spec on every movie in filenamebuilder
var namingConfig = _namingService.GetConfig(); var namingConfig = _namingService.GetConfig();
var collectionMovies = _movieMetadataService.GetMoviesWithCollections(); var collectionMovies = _movieMetadataService.GetMoviesWithCollections();
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds(); var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
MapCoversToLocal(collectionMovies, coverFileInfos);
foreach (var collection in collections) foreach (var collection in collections)
{ {
var resource = collection.ToResource(); var resource = collection.ToResource();
@ -187,8 +175,6 @@ private CollectionResource MapToResource(MovieCollection collection)
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++;
@ -200,11 +186,6 @@ private CollectionResource MapToResource(MovieCollection collection)
return resource; return resource;
} }
private void MapCoversToLocal(IEnumerable<MovieMetadata> movies, Dictionary<string, FileInfo> coverFileInfos)
{
_coverMapper.ConvertToLocalUrls(movies.Select(x => Tuple.Create(0, x.Images.AsEnumerable())), coverFileInfos);
}
[NonAction] [NonAction]
public void Handle(CollectionAddedEvent message) public void Handle(CollectionAddedEvent message)
{ {