2019-09-13 12:23:01 +00:00
|
|
|
using System.Collections.Generic;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NLog;
|
2017-01-03 12:26:09 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch;
|
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2022-03-08 02:03:00 +00:00
|
|
|
using NzbDrone.Core.Movies.Collections;
|
2017-01-03 12:26:09 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
namespace NzbDrone.Core.Movies
|
2017-01-03 12:26:09 +00:00
|
|
|
{
|
|
|
|
public class MovieScannedHandler : IHandle<MovieScannedEvent>,
|
|
|
|
IHandle<MovieScanSkippedEvent>
|
|
|
|
{
|
|
|
|
private readonly IMovieService _movieService;
|
2022-03-08 02:03:00 +00:00
|
|
|
private readonly IMovieCollectionService _collectionService;
|
2017-01-03 12:26:09 +00:00
|
|
|
private readonly IManageCommandQueue _commandQueueManager;
|
|
|
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
public MovieScannedHandler(IMovieService movieService,
|
2022-03-08 02:03:00 +00:00
|
|
|
IMovieCollectionService collectionService,
|
2017-01-03 12:26:09 +00:00
|
|
|
IManageCommandQueue commandQueueManager,
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
_movieService = movieService;
|
2022-03-08 02:03:00 +00:00
|
|
|
_collectionService = collectionService;
|
2017-01-03 12:26:09 +00:00
|
|
|
_commandQueueManager = commandQueueManager;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HandleScanEvents(Movie movie)
|
|
|
|
{
|
2024-06-12 00:00:56 +00:00
|
|
|
var addOptions = movie.AddOptions;
|
|
|
|
|
|
|
|
if (addOptions == null)
|
2017-01-03 12:26:09 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Info("[{0}] was recently added, performing post-add actions", movie.Title);
|
|
|
|
|
2024-06-12 00:00:56 +00:00
|
|
|
if (addOptions.SearchForMovie)
|
2017-01-03 12:26:09 +00:00
|
|
|
{
|
2017-01-21 21:43:58 +00:00
|
|
|
_commandQueueManager.Push(new MoviesSearchCommand { MovieIds = new List<int> { movie.Id } });
|
2017-01-03 12:26:09 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 00:00:56 +00:00
|
|
|
if (addOptions.Monitor == MonitorTypes.MovieAndCollection && movie.MovieMetadata.Value.CollectionTmdbId > 0)
|
2022-03-08 02:03:00 +00:00
|
|
|
{
|
|
|
|
var collection = _collectionService.FindByTmdbId(movie.MovieMetadata.Value.CollectionTmdbId);
|
|
|
|
collection.Monitored = true;
|
|
|
|
|
|
|
|
_collectionService.UpdateCollection(collection);
|
|
|
|
}
|
|
|
|
|
2017-01-03 12:26:09 +00:00
|
|
|
movie.AddOptions = null;
|
|
|
|
_movieService.RemoveAddOptions(movie);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Handle(MovieScannedEvent message)
|
|
|
|
{
|
|
|
|
HandleScanEvents(message.Movie);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Handle(MovieScanSkippedEvent message)
|
|
|
|
{
|
|
|
|
HandleScanEvents(message.Movie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|