mirror of
https://github.com/Radarr/Radarr
synced 2025-01-01 12:54:21 +00:00
Use MediaCoverService from Sonarr
This commit is contained in:
parent
80673b572a
commit
8e256462bf
3 changed files with 11 additions and 85 deletions
|
@ -8,7 +8,6 @@
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Core.MediaCover;
|
using NzbDrone.Core.MediaCover;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
|
||||||
using NzbDrone.Core.Movies;
|
using NzbDrone.Core.Movies;
|
||||||
using NzbDrone.Core.Movies.Events;
|
using NzbDrone.Core.Movies.Events;
|
||||||
using NzbDrone.Core.Test.Framework;
|
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);
|
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]
|
[Test]
|
||||||
public void should_convert_cover_urls_to_local()
|
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>()))
|
.Setup(v => v.FileExists(It.IsAny<string>()))
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
ExecuteAndVerifyCommand(_movie);
|
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||||
|
|
||||||
Mocker.GetMock<IImageResizer>()
|
Mocker.GetMock<IImageResizer>()
|
||||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
.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>()))
|
.Setup(v => v.FileExists(It.IsAny<string>()))
|
||||||
.Returns(false);
|
.Returns(false);
|
||||||
|
|
||||||
ExecuteAndVerifyCommand(_movie);
|
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||||
|
|
||||||
Mocker.GetMock<IImageResizer>()
|
Mocker.GetMock<IImageResizer>()
|
||||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
.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>()))
|
.Setup(v => v.GetFileSize(It.IsAny<string>()))
|
||||||
.Returns(1000);
|
.Returns(1000);
|
||||||
|
|
||||||
ExecuteAndVerifyCommand(_movie);
|
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||||
|
|
||||||
Mocker.GetMock<IImageResizer>()
|
Mocker.GetMock<IImageResizer>()
|
||||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never());
|
.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>()))
|
.Setup(v => v.GetFileSize(It.IsAny<string>()))
|
||||||
.Returns(0);
|
.Returns(0);
|
||||||
|
|
||||||
ExecuteAndVerifyCommand(_movie);
|
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||||
|
|
||||||
Mocker.GetMock<IImageResizer>()
|
Mocker.GetMock<IImageResizer>()
|
||||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
.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>()))
|
.Setup(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()))
|
||||||
.Throws<ApplicationException>();
|
.Throws<ApplicationException>();
|
||||||
|
|
||||||
ExecuteAndVerifyCommand(_movie);
|
Subject.HandleAsync(new MovieUpdatedEvent(_movie));
|
||||||
|
|
||||||
Mocker.GetMock<IImageResizer>()
|
Mocker.GetMock<IImageResizer>()
|
||||||
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
|
.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.Extensions;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Movies;
|
using NzbDrone.Core.Movies;
|
||||||
using NzbDrone.Core.Movies.Events;
|
using NzbDrone.Core.Movies.Events;
|
||||||
|
@ -24,10 +23,7 @@ public interface IMapCoversToLocal
|
||||||
|
|
||||||
public class MediaCoverService :
|
public class MediaCoverService :
|
||||||
IHandleAsync<MovieUpdatedEvent>,
|
IHandleAsync<MovieUpdatedEvent>,
|
||||||
|
|
||||||
//IHandleAsync<MovieAddedEvent>,
|
|
||||||
IHandleAsync<MovieDeletedEvent>,
|
IHandleAsync<MovieDeletedEvent>,
|
||||||
IExecute<EnsureMediaCoversCommand>,
|
|
||||||
IMapCoversToLocal
|
IMapCoversToLocal
|
||||||
{
|
{
|
||||||
private readonly IImageResizer _resizer;
|
private readonly IImageResizer _resizer;
|
||||||
|
@ -36,8 +32,6 @@ public class MediaCoverService :
|
||||||
private readonly ICoverExistsSpecification _coverExistsSpecification;
|
private readonly ICoverExistsSpecification _coverExistsSpecification;
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly IManageCommandQueue _commandQueue;
|
|
||||||
private readonly IMovieService _movieService;
|
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
private readonly string _coverRootFolder;
|
private readonly string _coverRootFolder;
|
||||||
|
@ -53,8 +47,6 @@ public MediaCoverService(IImageResizer resizer,
|
||||||
ICoverExistsSpecification coverExistsSpecification,
|
ICoverExistsSpecification coverExistsSpecification,
|
||||||
IConfigFileProvider configFileProvider,
|
IConfigFileProvider configFileProvider,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
IManageCommandQueue commandQueue,
|
|
||||||
IMovieService movieService,
|
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_resizer = resizer;
|
_resizer = resizer;
|
||||||
|
@ -63,8 +55,6 @@ public MediaCoverService(IImageResizer resizer,
|
||||||
_coverExistsSpecification = coverExistsSpecification;
|
_coverExistsSpecification = coverExistsSpecification;
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_commandQueue = commandQueue;
|
|
||||||
_movieService = movieService;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_coverRootFolder = appFolderInfo.GetMediaCoverPath();
|
_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";
|
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + movieId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg";
|
||||||
|
|
||||||
/*if (_diskProvider.FileExists(filePath))
|
if (_diskProvider.FileExists(filePath))
|
||||||
{
|
{
|
||||||
var lastWrite = _diskProvider.FileGetLastWrite(filePath);
|
var lastWrite = _diskProvider.FileGetLastWrite(filePath);
|
||||||
mediaCover.Url += "?lastWrite=" + lastWrite.Ticks;
|
mediaCover.Url += "?lastWrite=" + lastWrite.Ticks;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +88,7 @@ private string GetMovieCoverPath(int movieId)
|
||||||
return Path.Combine(_coverRootFolder, movieId.ToString());
|
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>>();
|
var toResize = new List<Tuple<MediaCover, bool>>();
|
||||||
|
|
||||||
|
@ -116,25 +106,7 @@ private void EnsureCovers(Movie movie, int retried = 0)
|
||||||
}
|
}
|
||||||
catch (WebException e)
|
catch (WebException e)
|
||||||
{
|
{
|
||||||
if (e.Status == WebExceptionStatus.ProtocolError)
|
_logger.Warn("Couldn't download media cover for {0}. {1}", movie, e.Message);
|
||||||
{
|
|
||||||
_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 :(.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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)
|
public void HandleAsync(MovieUpdatedEvent message)
|
||||||
{
|
{
|
||||||
//EnsureCovers(message.Movie);
|
EnsureCovers(message.Movie);
|
||||||
_logger.Info("Testing: {0}, {1}", _commandQueue, message.Movie.Id);
|
_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie));
|
||||||
_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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleAsync(MovieDeletedEvent message)
|
public void HandleAsync(MovieDeletedEvent message)
|
||||||
|
|
Loading…
Reference in a new issue