mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Use MediaCoverService from Sonarr
This commit is contained in:
parent
80673b572a
commit
8e256462bf
@ -8,7 +8,6 @@
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@ -33,16 +32,6 @@ public void Setup()
|
||||
Mocker.GetMock<IMovieService>().Setup(m => m.GetMovie(It.Is<int>(id => id == _movie.Id))).Returns(_movie);
|
||||
}
|
||||
|
||||
private void ExecuteAndVerifyCommand(Movie movie)
|
||||
{
|
||||
Subject.HandleAsync(new MovieUpdatedEvent(movie));
|
||||
|
||||
Mocker.GetMock<IManageCommandQueue>()
|
||||
.Verify(v => v.Push(It.Is<EnsureMediaCoversCommand>(c => c.MovieId == movie.Id), It.IsAny<CommandPriority>(), It.IsAny<CommandTrigger>()), Times.Once());
|
||||
|
||||
Subject.Execute(new EnsureMediaCoversCommand(movie.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_convert_cover_urls_to_local()
|
||||
{
|
||||
@ -86,7 +75,7 @@ public void should_resize_covers_if_main_downloaded()
|
||||
.Setup(v => v.FileExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
ExecuteAndVerifyCommand(_movie);
|
||||
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||
|
||||
Mocker.GetMock<IImageResizer>()
|
||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
||||
@ -103,7 +92,7 @@ public void should_resize_covers_if_missing()
|
||||
.Setup(v => v.FileExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
ExecuteAndVerifyCommand(_movie);
|
||||
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||
|
||||
Mocker.GetMock<IImageResizer>()
|
||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
||||
@ -124,7 +113,7 @@ public void should_not_resize_covers_if_exists()
|
||||
.Setup(v => v.GetFileSize(It.IsAny<string>()))
|
||||
.Returns(1000);
|
||||
|
||||
ExecuteAndVerifyCommand(_movie);
|
||||
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||
|
||||
Mocker.GetMock<IImageResizer>()
|
||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never());
|
||||
@ -145,7 +134,7 @@ public void should_resize_covers_if_existing_is_empty()
|
||||
.Setup(v => v.GetFileSize(It.IsAny<string>()))
|
||||
.Returns(0);
|
||||
|
||||
ExecuteAndVerifyCommand(_movie);
|
||||
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||
|
||||
Mocker.GetMock<IImageResizer>()
|
||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
||||
@ -166,7 +155,7 @@ public void should_log_error_if_resize_failed()
|
||||
.Setup(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()))
|
||||
.Throws<ApplicationException>();
|
||||
|
||||
ExecuteAndVerifyCommand(_movie);
|
||||
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||
|
||||
Mocker.GetMock<IImageResizer>()
|
||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
||||
|
@ -1,18 +0,0 @@
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.MediaCover
|
||||
{
|
||||
public class EnsureMediaCoversCommand : Command
|
||||
{
|
||||
public int MovieId { get; set; }
|
||||
|
||||
public EnsureMediaCoversCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public EnsureMediaCoversCommand(int movieId)
|
||||
{
|
||||
MovieId = movieId;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
@ -24,10 +23,7 @@ public interface IMapCoversToLocal
|
||||
|
||||
public class MediaCoverService :
|
||||
IHandleAsync<MovieUpdatedEvent>,
|
||||
|
||||
//IHandleAsync<MovieAddedEvent>,
|
||||
IHandleAsync<MovieDeletedEvent>,
|
||||
IExecute<EnsureMediaCoversCommand>,
|
||||
IMapCoversToLocal
|
||||
{
|
||||
private readonly IImageResizer _resizer;
|
||||
@ -36,8 +32,6 @@ public class MediaCoverService :
|
||||
private readonly ICoverExistsSpecification _coverExistsSpecification;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IManageCommandQueue _commandQueue;
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly string _coverRootFolder;
|
||||
@ -53,8 +47,6 @@ public MediaCoverService(IImageResizer resizer,
|
||||
ICoverExistsSpecification coverExistsSpecification,
|
||||
IConfigFileProvider configFileProvider,
|
||||
IEventAggregator eventAggregator,
|
||||
IManageCommandQueue commandQueue,
|
||||
IMovieService movieService,
|
||||
Logger logger)
|
||||
{
|
||||
_resizer = resizer;
|
||||
@ -63,8 +55,6 @@ public MediaCoverService(IImageResizer resizer,
|
||||
_coverExistsSpecification = coverExistsSpecification;
|
||||
_configFileProvider = configFileProvider;
|
||||
_eventAggregator = eventAggregator;
|
||||
_commandQueue = commandQueue;
|
||||
_movieService = movieService;
|
||||
_logger = logger;
|
||||
|
||||
_coverRootFolder = appFolderInfo.GetMediaCoverPath();
|
||||
@ -85,11 +75,11 @@ public void ConvertToLocalUrls(int movieId, IEnumerable<MediaCover> covers)
|
||||
|
||||
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + movieId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg";
|
||||
|
||||
/*if (_diskProvider.FileExists(filePath))
|
||||
if (_diskProvider.FileExists(filePath))
|
||||
{
|
||||
var lastWrite = _diskProvider.FileGetLastWrite(filePath);
|
||||
mediaCover.Url += "?lastWrite=" + lastWrite.Ticks;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +88,7 @@ private string GetMovieCoverPath(int movieId)
|
||||
return Path.Combine(_coverRootFolder, movieId.ToString());
|
||||
}
|
||||
|
||||
private void EnsureCovers(Movie movie, int retried = 0)
|
||||
private void EnsureCovers(Movie movie)
|
||||
{
|
||||
var toResize = new List<Tuple<MediaCover, bool>>();
|
||||
|
||||
@ -116,25 +106,7 @@ private void EnsureCovers(Movie movie, int retried = 0)
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
if (e.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
_logger.Warn(e, "Couldn't download media cover for {0}, likely the cover doesn't exist for this movie. {1}", movie, e.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warn(e, "Couldn't download media cover for {0}. {1}", movie, e.Message);
|
||||
if (retried < 3)
|
||||
{
|
||||
retried += 1;
|
||||
_logger.Warn("Retrying for the {0}. time in ten seconds.", retried);
|
||||
System.Threading.Thread.Sleep(10 * 1000);
|
||||
EnsureCovers(movie, retried);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warn(e, "Couldn't download media cover even after retrying five times :(.");
|
||||
}
|
||||
}
|
||||
_logger.Warn("Couldn't download media cover for {0}. {1}", movie, e.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -212,27 +184,10 @@ private void EnsureResizedCovers(Movie movie, MediaCover cover, bool forceResize
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(EnsureMediaCoversCommand command)
|
||||
{
|
||||
var movie = _movieService.GetMovie(command.MovieId);
|
||||
EnsureCovers(movie);
|
||||
_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(movie));
|
||||
}
|
||||
|
||||
public void HandleAsync(MovieUpdatedEvent message)
|
||||
{
|
||||
//EnsureCovers(message.Movie);
|
||||
_logger.Info("Testing: {0}, {1}", _commandQueue, message.Movie.Id);
|
||||
_commandQueue.Push(new EnsureMediaCoversCommand(message.Movie.Id));
|
||||
|
||||
//_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie));
|
||||
}
|
||||
|
||||
public void HandleAsync(MovieAddedEvent message)
|
||||
{
|
||||
//EnsureCovers(message.Movie);
|
||||
//_commandQueue.Push(new EnsureMediaCoversCommand(message.Movie.Id));
|
||||
//_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie));
|
||||
EnsureCovers(message.Movie);
|
||||
_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie));
|
||||
}
|
||||
|
||||
public void HandleAsync(MovieDeletedEvent message)
|
||||
|
Loading…
Reference in New Issue
Block a user