New: Download History

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/4342/head
Qstick 5 years ago
parent 72caab1b2b
commit 824d315a3b

@ -317,7 +317,7 @@ class QueueRow extends Component {
<RemoveQueueItemModal
isOpen={isRemoveQueueItemModalOpen}
sourceTitle={title}
canIgnore={!!(movie)}
canIgnore={!!movie}
onRemovePress={this.onRemoveQueueItemModalConfirmed}
onModalClose={this.onRemoveQueueItemModalClose}
/>

@ -73,11 +73,12 @@ export default function createHandleActions(handlers, defaultState, section) {
const newState = getSectionState(state, payloadSection);
const items = newState.items;
if (!newState.itemMap) {
newState.itemMap = createItemMap(items);
}
const index = payload.id in newState.itemMap ? newState.itemMap[payload.id] : -1;
// Client side collections that are created by adding items to an
// existing array may not have an itemMap, the array is probably empty,
// but on the offchance it's not create a new item map based on the
// items in the array.
const itemMap = newState.itemMap ?? createItemMap(items);
const index = payload.id in itemMap ? itemMap[payload.id] : -1;
newState.items = [...items];
@ -96,6 +97,7 @@ export default function createHandleActions(handlers, defaultState, section) {
} else if (!updateOnly) {
const newIndex = newState.items.push({ ...otherProps }) - 1;
newState.itemMap = { ...itemMap };
newState.itemMap[payload.id] = newIndex;
}
@ -152,7 +154,8 @@ export default function createHandleActions(handlers, defaultState, section) {
const serverState = _.omit(data, ['records']);
const calculatedState = {
totalPages: Math.max(Math.ceil(data.totalRecords / data.pageSize), 1),
items: data.records
items: data.records,
itemMap: createItemMap(data.records)
};
return updateSectionState(state, payloadSection, Object.assign(newState, serverState, calculatedState));

@ -187,12 +187,12 @@ export const actionHandlers = handleThunks({
const addedIds = [];
const allNewMovies = ids.reduce((acc, id) => {
const item = _.find(items, { id });
const item = items.find((i) => i.id === id);
const selectedMovie = item.selectedMovie;
// Make sure we have a selected movie and
// the same movie hasn't been added yet.
if (selectedMovie && !_.some(acc, { tmdbId: selectedMovie.tmdbId })) {
if (selectedMovie && !acc.some((a) => a.tmdbId === selectedMovie.tmdbId)) {
const newMovie = getNewMovie(_.cloneDeep(selectedMovie), item);
newMovie.path = item.path;
@ -268,7 +268,7 @@ export const reducers = createHandleActions({
[SET_IMPORT_MOVIE_VALUE]: function(state, { payload }) {
const newState = getSectionState(state, section);
const items = newState.items;
const index = _.findIndex(items, { id: payload.id });
const index = items.findIndex((item) => item.id === payload.id);
newState.items = [...items];

@ -28,7 +28,7 @@ namespace NzbDrone.Api.History
Post("/failed", x => MarkAsFailed());
}
protected HistoryResource MapToResource(Core.History.History model)
protected HistoryResource MapToResource(MovieHistory model)
{
var resource = model.ToResource();
resource.Movie = model.Movie.ToResource();
@ -44,12 +44,12 @@ namespace NzbDrone.Api.History
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
{
var movieId = Request.Query.MovieId;
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, Core.History.History>("date", SortDirection.Descending);
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, MovieHistory>("date", SortDirection.Descending);
var filter = pagingResource.Filters.FirstOrDefault();
if (filter != null && filter.Key == "eventType")
{
var filterValue = (HistoryEventType)Convert.ToInt32(filter.Value);
var filterValue = (MovieHistoryEventType)Convert.ToInt32(filter.Value);
pagingSpec.FilterExpressions.Add(v => v.EventType == filterValue);
}

@ -16,7 +16,7 @@ namespace NzbDrone.Api.History
public DateTime Date { get; set; }
public string DownloadId { get; set; }
public HistoryEventType EventType { get; set; }
public MovieHistoryEventType EventType { get; set; }
public Dictionary<string, string> Data { get; set; }
public MovieResource Movie { get; set; }
@ -24,7 +24,7 @@ namespace NzbDrone.Api.History
public static class HistoryResourceMapper
{
public static HistoryResource ToResource(this Core.History.History model)
public static HistoryResource ToResource(this MovieHistory model)
{
if (model == null)
{

@ -1,4 +1,3 @@
using NLog;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Exceptions;

@ -14,7 +14,6 @@ namespace NzbDrone.Api.Queue
{
private readonly IQueueService _queueService;
private readonly ITrackedDownloadService _trackedDownloadService;
private readonly ICompletedDownloadService _completedDownloadService;
private readonly IFailedDownloadService _failedDownloadService;
private readonly IProvideDownloadClient _downloadClientProvider;
private readonly IPendingReleaseService _pendingReleaseService;
@ -22,7 +21,6 @@ namespace NzbDrone.Api.Queue
public QueueActionModule(IQueueService queueService,
ITrackedDownloadService trackedDownloadService,
ICompletedDownloadService completedDownloadService,
IFailedDownloadService failedDownloadService,
IProvideDownloadClient downloadClientProvider,
IPendingReleaseService pendingReleaseService,
@ -30,7 +28,6 @@ namespace NzbDrone.Api.Queue
{
_queueService = queueService;
_trackedDownloadService = trackedDownloadService;
_completedDownloadService = completedDownloadService;
_failedDownloadService = failedDownloadService;
_downloadClientProvider = downloadClientProvider;
_pendingReleaseService = pendingReleaseService;

@ -3,6 +3,7 @@ using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.History;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
@ -24,7 +25,7 @@ namespace NzbDrone.Core.Test.Datastore
var quality = new QualityModel { Quality = Quality.Bluray720p, Revision = new Revision(version: 2) };
var languages = new List<Language> { Language.English };
var history = Builder<History.History>.CreateNew()
var history = Builder<MovieHistory>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.Quality = quality)
.With(c => c.Languages = languages)
@ -32,7 +33,7 @@ namespace NzbDrone.Core.Test.Datastore
Db.Insert(history);
var loadedQuality = Db.Single<History.History>().Quality;
var loadedQuality = Db.Single<MovieHistory>().Quality;
loadedQuality.Should().Be(quality);
}
@ -41,7 +42,7 @@ namespace NzbDrone.Core.Test.Datastore
{
var languages = new List<Language> { Language.English };
var history = Builder<History.History>.CreateListOfSize(2)
var history = Builder<MovieHistory>.CreateListOfSize(2)
.All().With(c => c.Id = 0)
.With(c => c.Languages = languages)
.Build().ToList();
@ -51,7 +52,7 @@ namespace NzbDrone.Core.Test.Datastore
Db.InsertMany(history);
var returnedHistory = Db.All<History.History>();
var returnedHistory = Db.All<MovieHistory>();
returnedHistory[0].Quality.Quality.Should().Be(Quality.HDTV1080p);
}

@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.History;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
public class AlreadyImportedSpecificationFixture : CoreTest<AlreadyImportedSpecification>
{
private const int FIRST_MOVIE_ID = 1;
private const string TITLE = "Movie.Title.2018.720p.HDTV.x264-Radarr";
private Movie _movie;
private QualityModel _hdtv720p;
private QualityModel _hdtv1080p;
private RemoteMovie _remoteMovie;
private List<MovieHistory> _history;
[SetUp]
public void Setup()
{
_movie = Builder<Movie>.CreateNew()
.With(m => m.Id = FIRST_MOVIE_ID)
.With(m => m.MovieFileId = 1)
.Build();
_hdtv720p = new QualityModel(Quality.HDTV720p, new Revision(version: 1));
_hdtv1080p = new QualityModel(Quality.HDTV1080p, new Revision(version: 1));
_remoteMovie = new RemoteMovie
{
Movie = _movie,
ParsedMovieInfo = new ParsedMovieInfo { Quality = _hdtv720p },
Release = Builder<ReleaseInfo>.CreateNew()
.Build()
};
_history = new List<MovieHistory>();
Mocker.GetMock<IConfigService>()
.SetupGet(s => s.EnableCompletedDownloadHandling)
.Returns(true);
Mocker.GetMock<IHistoryService>()
.Setup(s => s.GetByMovieId(It.IsAny<int>(), null))
.Returns(_history);
}
private void GivenCdhDisabled()
{
Mocker.GetMock<IConfigService>()
.SetupGet(s => s.EnableCompletedDownloadHandling)
.Returns(false);
}
private void GivenHistoryItem(string downloadId, string sourceTitle, QualityModel quality, MovieHistoryEventType eventType)
{
_history.Add(new MovieHistory
{
DownloadId = downloadId,
SourceTitle = sourceTitle,
Quality = quality,
Date = DateTime.UtcNow,
EventType = eventType
});
}
[Test]
public void should_be_accepted_if_CDH_is_disabled()
{
GivenCdhDisabled();
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_movie_does_not_have_a_file()
{
_remoteMovie.Movie.MovieFileId = 0;
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_movie_does_not_have_grabbed_event()
{
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_movie_does_not_have_imported_event()
{
GivenHistoryItem(Guid.NewGuid().ToString().ToUpper(), TITLE, _hdtv720p, MovieHistoryEventType.Grabbed);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_grabbed_and_imported_quality_is_the_same()
{
var downloadId = Guid.NewGuid().ToString().ToUpper();
GivenHistoryItem(downloadId, TITLE, _hdtv720p, MovieHistoryEventType.Grabbed);
GivenHistoryItem(downloadId, TITLE, _hdtv720p, MovieHistoryEventType.DownloadFolderImported);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_grabbed_download_id_and_release_torrent_hash_is_unknown()
{
var downloadId = Guid.NewGuid().ToString().ToUpper();
GivenHistoryItem(downloadId, TITLE, _hdtv720p, MovieHistoryEventType.Grabbed);
GivenHistoryItem(downloadId, TITLE, _hdtv1080p, MovieHistoryEventType.DownloadFolderImported);
_remoteMovie.Release = Builder<TorrentInfo>.CreateNew()
.With(t => t.DownloadProtocol = DownloadProtocol.Torrent)
.With(t => t.InfoHash = null)
.Build();
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_grabbed_download_does_not_have_an_id()
{
var downloadId = Guid.NewGuid().ToString().ToUpper();
GivenHistoryItem(null, TITLE, _hdtv720p, MovieHistoryEventType.Grabbed);
GivenHistoryItem(downloadId, TITLE, _hdtv1080p, MovieHistoryEventType.DownloadFolderImported);
_remoteMovie.Release = Builder<TorrentInfo>.CreateNew()
.With(t => t.DownloadProtocol = DownloadProtocol.Torrent)
.With(t => t.InfoHash = downloadId)
.Build();
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_rejected_if_grabbed_download_id_matches_release_torrent_hash()
{
var downloadId = Guid.NewGuid().ToString().ToUpper();
GivenHistoryItem(downloadId, TITLE, _hdtv720p, MovieHistoryEventType.Grabbed);
GivenHistoryItem(downloadId, TITLE, _hdtv1080p, MovieHistoryEventType.DownloadFolderImported);
_remoteMovie.Release = Builder<TorrentInfo>.CreateNew()
.With(t => t.DownloadProtocol = DownloadProtocol.Torrent)
.With(t => t.InfoHash = downloadId)
.Build();
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
}
[Test]
public void should_be_rejected_if_release_title_matches_grabbed_event_source_title()
{
var downloadId = Guid.NewGuid().ToString().ToUpper();
GivenHistoryItem(downloadId, TITLE, _hdtv720p, MovieHistoryEventType.Grabbed);
GivenHistoryItem(downloadId, TITLE, _hdtv1080p, MovieHistoryEventType.DownloadFolderImported);
_remoteMovie.Release = Builder<TorrentInfo>.CreateNew()
.With(t => t.DownloadProtocol = DownloadProtocol.Torrent)
.With(t => t.InfoHash = downloadId)
.Build();
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
}
}
}

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
public class BlockedIndexerSpecificationFixture : CoreTest<BlockedIndexerSpecification>
{
private RemoteMovie _remoteMovie;
[SetUp]
public void Setup()
{
_remoteMovie = new RemoteMovie
{
Release = new ReleaseInfo { IndexerId = 1 }
};
Mocker.GetMock<IIndexerStatusService>()
.Setup(v => v.GetBlockedProviders())
.Returns(new List<IndexerStatus>());
}
private void WithBlockedIndexer()
{
Mocker.GetMock<IIndexerStatusService>()
.Setup(v => v.GetBlockedProviders())
.Returns(new List<IndexerStatus> { new IndexerStatus { ProviderId = 1, DisabledTill = DateTime.UtcNow } });
}
[Test]
public void should_return_true_if_no_blocked_indexer()
{
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_return_false_if_blocked_indexer()
{
WithBlockedIndexer();
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
Subject.Type.Should().Be(RejectionType.Temporary);
}
}
}

@ -65,14 +65,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
.Returns(true);
Mocker.GetMock<ICustomFormatCalculationService>()
.Setup(x => x.ParseCustomFormat(It.IsAny<History.History>()))
.Setup(x => x.ParseCustomFormat(It.IsAny<MovieHistory>()))
.Returns(new List<CustomFormat>());
}
private void GivenMostRecentForEpisode(int episodeId, string downloadId, QualityModel quality, DateTime date, HistoryEventType eventType)
private void GivenMostRecentForEpisode(int episodeId, string downloadId, QualityModel quality, DateTime date, MovieHistoryEventType eventType)
{
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForMovie(episodeId))
.Returns(new History.History { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType });
.Returns(new MovieHistory { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType });
}
private void GivenCdhDisabled()
@ -91,14 +91,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_true_if_latest_history_item_is_null()
{
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForMovie(It.IsAny<int>())).Returns((History.History)null);
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForMovie(It.IsAny<int>())).Returns((MovieHistory)null);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
}
[Test]
public void should_return_true_if_latest_history_item_is_not_grabbed()
{
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.DownloadFailed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, MovieHistoryEventType.DownloadFailed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
}
@ -111,14 +111,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_true_if_latest_history_item_is_older_than_twelve_hours()
{
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-13), HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-13), MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_upgradable_if_only_episode_is_upgradable()
{
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
}
@ -170,10 +170,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
Mocker.GetMock<ICustomFormatCalculationService>()
.Setup(x => x.ParseCustomFormat(It.IsAny<History.History>()))
.Setup(x => x.ParseCustomFormat(It.IsAny<MovieHistory>()))
.Returns(new List<CustomFormat>());
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
}
@ -192,7 +192,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
_upgradableQuality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1));
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
}
@ -200,7 +200,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_false_if_latest_history_item_is_only_one_hour_old()
{
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
}
@ -208,7 +208,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_return_false_if_latest_history_has_a_download_id_and_cdh_is_disabled()
{
GivenCdhDisabled();
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
}
@ -227,7 +227,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1));
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
}
@ -236,7 +236,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_return_false_if_only_episode_is_not_upgradable_and_cdh_is_disabled()
{
GivenCdhDisabled();
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), MovieHistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
}
}

@ -63,14 +63,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
}
[Test]
public void should_return_true_if_episode_has_no_existing_file()
public void should_return_true_if_movie_has_no_existing_file()
{
_parseResultSingle.Movie.MovieFile = null;
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_upgradable_if_only_episode_is_upgradable()
public void should_be_upgradable_if_only_movie_is_upgradable()
{
WithFirstFileUpgradable();
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();

@ -51,7 +51,7 @@ namespace NzbDrone.Core.Test.Download
Mocker.GetMock<IHistoryService>()
.Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId))
.Returns(new History.History());
.Returns(new MovieHistory());
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetMovie("Drone.1998"))
@ -72,7 +72,7 @@ namespace NzbDrone.Core.Test.Download
_trackedDownload.DownloadItem.Title = "Droned Pilot"; // Set a badly named download
Mocker.GetMock<IHistoryService>()
.Setup(s => s.MostRecentForDownloadId(It.Is<string>(i => i == "1234")))
.Returns(new History.History() { SourceTitle = "Droned 1998" });
.Returns(new MovieHistory() { SourceTitle = "Droned 1998" });
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetMovie(It.IsAny<string>()))

@ -4,13 +4,11 @@ using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.MovieImport;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
@ -51,7 +49,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
Mocker.GetMock<IHistoryService>()
.Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId))
.Returns(new History.History());
.Returns(new MovieHistory());
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetMovie("Drone.S01E01.HDTV"))
@ -70,7 +68,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
{
Mocker.GetMock<IHistoryService>()
.Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId))
.Returns((History.History)null);
.Returns((MovieHistory)null);
}
private void GivenMovieMatch()
@ -86,7 +84,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
_trackedDownload.DownloadItem.Title = "Droned Pilot"; // Set a badly named download
Mocker.GetMock<IHistoryService>()
.Setup(s => s.MostRecentForDownloadId(It.Is<string>(i => i == "1234")))
.Returns(new History.History() { SourceTitle = "Droned S01E01" });
.Returns(new MovieHistory() { SourceTitle = "Droned S01E01" });
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetMovie(It.IsAny<string>()))

@ -1,4 +1,4 @@
using System;
using System;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@ -58,7 +58,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
protected void VerifyIdentifiable(DownloadClientItem downloadClientItem)
{
downloadClientItem.DownloadClient.Should().Be(Subject.Definition.Name);
downloadClientItem.DownloadClientInfo.Protocol.Should().Be(Subject.Protocol);
downloadClientItem.DownloadClientInfo.Id.Should().Be(Subject.Definition.Id);
downloadClientItem.DownloadClientInfo.Name.Should().Be(Subject.Definition.Name);
downloadClientItem.DownloadId.Should().NotBeNullOrEmpty();
downloadClientItem.Title.Should().NotBeNullOrEmpty();
}

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
public class ProcessFailedFixture : CoreTest<FailedDownloadService>
{
private TrackedDownload _trackedDownload;
private List<History.History> _grabHistory;
private List<MovieHistory> _grabHistory;
[SetUp]
public void Setup()
@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
.With(h => h.Title = "Drone.S01E01.HDTV")
.Build();
_grabHistory = Builder<History.History>.CreateListOfSize(2).BuildList();
_grabHistory = Builder<MovieHistory>.CreateListOfSize(2).BuildList();
var remoteMovie = new RemoteMovie
{
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
.Build();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
.Returns(_grabHistory);
}

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
public class ProcessFixture : CoreTest<FailedDownloadService>
{
private TrackedDownload _trackedDownload;
private List<History.History> _grabHistory;
private List<MovieHistory> _grabHistory;
[SetUp]
public void Setup()
@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
.With(h => h.Title = "Drone.S01E01.HDTV")
.Build();
_grabHistory = Builder<History.History>.CreateListOfSize(2).BuildList();
_grabHistory = Builder<MovieHistory>.CreateListOfSize(2).BuildList();
var remoteMovie = new RemoteMovie
{
@ -44,15 +44,15 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
.Build();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
.Returns(_grabHistory);
}
private void GivenNoGrabbedHistory()
{
Mocker.GetMock<IHistoryService>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
.Returns(new List<History.History>());
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
.Returns(new List<MovieHistory>());
}
[Test]

@ -15,7 +15,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
{
private Movie _movie;
private TrackedDownload _trackedDownload;
private List<History.History> _historyItems;
private List<MovieHistory> _historyItems;
[SetUp]
public void Setup()
@ -30,15 +30,15 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
.With(t => t.RemoteMovie = remoteMovie)
.Build();
_historyItems = new List<History.History>();
_historyItems = new List<MovieHistory>();
}
public void GivenHistoryForMovie(Movie movie, params HistoryEventType[] eventTypes)
public void GivenHistoryForMovie(Movie movie, params MovieHistoryEventType[] eventTypes)
{
foreach (var eventType in eventTypes)
{
_historyItems.Add(
Builder<History.History>.CreateNew()
Builder<MovieHistory>.CreateNew()
.With(h => h.MovieId = movie.Id)
.With(h => h.EventType = eventType)
.Build());
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
[Test]
public void should_return_false_if_single_movie_download_is_not_imported()
{
GivenHistoryForMovie(_movie, HistoryEventType.Grabbed);
GivenHistoryForMovie(_movie, MovieHistoryEventType.Grabbed);
Subject.IsImported(_trackedDownload, _historyItems)
.Should()
@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
[Test]
public void should_return_true_if_single_movie_download_is_imported()
{
GivenHistoryForMovie(_movie, HistoryEventType.DownloadFolderImported, HistoryEventType.Grabbed);
GivenHistoryForMovie(_movie, MovieHistoryEventType.DownloadFolderImported, MovieHistoryEventType.Grabbed);
Subject.IsImported(_trackedDownload, _historyItems)
.Should()

@ -25,9 +25,9 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
{
Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.Is<string>(sr => sr == "35238")))
.Returns(new List<History.History>()
.Returns(new List<MovieHistory>()
{
new History.History()
new MovieHistory()
{
DownloadId = "35238",
SourceTitle = "TV Series S01",
@ -68,6 +68,12 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
{
Title = "A Movie 1998",
DownloadId = "35238",
DownloadClientInfo = new DownloadClientItemClientInfo
{
Protocol = client.Protocol,
Id = client.Id,
Name = client.Name
}
};
var trackedDownload = Subject.TrackDownload(client, item);

@ -12,7 +12,7 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.HistoryTests
{
[TestFixture]
public class HistoryRepositoryFixture : DbTest<HistoryRepository, History.History>
public class HistoryRepositoryFixture : DbTest<HistoryRepository, MovieHistory>
{
[SetUp]
public void Setup()
@ -22,7 +22,7 @@ namespace NzbDrone.Core.Test.HistoryTests
[Test]
public void should_read_write_dictionary()
{
var history = Builder<History.History>.CreateNew()
var history = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel())
.With(c => c.Languages = new List<Language>())
.BuildNew();
@ -38,18 +38,18 @@ namespace NzbDrone.Core.Test.HistoryTests
[Test]
public void should_get_download_history()
{
var historyBluray = Builder<History.History>.CreateNew()
var historyBluray = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
.BuildNew();
var historyDvd = Builder<History.History>.CreateNew()
var historyDvd = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.DVD))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
.BuildNew();
Subject.Insert(historyBluray);
@ -63,18 +63,18 @@ namespace NzbDrone.Core.Test.HistoryTests
[Test]
public void should_get_movie_history()
{
var historyMovie1 = Builder<History.History>.CreateNew()
var historyMovie1 = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
.BuildNew();
var historyMovie2 = Builder<History.History>.CreateNew()
var historyMovie2 = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 13)
.With(c => c.EventType = HistoryEventType.Grabbed)
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
.BuildNew();
Subject.Insert(historyMovie1);
@ -88,19 +88,19 @@ namespace NzbDrone.Core.Test.HistoryTests
[Test]
public void should_sort_movie_history_by_date()
{
var historyFirst = Builder<History.History>.CreateNew()
var historyFirst = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.MovieFileRenamed)
.With(c => c.EventType = MovieHistoryEventType.MovieFileRenamed)
.With(c => c.Date = DateTime.UtcNow)
.BuildNew();
var historySecond = Builder<History.History>.CreateNew()
var historySecond = Builder<MovieHistory>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
.With(c => c.Date = DateTime.UtcNow.AddMinutes(10))
.BuildNew();
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Test.HistoryTests
var movieHistory = Subject.GetByMovieId(12, null);
movieHistory.Should().HaveCount(2);
movieHistory.First().EventType.Should().Be(HistoryEventType.Grabbed);
movieHistory.First().EventType.Should().Be(MovieHistoryEventType.Grabbed);
}
}
}

@ -4,7 +4,9 @@ using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.History;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Movies;
@ -78,10 +80,21 @@ namespace NzbDrone.Core.Test.HistoryTests
Path = @"C:\Test\Unsorted\Movie.2011.mkv"
};
Subject.Handle(new MovieImportedEvent(localMovie, movieFile, true, "sab", "abcd"));
var downloadClientItem = new DownloadClientItem
{
DownloadClientInfo = new DownloadClientItemClientInfo
{
Protocol = DownloadProtocol.Usenet,
Id = 1,
Name = "sab"
},
DownloadId = "abcd"
};
Subject.Handle(new MovieImportedEvent(localMovie, movieFile, true, downloadClientItem, "abcd"));
Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localMovie.Path))));
.Verify(v => v.Insert(It.Is<MovieHistory>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localMovie.Path))));
}
}
}

@ -2,6 +2,7 @@ using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.History;
using NzbDrone.Core.Housekeeping.Housekeepers;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Movies;
@ -11,7 +12,7 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{
[TestFixture]
public class CleanupOrphanedHistoryItemsFixture : DbTest<CleanupOrphanedHistoryItems, History.History>
public class CleanupOrphanedHistoryItemsFixture : DbTest<CleanupOrphanedHistoryItems, MovieHistory>
{
private Movie _movie;
@ -30,7 +31,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
[Test]
public void should_delete_orphaned_items()
{
var history = Builder<History.History>.CreateNew()
var history = Builder<MovieHistory>.CreateNew()
.With(h => h.Quality = new QualityModel())
.With(h => h.Languages = new List<Language>())
.BuildNew();
@ -45,7 +46,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{
GivenSeries();
var history = Builder<History.History>.CreateNew()
var history = Builder<MovieHistory>.CreateNew()
.With(h => h.Quality = new QualityModel())
.With(h => h.Languages = new List<Language>())
.With(h => h.MovieId = _movie.Id)

@ -1,8 +1,6 @@
using System.Linq;
using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers.FileList;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Test.Framework;

@ -64,7 +64,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IHistoryService>()
.Setup(x => x.FindByDownloadId(It.IsAny<string>()))
.Returns(new List<History.History>());
.Returns(new List<MovieHistory>());
_downloadClientItem = Builder<DownloadClientItem>.CreateNew()
.With(d => d.OutputPath = new OsPath(outputPath))

@ -3,7 +3,6 @@ using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality;
using NzbDrone.Core.Parser;

@ -0,0 +1,95 @@
using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles.MovieImport.Specifications;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
{
[TestFixture]
public class DifferentQualitySpecificationFixture : CoreTest<DifferentQualitySpecification>
{
private LocalMovie _localMovie;
private DownloadClientItem _downloadClientItem;
[SetUp]
public void Setup()
{
var qualityProfile = new Profile
{
Cutoff = Quality.Bluray1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(Quality.DVD, Quality.HDTV720p, Quality.Bluray1080p)
};
var fakeMovie = Builder<Movie>.CreateNew()
.With(c => c.Profile = qualityProfile)
.Build();
_localMovie = Builder<LocalMovie>.CreateNew()
.With(l => l.Quality = new QualityModel(Quality.Bluray1080p))
.With(l => l.DownloadClientMovieInfo = new ParsedMovieInfo())
.With(l => l.Movie = fakeMovie)
.Build();
_downloadClientItem = Builder<DownloadClientItem>.CreateNew()
.Build();
}
private void GivenGrabbedMovieHistory(QualityModel quality)
{
var history = Builder<MovieHistory>.CreateListOfSize(1)
.TheFirst(1)
.With(h => h.Quality = quality)
.With(h => h.EventType = MovieHistoryEventType.Grabbed)
.BuildList();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
.Returns(history);
}
[Test]
public void should_be_accepted_if_no_download_client_item()
{
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_no_grabbed_movie_history()
{
Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
.Returns(new List<MovieHistory>());
_localMovie.Movie = Builder<Movie>.CreateNew()
.With(e => e.MovieFileId = 0)
.Build();
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_quality_matches()
{
GivenGrabbedMovieHistory(_localMovie.Quality);
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeTrue();
}
[Test]
public void should_be_rejected_if_quality_does_not_match()
{
GivenGrabbedMovieHistory(new QualityModel(Quality.SDTV));
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeFalse();
}
}
}

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
.Build();
}
private void GivenHistory(List<History.History> history)
private void GivenHistory(List<MovieHistory> history)
{
Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
[Test]
public void should_be_accepted_if_no_history_for_downloadId()
{
GivenHistory(new List<History.History>());
GivenHistory(new List<MovieHistory>());
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeTrue();
}
@ -53,9 +53,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
[Test]
public void should_be_accepted_if_no_grabbed_history_for_downloadId()
{
var history = Builder<History.History>.CreateListOfSize(1)
var history = Builder<MovieHistory>.CreateListOfSize(1)
.All()
.With(h => h.EventType = HistoryEventType.Unknown)
.With(h => h.EventType = MovieHistoryEventType.Unknown)
.BuildList();
GivenHistory(history);
@ -66,9 +66,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
[Test]
public void should_be_accepted_if_grabbed_history_quality_is_unknown()
{
var history = Builder<History.History>.CreateListOfSize(1)
var history = Builder<MovieHistory>.CreateListOfSize(1)
.All()
.With(h => h.EventType = HistoryEventType.Grabbed)
.With(h => h.EventType = MovieHistoryEventType.Grabbed)
.With(h => h.Quality = new QualityModel(Quality.Unknown))
.BuildList();
@ -80,9 +80,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
[Test]
public void should_be_accepted_if_grabbed_history_quality_matches()
{
var history = Builder<History.History>.CreateListOfSize(1)
var history = Builder<MovieHistory>.CreateListOfSize(1)
.All()
.With(h => h.EventType = HistoryEventType.Grabbed)
.With(h => h.EventType = MovieHistoryEventType.Grabbed)
.With(h => h.Quality = _localMovie.Quality)
.BuildList();
@ -94,9 +94,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
[Test]
public void should_be_rejected_if_grabbed_history_quality_does_not_match()
{
var history = Builder<History.History>.CreateListOfSize(1)
var history = Builder<MovieHistory>.CreateListOfSize(1)
.All()
.With(h => h.EventType = HistoryEventType.Grabbed)
.With(h => h.EventType = MovieHistoryEventType.Grabbed)
.With(h => h.Quality = new QualityModel(Quality.HDTV720p))
.BuildList();

@ -1,76 +0,0 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.MovieImport.Specifications;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
{
[TestFixture]
public class SameFileSpecificationFixture : CoreTest<SameFileSpecification>
{
private LocalMovie _localMovie;
[SetUp]
public void Setup()
{
_localMovie = Builder<LocalMovie>.CreateNew()
.With(l => l.Size = 150.Megabytes())
.Build();
}
[Test]
public void should_be_accepted_if_no_existing_file()
{
_localMovie.Movie = Builder<Movie>.CreateNew()
.With(e => e.MovieFileId = 0)
.Build();
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_accepted_if_file_size_is_different()
{
_localMovie.Movie = Builder<Movie>.CreateNew()
.With(e => e.MovieFileId = 1)
.With(e => e.MovieFile =
new MovieFile
{
Size = _localMovie.Size + 100.Megabytes()
})
.Build();
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_reject_if_file_size_is_the_same()
{
_localMovie.Movie = Builder<Movie>.CreateNew()
.With(e => e.MovieFileId = 1)
.With(e => e.MovieFile =
new MovieFile
{
Size = _localMovie.Size
})
.Build();
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeFalse();
}
[Test]
public void should_be_accepted_if_file_cannot_be_fetched()
{
_localMovie.Movie = Builder<Movie>.CreateNew()
.With(e => e.MovieFileId = 1)
.With(e => e.MovieFile = null)
.Build();
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
}
}
}

@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests.AugmentersTests
});
}
private History.History HistoryWithData(params string[] data)
private MovieHistory HistoryWithData(params string[] data)
{
var dict = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
for (var i = 0; i < data.Length; i += 2)
@ -62,10 +62,10 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests.AugmentersTests
dict.Add(data[i], data[i + 1]);
}
return new History.History
return new MovieHistory
{
Data = dict,
EventType = HistoryEventType.Grabbed
EventType = MovieHistoryEventType.Grabbed
};
}

@ -1,6 +1,5 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.CustomFormats;

@ -1,6 +1,5 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Test.Qualities

@ -4,6 +4,7 @@ using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
@ -20,8 +21,11 @@ namespace NzbDrone.Core.Test.QueueTests
[SetUp]
public void SetUp()
{
var downloadClientInfo = Builder<DownloadClientItemClientInfo>.CreateNew().Build();
var downloadItem = Builder<NzbDrone.Core.Download.DownloadClientItem>.CreateNew()
.With(v => v.RemainingTime = TimeSpan.FromSeconds(10))
.With(v => v.DownloadClientInfo = downloadClientInfo)
.Build();
var series = Builder<Movie>.CreateNew()

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Analytics
{
get
{
var lastRecord = _historyService.Paged(new PagingSpec<History.History>() { Page = 0, PageSize = 1, SortKey = "date", SortDirection = SortDirection.Descending });
var lastRecord = _historyService.Paged(new PagingSpec<MovieHistory>() { Page = 0, PageSize = 1, SortKey = "date", SortDirection = SortDirection.Descending });
var monthAgo = DateTime.UtcNow.AddMonths(-1);
return lastRecord.Records.Any(v => v.Date > monthAgo);

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Blacklisting;
using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser;
@ -15,7 +16,7 @@ namespace NzbDrone.Core.CustomFormats
List<CustomFormat> ParseCustomFormat(ParsedMovieInfo movieInfo);
List<CustomFormat> ParseCustomFormat(MovieFile movieFile);
List<CustomFormat> ParseCustomFormat(Blacklist blacklist);
List<CustomFormat> ParseCustomFormat(History.History history);
List<CustomFormat> ParseCustomFormat(MovieHistory history);
}
public class CustomFormatCalculationService : ICustomFormatCalculationService
@ -113,7 +114,7 @@ namespace NzbDrone.Core.CustomFormats
return ParseCustomFormat(info);
}
public List<CustomFormat> ParseCustomFormat(History.History history)
public List<CustomFormat> ParseCustomFormat(MovieHistory history)
{
var movie = _movieService.GetMovie(history.MovieId);
var parsed = _parsingService.ParseMovieInfo(history.SourceTitle, null);

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(172)]
public class add_download_history : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("DownloadHistory")
.WithColumn("EventType").AsInt32().NotNullable()
.WithColumn("MovieId").AsInt32().NotNullable()
.WithColumn("DownloadId").AsString().NotNullable()
.WithColumn("SourceTitle").AsString().NotNullable()
.WithColumn("Date").AsDateTime().NotNullable()
.WithColumn("Protocol").AsInt32().Nullable()
.WithColumn("IndexerId").AsInt32().Nullable()
.WithColumn("DownloadClientId").AsInt32().Nullable()
.WithColumn("Release").AsString().Nullable()
.WithColumn("Data").AsString().Nullable();
Create.Index().OnTable("DownloadHistory").OnColumn("EventType");
Create.Index().OnTable("DownloadHistory").OnColumn("MovieId");
Create.Index().OnTable("DownloadHistory").OnColumn("DownloadId");
Execute.WithConnection(InitialImportedDownloadHistory);
}
private static readonly Dictionary<int, int> EventTypeMap = new Dictionary<int, int>()
{
{ 1, 1 }, // MovieHistoryType.Grabbed -> DownloadHistoryType.Grabbed
{ 3, 2 }, // MovieHistoryType.DownloadFolderImported -> DownloadHistoryType.DownloadImported
{ 4, 3 }, // MovieHistoryType.DownloadFailed -> DownloadHistoryType.DownloadFailed
{ 9, 4 } // MovieHistoryType.DownloadIgnored -> DownloadHistoryType.DownloadIgnored
};
private void InitialImportedDownloadHistory(IDbConnection conn, IDbTransaction tran)
{
using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = "SELECT MovieId, DownloadId, EventType, SourceTitle, Date, Data FROM History WHERE DownloadId IS NOT NULL AND EventType IN (1, 3, 4, 9) GROUP BY EventType, DownloadId";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var movieId = reader.GetInt32(0);
var downloadId = reader.GetString(1);
var eventType = reader.GetInt32(2);
var sourceTitle = reader.GetString(3);
var date = reader.GetDateTime(4);
var rawData = reader.GetString(5);
var data = Json.Deserialize<Dictionary<string, string>>(rawData);
var downloadHistoryEventType = EventTypeMap[eventType];
var protocol = data.ContainsKey("protocol") ? Convert.ToInt32(data["protocol"]) : (int?)null;
var downloadHistoryData = new Dictionary<string, string>();
if (data.ContainsKey("indexer"))
{
downloadHistoryData.Add("indexer", data["indexer"]);
}
if (data.ContainsKey("downloadClient"))
{
downloadHistoryData.Add("downloadClient", data["downloadClient"]);
}
using (var updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = @"INSERT INTO DownloadHistory (EventType, MovieId, DownloadId, SourceTitle, Date, Protocol, Data) VALUES (?, ?, ?, ?, ?, ?, ?)";
updateCmd.AddParameter(downloadHistoryEventType);
updateCmd.AddParameter(movieId);
updateCmd.AddParameter(downloadId);
updateCmd.AddParameter(sourceTitle);
updateCmd.AddParameter(date);
updateCmd.AddParameter(protocol);
updateCmd.AddParameter(downloadHistoryData.ToJson());
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

@ -10,11 +10,13 @@ using NzbDrone.Core.CustomFilters;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Datastore.Converters;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.History;
using NzbDrone.Core.Download.Pending;
using NzbDrone.Core.Extras.Metadata;
using NzbDrone.Core.Extras.Metadata.Files;
using NzbDrone.Core.Extras.Others;
using NzbDrone.Core.Extras.Subtitles;
using NzbDrone.Core.History;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Jobs;
@ -93,7 +95,7 @@ namespace NzbDrone.Core.Datastore
.Ignore(d => d.Protocol)
.Ignore(d => d.Tags);
Mapper.Entity<History.History>("History").RegisterModel();
Mapper.Entity<MovieHistory>("History").RegisterModel();
Mapper.Entity<MovieFile>("MovieFiles").RegisterModel()
.Ignore(f => f.Path);
@ -137,6 +139,8 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<DownloadClientStatus>("DownloadClientStatus").RegisterModel();
Mapper.Entity<CustomFilter>("CustomFilters").RegisterModel();
Mapper.Entity<DownloadHistory>("DownloadHistory").RegisterModel();
}
private static void RegisterMappers()

@ -49,7 +49,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
var historyForEpisode = _historyService.GetByMovieId(movie.Id, null);
var lastGrabbed = historyForEpisode.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed);
var lastGrabbed = historyForEpisode.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
if (lastGrabbed == null)
{
@ -57,7 +57,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
}
var imported = historyForEpisode.FirstOrDefault(h =>
h.EventType == HistoryEventType.DownloadFolderImported &&
h.EventType == MovieHistoryEventType.DownloadFolderImported &&
h.DownloadId == lastGrabbed.DownloadId);
if (imported == null)

@ -47,7 +47,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
_logger.Debug("Checking current status of movie [{0}] in history", subject.Movie.Id);
var mostRecent = _historyService.MostRecentForMovie(subject.Movie.Id);
if (mostRecent != null && mostRecent.EventType == HistoryEventType.Grabbed)
if (mostRecent != null && mostRecent.EventType == MovieHistoryEventType.Grabbed)
{
var customFormats = _formatService.ParseCustomFormat(mostRecent);

@ -88,7 +88,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
{
yield return new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = Definition.Name + "_" + item.DownloadId,
Category = "radarr",
Title = item.Title,

@ -60,7 +60,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
{
yield return new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = Definition.Name + "_" + item.DownloadId,
Category = "Radarr",
Title = item.Title,

@ -135,7 +135,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
item.Title = torrent.Name;
item.Category = Settings.MovieCategory;
item.DownloadClient = Definition.Name;
item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.DownloadPath));
item.OutputPath = outputPath + torrent.Name;

@ -87,7 +87,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
var item = new DownloadClientItem()
{
Category = Settings.TvCategory,
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = CreateDownloadId(torrent.Id, serialNumber),
Title = torrent.Title,
TotalSize = torrent.Size,

@ -97,7 +97,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
var item = new DownloadClientItem()
{
Category = Settings.TvCategory,
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = CreateDownloadId(nzb.Id, serialNumber),
Title = nzb.Title,
TotalSize = nzb.Size,

@ -68,7 +68,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
var item = new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = torrent.InfoHash.ToUpper(),
OutputPath = outputPath + torrent.Name,
RemainingSize = torrent.TotalSize - torrent.DownloadedBytes,

@ -68,7 +68,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
{
var queueItem = new DownloadClientItem();
queueItem.DownloadClient = Definition.Name;
queueItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
queueItem.DownloadId = vortexQueueItem.AddUUID ?? vortexQueueItem.Id.ToString();
queueItem.Category = vortexQueueItem.GroupName;
queueItem.Title = vortexQueueItem.UiTitle;

@ -75,7 +75,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
queueItem.Title = item.NzbName;
queueItem.TotalSize = totalSize;
queueItem.Category = item.Category;
queueItem.DownloadClient = Definition.Name;
queueItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
queueItem.CanMoveFiles = true;
queueItem.CanBeRemoved = true;
@ -122,7 +122,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
var historyItem = new DownloadClientItem();
var itemDir = item.FinalDir.IsNullOrWhiteSpace() ? item.DestDir : item.FinalDir;
historyItem.DownloadClient = Definition.Name;
historyItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
historyItem.DownloadId = droneParameter == null ? item.Id.ToString() : droneParameter.Value.ToString();
historyItem.Title = item.Name;
historyItem.TotalSize = MakeInt64(item.FileSizeHi, item.FileSizeLo);

@ -73,7 +73,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
var historyItem = new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = GetDownloadClientId(file),
Title = title,

@ -135,7 +135,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
Category = torrent.Category.IsNotNullOrWhiteSpace() ? torrent.Category : torrent.Label,
Title = torrent.Name,
TotalSize = torrent.Size,
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
RemainingSize = (long)(torrent.Size * (1.0 - torrent.Progress)),
RemainingTime = GetRemainingTime(torrent),
SeedRatio = torrent.Ratio,

@ -64,7 +64,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
}
var queueItem = new DownloadClientItem();
queueItem.DownloadClient = Definition.Name;
queueItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
queueItem.DownloadId = sabQueueItem.Id;
queueItem.Category = sabQueueItem.Category;
queueItem.Title = sabQueueItem.Title;
@ -119,7 +119,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
var historyItem = new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
DownloadId = sabHistoryItem.Id,
Category = sabHistoryItem.Category,
Title = sabHistoryItem.Title,

@ -72,7 +72,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
item.Category = Settings.MovieCategory;
item.Title = torrent.Name;
item.DownloadClient = Definition.Name;
item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
item.OutputPath = GetOutputPath(outputPath, torrent);
item.TotalSize = torrent.TotalSize;

@ -122,7 +122,7 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
}
var item = new DownloadClientItem();
item.DownloadClient = Definition.Name;
item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
item.Title = torrent.Name;
item.DownloadId = torrent.Hash;
item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.Path));

@ -120,7 +120,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
item.Title = torrent.Name;
item.TotalSize = torrent.Size;
item.Category = torrent.Label;
item.DownloadClient = Definition.Name;
item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
item.RemainingSize = torrent.Remaining;
item.SeedRatio = torrent.Ratio;

@ -1,9 +1,7 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles;
@ -108,7 +106,7 @@ namespace NzbDrone.Core.Download
var allMoviesImported = importResults.Where(c => c.Result == ImportResultType.Imported)
.Select(c => c.ImportDecision.LocalMovie.Movie)
.Count() >= 1;
.Any();
if (allMoviesImported)
{
@ -117,7 +115,7 @@ namespace NzbDrone.Core.Download
return;
}
// Double check if all episodes were imported by checking the history if at least one
// Double check if all movies were imported by checking the history if at least one
// file was imported. This will allow the decision engine to reject already imported
// episode files and still mark the download complete when all files are imported.
if (importResults.Any(c => c.Result == ImportResultType.Imported))
@ -126,9 +124,9 @@ namespace NzbDrone.Core.Download
.OrderByDescending(h => h.Date)
.ToList();
var allEpisodesImportedInHistory = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
var allMoviesImportedInHistory = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
if (allEpisodesImportedInHistory)
if (allMoviesImportedInHistory)
{
trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));

@ -1,13 +1,15 @@
using System;
using System;
using System.Diagnostics;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Download
{
[DebuggerDisplay("{DownloadClient}:{Title}")]
[DebuggerDisplay("{DownloadClientName}:{Title}")]
public class DownloadClientItem
{
public string DownloadClient { get; set; }
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
public string DownloadId { get; set; }
public string Category { get; set; }
public string Title { get; set; }
@ -16,16 +18,32 @@ namespace NzbDrone.Core.Download
public long RemainingSize { get; set; }
public TimeSpan? RemainingTime { get; set; }
public double? SeedRatio { get; set; }
public OsPath OutputPath { get; set; }
public string Message { get; set; }
public DownloadItemStatus Status { get; set; }
public bool IsEncrypted { get; set; }
public bool CanMoveFiles { get; set; }
public bool CanBeRemoved { get; set; }
public bool Removed { get; set; }
}
public class DownloadClientItemClientInfo
{
public DownloadProtocol Protocol { get; set; }
public string Type { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public static DownloadClientItemClientInfo FromDownloadClient<TSettings>(DownloadClientBase<TSettings> downloadClient)
where TSettings : IProviderConfig, new()
{
return new DownloadClientItemClientInfo
{
Protocol = downloadClient.Protocol,
Type = downloadClient.Name,
Id = downloadClient.Definition.Id,
Name = downloadClient.Definition.Name
};
}
}
}

@ -1,4 +1,4 @@
using System;
using System;
using NLog;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Configuration;
@ -65,7 +65,7 @@ namespace NzbDrone.Core.Download
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
try
{
_logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClient);
_logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name);
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true);
trackedDownload.DownloadItem.Removed = true;
}
@ -84,7 +84,7 @@ namespace NzbDrone.Core.Download
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
try
{
_logger.Debug("[{0}] Marking download as imported from {1}", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClient);
_logger.Debug("[{0}] Marking download as imported from {1}", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name);
downloadClient.MarkItemAsImported(trackedDownload.DownloadItem);
}
catch (NotSupportedException e)

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Download
public List<Language> Languages { get; set; }
public QualityModel Quality { get; set; }
public string SourceTitle { get; set; }
public string DownloadClient { get; set; }
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
public string DownloadId { get; set; }
public string Message { get; set; }
}

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Configuration;
@ -33,18 +32,12 @@ namespace NzbDrone.Core.Download
_logger = logger;
}
private void RemoveCompletedDownloads(List<TrackedDownload> trackedDownloads)
{
foreach (var trackedDownload in trackedDownloads.Where(c => c.DownloadItem.CanBeRemoved && c.State == TrackedDownloadState.Imported))
{
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
}
}
public void Execute(ProcessMonitoredDownloadsCommand message)
{
var enableCompletedDownloadHandling = _configService.EnableCompletedDownloadHandling;
var trackedDownloads = _trackedDownloadService.GetTrackedDownloads();
var trackedDownloads = _trackedDownloadService.GetTrackedDownloads()
.Where(t => t.IsTrackable)
.ToList();
foreach (var trackedDownload in trackedDownloads)
{
@ -66,12 +59,6 @@ namespace NzbDrone.Core.Download
}
}
if (enableCompletedDownloadHandling && _configService.RemoveCompletedDownloads)
{
// Remove tracked downloads that are now complete
RemoveCompletedDownloads(trackedDownloads);
}
_eventAggregator.PublishEvent(new DownloadsProcessedEvent());
}
}

@ -96,6 +96,8 @@ namespace NzbDrone.Core.Download
var movieGrabbedEvent = new MovieGrabbedEvent(remoteMovie);
movieGrabbedEvent.DownloadClient = downloadClient.Name;
movieGrabbedEvent.DownloadClientId = downloadClient.Definition.Id;
movieGrabbedEvent.DownloadClientName = downloadClient.Definition.Name;
if (!string.IsNullOrWhiteSpace(downloadClientId))
{

@ -18,12 +18,15 @@ namespace NzbDrone.Core.Download
public class FailedDownloadService : IFailedDownloadService
{
private readonly IHistoryService _historyService;
private readonly ITrackedDownloadService _trackedDownloadService;
private readonly IEventAggregator _eventAggregator;
public FailedDownloadService(IHistoryService historyService,
ITrackedDownloadService trackedDownloadService,
IEventAggregator eventAggregator)
{
_historyService = historyService;
_trackedDownloadService = trackedDownloadService;
_eventAggregator = eventAggregator;
}
@ -34,22 +37,24 @@ namespace NzbDrone.Core.Download
var downloadId = history.DownloadId;
if (downloadId.IsNullOrWhiteSpace())
{
PublishDownloadFailedEvent(new List<History.History> { history }, "Manually marked as failed");
PublishDownloadFailedEvent(new List<MovieHistory> { history }, "Manually marked as failed");
}
else
{
var grabbedHistory = _historyService.Find(downloadId, HistoryEventType.Grabbed).ToList();
var grabbedHistory = _historyService.Find(downloadId, MovieHistoryEventType.Grabbed).ToList();
PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed");
}
}
public void MarkAsFailed(string downloadId)
{
var history = _historyService.Find(downloadId, HistoryEventType.Grabbed);
var history = _historyService.Find(downloadId, MovieHistoryEventType.Grabbed);
if (history.Any())
{
PublishDownloadFailedEvent(history, "Manually marked as failed");
var trackedDownload = _trackedDownloadService.Find(downloadId);
PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload);
}
}
@ -65,7 +70,7 @@ namespace NzbDrone.Core.Download
trackedDownload.DownloadItem.Status == DownloadItemStatus.Failed)
{
var grabbedItems = _historyService
.Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed)
.Find(trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed)
.ToList();
if (grabbedItems.Empty())
@ -86,7 +91,7 @@ namespace NzbDrone.Core.Download
}
var grabbedItems = _historyService
.Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed)
.Find(trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed)
.ToList();
if (grabbedItems.Empty())
@ -109,7 +114,7 @@ namespace NzbDrone.Core.Download
PublishDownloadFailedEvent(grabbedItems, failure, trackedDownload);
}
private void PublishDownloadFailedEvent(List<History.History> historyItems, string message, TrackedDownload trackedDownload = null)
private void PublishDownloadFailedEvent(List<MovieHistory> historyItems, string message, TrackedDownload trackedDownload = null)
{
var historyItem = historyItems.First();
@ -118,7 +123,7 @@ namespace NzbDrone.Core.Download
MovieId = historyItem.MovieId,
Quality = historyItem.Quality,
SourceTitle = historyItem.SourceTitle,
DownloadClient = historyItem.Data.GetValueOrDefault(History.History.DOWNLOAD_CLIENT),
DownloadClient = historyItem.Data.GetValueOrDefault(MovieHistory.DOWNLOAD_CLIENT),
DownloadId = historyItem.DownloadId,
Message = message,
Data = historyItem.Data,

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download.History
{
public class DownloadHistory : ModelBase
{
public DownloadHistoryEventType EventType { get; set; }
public int MovieId { get; set; }
public string DownloadId { get; set; }
public string SourceTitle { get; set; }
public DateTime Date { get; set; }
public DownloadProtocol Protocol { get; set; }
public int IndexerId { get; set; }
public int DownloadClientId { get; set; }
public ReleaseInfo Release { get; set; }
public Dictionary<string, string> Data { get; set; }
public DownloadHistory()
{
Data = new Dictionary<string, string>();
}
}
public enum DownloadHistoryEventType
{
DownloadGrabbed = 1,
DownloadImported = 2,
DownloadFailed = 3,
DownloadIgnored = 4,
FileImported = 5
}
}

@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Download.History
{
public interface IDownloadHistoryRepository : IBasicRepository<DownloadHistory>
{
List<DownloadHistory> FindByDownloadId(string downloadId);
void DeleteByMovieId(int movieId);
}
public class DownloadHistoryRepository : BasicRepository<DownloadHistory>, IDownloadHistoryRepository
{
public DownloadHistoryRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
public List<DownloadHistory> FindByDownloadId(string downloadId)
{
return Query(x => x.DownloadId == downloadId).OrderByDescending(h => h.Date).ToList();
}
public void DeleteByMovieId(int movieId)
{
Delete(r => r.MovieId == movieId);
}
}
}

@ -0,0 +1,210 @@
using System;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies.Events;
namespace NzbDrone.Core.Download.History
{
public interface IDownloadHistoryService
{
bool DownloadAlreadyImported(string downloadId);
DownloadHistory GetLatestDownloadHistoryItem(string downloadId);
}
public class DownloadHistoryService : IDownloadHistoryService,
IHandle<MovieGrabbedEvent>,
IHandle<MovieImportedEvent>,
IHandle<DownloadCompletedEvent>,
IHandle<DownloadFailedEvent>,
IHandle<DownloadIgnoredEvent>,
IHandle<MovieDeletedEvent>
{
private readonly IDownloadHistoryRepository _repository;
private readonly IHistoryService _historyService;
public DownloadHistoryService(IDownloadHistoryRepository repository, IHistoryService historyService)
{
_repository = repository;
_historyService = historyService;
}
public bool DownloadAlreadyImported(string downloadId)
{
var events = _repository.FindByDownloadId(downloadId);
// Events are ordered by date descending, if a grabbed event comes before an imported event then it was never imported
// or grabbed again after importing and should be reprocessed.
foreach (var e in events)
{
if (e.EventType == DownloadHistoryEventType.DownloadGrabbed)
{
return false;
}
if (e.EventType == DownloadHistoryEventType.DownloadImported)
{
return true;
}
}
return false;
}
public DownloadHistory GetLatestDownloadHistoryItem(string downloadId)
{
var events = _repository.FindByDownloadId(downloadId);
// Events are ordered by date descending. We'll return the most recent expected event.
foreach (var e in events)
{
if (e.EventType == DownloadHistoryEventType.DownloadGrabbed)
{
return e;
}
if (e.EventType == DownloadHistoryEventType.DownloadImported)
{
return e;
}
if (e.EventType == DownloadHistoryEventType.DownloadFailed)
{
return e;
}
}
return null;
}
public void Handle(MovieGrabbedEvent message)
{
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.DownloadGrabbed,
MovieId = message.Movie.Movie.Id,
DownloadId = message.DownloadId,
SourceTitle = message.Movie.Release.Title,
Date = DateTime.UtcNow,
Protocol = message.Movie.Release.DownloadProtocol,
IndexerId = message.Movie.Release.IndexerId,
DownloadClientId = message.DownloadClientId,
Release = message.Movie.Release
};
history.Data.Add("Indexer", message.Movie.Release.Indexer);
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClientName", message.DownloadClientName);
history.Data.Add("CustomFormatScore", message.Movie.CustomFormatScore.ToString());
_repository.Insert(history);
}
public void Handle(MovieImportedEvent message)
{
if (!message.NewDownload)
{
return;
}
var downloadId = message.DownloadId;
// Try to find the downloadId if the user used manual import (from wanted: missing) or the
// API to import and downloadId wasn't provided.
if (downloadId.IsNullOrWhiteSpace())
{
downloadId = _historyService.FindDownloadId(message);
}
if (downloadId.IsNullOrWhiteSpace())
{
return;
}
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.FileImported,
MovieId = message.MovieInfo.Movie.Id,
DownloadId = downloadId,
SourceTitle = message.MovieInfo.Path,
Date = DateTime.UtcNow,
Protocol = message.DownloadClientInfo.Protocol,
DownloadClientId = message.DownloadClientInfo.Id
};
history.Data.Add("DownloadClient", message.DownloadClientInfo.Type);
history.Data.Add("DownloadClientName", message.DownloadClientInfo.Name);
_repository.Insert(history);
}
public void Handle(DownloadCompletedEvent message)
{
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.DownloadImported,
MovieId = message.TrackedDownload.RemoteMovie.Movie.Id,
DownloadId = message.TrackedDownload.DownloadItem.DownloadId,
SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(),
Date = DateTime.UtcNow,
Protocol = message.TrackedDownload.Protocol,
DownloadClientId = message.TrackedDownload.DownloadClient
};
history.Data.Add("DownloadClient", message.TrackedDownload.DownloadItem.DownloadClientInfo.Type);
history.Data.Add("DownloadClientName", message.TrackedDownload.DownloadItem.DownloadClientInfo.Name);
_repository.Insert(history);
}
public void Handle(DownloadFailedEvent message)
{
// Don't track failed download for an unknown download
if (message.TrackedDownload == null)
{
return;
}
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.DownloadFailed,
MovieId = message.MovieId,
DownloadId = message.DownloadId,
SourceTitle = message.SourceTitle,
Date = DateTime.UtcNow,
Protocol = message.TrackedDownload.Protocol,
DownloadClientId = message.TrackedDownload.DownloadClient
};
history.Data.Add("DownloadClient", message.TrackedDownload.DownloadItem.DownloadClientInfo.Type);
history.Data.Add("DownloadClientName", message.TrackedDownload.DownloadItem.DownloadClientInfo.Name);
_repository.Insert(history);
}
public void Handle(DownloadIgnoredEvent message)
{
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.DownloadIgnored,
MovieId = message.MovieId,
DownloadId = message.DownloadId,
SourceTitle = message.SourceTitle,
Date = DateTime.UtcNow,
Protocol = message.DownloadClientInfo.Protocol,
DownloadClientId = message.DownloadClientInfo.Id
};
history.Data.Add("DownloadClient", message.DownloadClientInfo.Type);
history.Data.Add("DownloadClientName", message.DownloadClientInfo.Name);
_repository.Insert(history);
}
public void Handle(MovieDeletedEvent message)
{
_repository.DeleteByMovieId(message.Movie.Id);
}
}
}

@ -8,7 +8,6 @@ namespace NzbDrone.Core.Download
public interface IDownloadClient : IProvider
{
DownloadProtocol Protocol { get; }
string Download(RemoteMovie remoteMovie);
IEnumerable<DownloadClientItem> GetItems();
void RemoveItem(string downloadId, bool deleteData);

@ -37,7 +37,7 @@ namespace NzbDrone.Core.Download
Languages = trackedDownload.RemoteMovie.ParsedMovieInfo.Languages,
Quality = trackedDownload.RemoteMovie.ParsedMovieInfo.Quality,
SourceTitle = trackedDownload.DownloadItem.Title,
DownloadClient = trackedDownload.DownloadItem.DownloadClient,
DownloadClientInfo = trackedDownload.DownloadItem.DownloadClientInfo,
DownloadId = trackedDownload.DownloadItem.DownloadId,
Message = "Manually ignored"
};

@ -1,4 +1,4 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download
@ -6,7 +6,9 @@ namespace NzbDrone.Core.Download
public class MovieGrabbedEvent : IEvent
{
public RemoteMovie Movie { get; private set; }
public int DownloadClientId { get; set; }
public string DownloadClient { get; set; }
public string DownloadClientName { get; set; }
public string DownloadId { get; set; }
public MovieGrabbedEvent(RemoteMovie movie)

@ -5,7 +5,6 @@ using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Messaging;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Download
{

@ -7,12 +7,12 @@ namespace NzbDrone.Core.Download.TrackedDownloads
{
public interface ITrackedDownloadAlreadyImported
{
bool IsImported(TrackedDownload trackedDownload, List<History.History> historyItems);
bool IsImported(TrackedDownload trackedDownload, List<MovieHistory> historyItems);
}
public class TrackedDownloadAlreadyImported : ITrackedDownloadAlreadyImported
{
public bool IsImported(TrackedDownload trackedDownload, List<History.History> historyItems)
public bool IsImported(TrackedDownload trackedDownload, List<MovieHistory> historyItems)
{
if (historyItems.Empty())
{
@ -28,9 +28,9 @@ namespace NzbDrone.Core.Download.TrackedDownloads
return false;
}
var allEpisodesImportedInHistory = lastHistoryItem.EventType == HistoryEventType.DownloadFolderImported;
var allMoviesImportedInHistory = lastHistoryItem.EventType == MovieHistoryEventType.DownloadFolderImported;
return allEpisodesImportedInHistory;
return allMoviesImportedInHistory;
}
}
}

@ -6,6 +6,7 @@ using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Download.History;
using NzbDrone.Core.History;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser;
@ -27,7 +28,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
private readonly IParsingService _parsingService;
private readonly IHistoryService _historyService;
private readonly IEventAggregator _eventAggregator;
private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported;
private readonly IDownloadHistoryService _downloadHistoryService;
private readonly IConfigService _config;
private readonly ICustomFormatCalculationService _formatCalculator;
private readonly Logger _logger;
@ -39,7 +40,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
IConfigService config,
ICustomFormatCalculationService formatCalculator,
IEventAggregator eventAggregator,
ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported,
IDownloadHistoryService downloadHistoryService,
Logger logger)
{
_parsingService = parsingService;
@ -48,7 +49,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
_config = config;
_formatCalculator = formatCalculator;
_eventAggregator = eventAggregator;
_trackedDownloadAlreadyImported = trackedDownloadAlreadyImported;
_downloadHistoryService = downloadHistoryService;
_logger = logger;
}
@ -107,7 +108,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
var historyItems = _historyService.FindByDownloadId(downloadItem.DownloadId)
.OrderByDescending(h => h.Date)
.ToList();
var grabbedHistoryItem = historyItems.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed);
var grabbedHistoryItem = historyItems.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
//TODO: Create release info from history and use that here, so we don't loose indexer flags!
var parsedMovieInfo = _parsingService.ParseMovieInfo(trackedDownload.DownloadItem.Title, new List<object> { grabbedHistoryItem });
@ -117,28 +118,19 @@ namespace NzbDrone.Core.Download.TrackedDownloads
trackedDownload.RemoteMovie = _parsingService.Map(parsedMovieInfo, "", null).RemoteMovie;
}
var downloadHistory = _downloadHistoryService.GetLatestDownloadHistoryItem(downloadItem.DownloadId);
if (downloadHistory != null)
{
var state = GetStateFromHistory(downloadHistory.EventType);
trackedDownload.State = state;
}
if (historyItems.Any())
{
var firstHistoryItem = historyItems.FirstOrDefault();
var state = GetStateFromHistory(firstHistoryItem.EventType);
trackedDownload.State = state;
var grabbedEvent = historyItems.FirstOrDefault(v => v.EventType == MovieHistoryEventType.Grabbed);
// TODO: Restore check to confirm all files were imported
// This will treat partially imported downloads as imported (as it was before), which means a partially imported download after a
// restart will get marked as imported without importing the restart of the files.
//if (state == TrackedDownloadState.Imported)
//{
// var allImported = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
// trackedDownload.State = allImported ? TrackedDownloadState.Imported : TrackedDownloadState.Downloading;
//}
//else
//{
// trackedDownload.State = state;
//}
var grabbedEvent = historyItems.FirstOrDefault(v => v.EventType == HistoryEventType.Grabbed);
trackedDownload.Indexer = grabbedEvent?.Data["indexer"];
if (parsedMovieInfo == null ||
@ -193,6 +185,21 @@ namespace NzbDrone.Core.Download.TrackedDownloads
}
}
private static TrackedDownloadState GetStateFromHistory(DownloadHistoryEventType eventType)
{
switch (eventType)
{
case DownloadHistoryEventType.DownloadImported:
return TrackedDownloadState.Imported;
case DownloadHistoryEventType.DownloadFailed:
return TrackedDownloadState.Failed;
case DownloadHistoryEventType.DownloadIgnored:
return TrackedDownloadState.Ignored;
default:
return TrackedDownloadState.Downloading;
}
}
private void LogItemChange(TrackedDownload trackedDownload, DownloadClientItem existingItem, DownloadClientItem downloadItem)
{
if (existingItem == null ||
@ -201,7 +208,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
existingItem.CanMoveFiles != downloadItem.CanMoveFiles)
{
_logger.Debug("Tracking '{0}:{1}': ClientState={2}{3} SonarrStage={4} Episode='{5}' OutputPath={6}.",
downloadItem.DownloadClient,
downloadItem.DownloadClientInfo.Name,
downloadItem.Title,
downloadItem.Status,
downloadItem.CanBeRemoved ? "" : downloadItem.CanMoveFiles ? " (busy)" : " (readonly)",
@ -210,20 +217,5 @@ namespace NzbDrone.Core.Download.TrackedDownloads
downloadItem.OutputPath);
}
}
private static TrackedDownloadState GetStateFromHistory(HistoryEventType eventType)
{
switch (eventType)
{
case HistoryEventType.DownloadFolderImported:
return TrackedDownloadState.Imported;
case HistoryEventType.DownloadFailed:
return TrackedDownloadState.Failed;
case HistoryEventType.DownloadIgnored:
return TrackedDownloadState.Ignored;
default:
return TrackedDownloadState.Downloading;
}
}
}
}

@ -7,11 +7,11 @@ using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.History
{
public class History : ModelBase
public class MovieHistory : ModelBase
{
public const string DOWNLOAD_CLIENT = "downloadClient";
public History()
public MovieHistory()
{
Data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
@ -21,14 +21,14 @@ namespace NzbDrone.Core.History
public QualityModel Quality { get; set; }
public DateTime Date { get; set; }
public Movie Movie { get; set; }
public HistoryEventType EventType { get; set; }
public MovieHistoryEventType EventType { get; set; }
public Dictionary<string, string> Data { get; set; }
public List<Language> Languages { get; set; }
public string DownloadId { get; set; }
}
public enum HistoryEventType
public enum MovieHistoryEventType
{
Unknown = 0,
Grabbed = 1,

@ -10,19 +10,19 @@ using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.History
{
public interface IHistoryRepository : IBasicRepository<History>
public interface IHistoryRepository : IBasicRepository<MovieHistory>
{
List<QualityModel> GetBestQualityInHistory(int movieId);
History MostRecentForDownloadId(string downloadId);
List<History> FindByDownloadId(string downloadId);
List<History> FindDownloadHistory(int movieId, QualityModel quality);
List<History> GetByMovieId(int movieId, HistoryEventType? eventType);
MovieHistory MostRecentForDownloadId(string downloadId);
List<MovieHistory> FindByDownloadId(string downloadId);
List<MovieHistory> FindDownloadHistory(int movieId, QualityModel quality);
List<MovieHistory> GetByMovieId(int movieId, MovieHistoryEventType? eventType);
void DeleteForMovie(int movieId);
History MostRecentForMovie(int movieId);
List<History> Since(DateTime date, HistoryEventType? eventType);
MovieHistory MostRecentForMovie(int movieId);
List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType);
}
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
public class HistoryRepository : BasicRepository<MovieHistory>, IHistoryRepository
{
public HistoryRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
@ -36,28 +36,28 @@ namespace NzbDrone.Core.History
return history.Select(h => h.Quality).ToList();
}
public History MostRecentForDownloadId(string downloadId)
public MovieHistory MostRecentForDownloadId(string downloadId)
{
return FindByDownloadId(downloadId)
.OrderByDescending(h => h.Date)
.FirstOrDefault();
}
public List<History> FindByDownloadId(string downloadId)
public List<MovieHistory> FindByDownloadId(string downloadId)
{
return Query(x => x.DownloadId == downloadId);
}
public List<History> FindDownloadHistory(int movieId, QualityModel quality)
public List<MovieHistory> FindDownloadHistory(int movieId, QualityModel quality)
{
var allowed = new[] { HistoryEventType.Grabbed, HistoryEventType.DownloadFailed, HistoryEventType.DownloadFolderImported };
var allowed = new[] { MovieHistoryEventType.Grabbed, MovieHistoryEventType.DownloadFailed, MovieHistoryEventType.DownloadFolderImported };
return Query(h => h.MovieId == movieId &&
h.Quality == quality &&
allowed.Contains(h.EventType));
}
public List<History> GetByMovieId(int movieId, HistoryEventType? eventType)
public List<MovieHistory> GetByMovieId(int movieId, MovieHistoryEventType? eventType)
{
var query = Query(x => x.MovieId == movieId);
@ -74,11 +74,11 @@ namespace NzbDrone.Core.History
Delete(c => c.MovieId == movieId);
}
private IEnumerable<History> SelectJoined(SqlBuilder.Template sql)
private IEnumerable<MovieHistory> SelectJoined(SqlBuilder.Template sql)
{
using (var conn = _database.OpenConnection())
{
return conn.Query<History, Movie, Profile, History>(
return conn.Query<MovieHistory, Movie, Profile, MovieHistory>(
sql.RawSql,
(hist, movie, profile) =>
{
@ -92,25 +92,25 @@ namespace NzbDrone.Core.History
}
protected override SqlBuilder PagedBuilder() => new SqlBuilder()
.Join<History, Movie>((h, m) => h.MovieId == m.Id)
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id);
protected override IEnumerable<History> PagedSelector(SqlBuilder.Template sql) => SelectJoined(sql);
protected override IEnumerable<MovieHistory> PagedSelector(SqlBuilder.Template sql) => SelectJoined(sql);
public History MostRecentForMovie(int movieId)
public MovieHistory MostRecentForMovie(int movieId)
{
return Query(x => x.MovieId == movieId)
.OrderByDescending(h => h.Date)
.FirstOrDefault();
}
public List<History> Since(DateTime date, HistoryEventType? eventType)
public List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType)
{
var builder = Builder().Where<History>(x => x.Date >= date);
var builder = Builder().Where<MovieHistory>(x => x.Date >= date);
if (eventType.HasValue)
{
builder.Where<History>(h => h.EventType == eventType);
builder.Where<MovieHistory>(h => h.EventType == eventType);
}
return Query(builder).OrderBy(h => h.Date).ToList();

@ -19,15 +19,16 @@ namespace NzbDrone.Core.History
public interface IHistoryService
{
QualityModel GetBestQualityInHistory(Profile profile, int movieId);
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
History MostRecentForMovie(int movieId);
History MostRecentForDownloadId(string downloadId);
History Get(int historyId);
List<History> Find(string downloadId, HistoryEventType eventType);
List<History> FindByDownloadId(string downloadId);
List<History> GetByMovieId(int movieId, HistoryEventType? eventType);
void UpdateMany(List<History> toUpdate);
List<History> Since(DateTime date, HistoryEventType? eventType);
PagingSpec<MovieHistory> Paged(PagingSpec<MovieHistory> pagingSpec);
MovieHistory MostRecentForMovie(int movieId);
MovieHistory MostRecentForDownloadId(string downloadId);
MovieHistory Get(int historyId);
List<MovieHistory> Find(string downloadId, MovieHistoryEventType eventType);
List<MovieHistory> FindByDownloadId(string downloadId);
List<MovieHistory> GetByMovieId(int movieId, MovieHistoryEventType? eventType);
void UpdateMany(List<MovieHistory> toUpdate);
string FindDownloadId(MovieImportedEvent trackedDownload);
List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType);
}
public class HistoryService : IHistoryService,
@ -48,37 +49,37 @@ namespace NzbDrone.Core.History
_logger = logger;
}
public PagingSpec<History> Paged(PagingSpec<History> pagingSpec)
public PagingSpec<MovieHistory> Paged(PagingSpec<MovieHistory> pagingSpec)
{
return _historyRepository.GetPaged(pagingSpec);
}
public History MostRecentForMovie(int movieId)
public MovieHistory MostRecentForMovie(int movieId)
{
return _historyRepository.MostRecentForMovie(movieId);
}
public History MostRecentForDownloadId(string downloadId)
public MovieHistory MostRecentForDownloadId(string downloadId)
{
return _historyRepository.MostRecentForDownloadId(downloadId);
}
public History Get(int historyId)
public MovieHistory Get(int historyId)
{
return _historyRepository.Get(historyId);
}
public List<History> Find(string downloadId, HistoryEventType eventType)
public List<MovieHistory> Find(string downloadId, MovieHistoryEventType eventType)
{
return _historyRepository.FindByDownloadId(downloadId).Where(c => c.EventType == eventType).ToList();
}
public List<History> FindByDownloadId(string downloadId)
public List<MovieHistory> FindByDownloadId(string downloadId)
{
return _historyRepository.FindByDownloadId(downloadId);
}
public List<History> GetByMovieId(int movieId, HistoryEventType? eventType)
public List<MovieHistory> GetByMovieId(int movieId, MovieHistoryEventType? eventType)
{
return _historyRepository.GetByMovieId(movieId, eventType);
}
@ -91,16 +92,16 @@ namespace NzbDrone.Core.History
.FirstOrDefault();
}
public void UpdateMany(List<History> toUpdate)
public void UpdateMany(List<MovieHistory> toUpdate)
{
_historyRepository.UpdateMany(toUpdate);
}
public void Handle(MovieGrabbedEvent message)
{
var history = new History
var history = new MovieHistory
{
EventType = HistoryEventType.Grabbed,
EventType = MovieHistoryEventType.Grabbed,
Date = DateTime.UtcNow,
Quality = message.Movie.ParsedMovieInfo.Quality,
Languages = message.Movie.ParsedMovieInfo.Languages,
@ -117,6 +118,7 @@ namespace NzbDrone.Core.History
history.Data.Add("AgeMinutes", message.Movie.Release.AgeMinutes.ToString());
history.Data.Add("PublishedDate", message.Movie.Release.PublishDate.ToString("s") + "Z");
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClientName", message.DownloadClientName);
history.Data.Add("Size", message.Movie.Release.Size.ToString());
history.Data.Add("DownloadUrl", message.Movie.Release.DownloadUrl);
history.Data.Add("Guid", message.Movie.Release.Guid);
@ -156,9 +158,9 @@ namespace NzbDrone.Core.History
}
var movie = message.MovieInfo.Movie;
var history = new History
var history = new MovieHistory
{
EventType = HistoryEventType.DownloadFolderImported,
EventType = MovieHistoryEventType.DownloadFolderImported,
Date = DateTime.UtcNow,
Quality = message.MovieInfo.Quality,
Languages = message.MovieInfo.Languages,
@ -171,7 +173,8 @@ namespace NzbDrone.Core.History
//history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
history.Data.Add("DroppedPath", message.MovieInfo.Path);
history.Data.Add("ImportedPath", Path.Combine(movie.Path, message.ImportedMovie.RelativePath));
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClient", message.DownloadClientInfo?.Type);
history.Data.Add("DownloadClientName", message.DownloadClientInfo?.Name);
_historyRepository.Insert(history);
}
@ -184,9 +187,9 @@ namespace NzbDrone.Core.History
return;
}
var history = new History
var history = new MovieHistory
{
EventType = HistoryEventType.MovieFileDeleted,
EventType = MovieHistoryEventType.MovieFileDeleted,
Date = DateTime.UtcNow,
Quality = message.MovieFile.Quality,
Languages = message.MovieFile.Languages,
@ -206,9 +209,9 @@ namespace NzbDrone.Core.History
var path = Path.Combine(message.Movie.Path, message.MovieFile.RelativePath);
var relativePath = message.MovieFile.RelativePath;
var history = new History
var history = new MovieHistory
{
EventType = HistoryEventType.MovieFileRenamed,
EventType = MovieHistoryEventType.MovieFileRenamed,
Date = DateTime.UtcNow,
Quality = message.MovieFile.Quality,
Languages = message.MovieFile.Languages,
@ -226,9 +229,9 @@ namespace NzbDrone.Core.History
public void Handle(DownloadIgnoredEvent message)
{
var history = new History
var history = new MovieHistory
{
EventType = HistoryEventType.DownloadIgnored,
EventType = MovieHistoryEventType.DownloadIgnored,
Date = DateTime.UtcNow,
Quality = message.Quality,
SourceTitle = message.SourceTitle,
@ -237,7 +240,8 @@ namespace NzbDrone.Core.History
Languages = message.Languages
};
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClient", message.DownloadClientInfo.Type);
history.Data.Add("DownloadClientName", message.DownloadClientInfo.Name);
history.Data.Add("Message", message.Message);
_historyRepository.Insert(history);
@ -248,19 +252,18 @@ namespace NzbDrone.Core.History
_historyRepository.DeleteForMovie(message.Movie.Id);
}
private string FindDownloadId(MovieImportedEvent trackedDownload)
public string FindDownloadId(MovieImportedEvent trackedDownload)
{
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedMovie.Path);
var movieId = trackedDownload.MovieInfo.Movie.Id;
var movieHistory = _historyRepository.FindDownloadHistory(movieId, trackedDownload.ImportedMovie.Quality);
var processedDownloadId = movieHistory
.Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null)
.Where(c => c.EventType != MovieHistoryEventType.Grabbed && c.DownloadId != null)
.Select(c => c.DownloadId);
var stillDownloading = movieHistory.Where(c => c.EventType == HistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();
var stillDownloading = movieHistory.Where(c => c.EventType == MovieHistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();
string downloadId = null;
@ -293,9 +296,9 @@ namespace NzbDrone.Core.History
public void Handle(DownloadFailedEvent message)
{
var history = new History
var history = new MovieHistory
{
EventType = HistoryEventType.DownloadFailed,
EventType = MovieHistoryEventType.DownloadFailed,
Date = DateTime.UtcNow,
Quality = message.Quality,
Languages = message.Languages,
@ -305,12 +308,13 @@ namespace NzbDrone.Core.History
};
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClientName", message.TrackedDownload?.DownloadItem.DownloadClientInfo.Name);
history.Data.Add("Message", message.Message);
_historyRepository.Insert(history);
}
public List<History> Since(DateTime date, HistoryEventType? eventType)
public List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType)
{
return _historyRepository.Since(date, eventType);
}

@ -1,4 +1,4 @@
using System;
using System;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
@ -10,7 +10,7 @@ namespace NzbDrone.Core.MediaFiles.Events
public Exception Exception { get; set; }
public LocalMovie MovieInfo { get; }
public bool NewDownload { get; }
public string DownloadClient { get; }
public DownloadClientItemClientInfo DownloadClientInfo { get; }
public string DownloadId { get; }
public MovieImportFailedEvent(Exception exception, LocalMovie movieInfo, bool newDownload, DownloadClientItem downloadClientItem)
@ -21,7 +21,7 @@ namespace NzbDrone.Core.MediaFiles.Events
if (downloadClientItem != null)
{
DownloadClient = downloadClientItem.DownloadClient;
DownloadClientInfo = downloadClientItem.DownloadClientInfo;
DownloadId = downloadClientItem.DownloadId;
}
}

@ -1,4 +1,5 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.Events
@ -8,7 +9,7 @@ namespace NzbDrone.Core.MediaFiles.Events
public LocalMovie MovieInfo { get; private set; }
public MovieFile ImportedMovie { get; private set; }
public bool NewDownload { get; private set; }
public string DownloadClient { get; private set; }
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
public string DownloadId { get; private set; }
public MovieImportedEvent(LocalMovie movieInfo, MovieFile importedMovie, bool newDownload)
@ -18,12 +19,12 @@ namespace NzbDrone.Core.MediaFiles.Events
NewDownload = newDownload;
}
public MovieImportedEvent(LocalMovie movieInfo, MovieFile importedMovie, bool newDownload, string downloadClient, string downloadId)
public MovieImportedEvent(LocalMovie movieInfo, MovieFile importedMovie, bool newDownload, DownloadClientItem downloadClientItem, string downloadId)
{
MovieInfo = movieInfo;
ImportedMovie = importedMovie;
NewDownload = newDownload;
DownloadClient = downloadClient;
DownloadClientInfo = downloadClientItem.DownloadClientInfo;
DownloadId = downloadId;
}
}

@ -93,7 +93,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
{
var grabHistory = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
.OrderByDescending(h => h.Date)
.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed);
.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
if (Enum.TryParse(grabHistory?.Data.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags))
{
@ -139,7 +139,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
if (downloadClientItem != null)
{
_eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId));
_eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload, downloadClientItem, downloadClientItem.DownloadId));
}
else
{

@ -39,8 +39,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
}
var movieImportedHistory = _historyService.GetByMovieId(movie.Id, null);
var lastImported = movieImportedHistory.FirstOrDefault(h => h.EventType == HistoryEventType.DownloadFolderImported);
var lastGrabbed = movieImportedHistory.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed);
var lastImported = movieImportedHistory.FirstOrDefault(h => h.EventType == MovieHistoryEventType.DownloadFolderImported);
var lastGrabbed = movieImportedHistory.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
if (lastImported == null)
{

@ -0,0 +1,52 @@
using System.Linq;
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.History;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
{
public class DifferentQualitySpecification : IImportDecisionEngineSpecification
{
private readonly IHistoryService _historyService;
private readonly Logger _logger;
public DifferentQualitySpecification(IHistoryService historyService, Logger logger)
{
_historyService = historyService;
_logger = logger;
}
public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{
if (downloadClientItem == null)
{
_logger.Debug("No download client item, skipping");
return Decision.Accept();
}
var grabbedMovieHistory = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
.OrderByDescending(h => h.Date)
.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
if (grabbedMovieHistory == null)
{
_logger.Debug("No grabbed history for this download item, skipping");
return Decision.Accept();
}
var qualityComparer = new QualityModelComparer(localMovie.Movie.Profile);
var qualityCompare = qualityComparer.Compare(localMovie.Quality, grabbedMovieHistory.Quality);
if (qualityCompare != 0)
{
_logger.Debug("Quality of file ({0}) does not match quality of grabbed history ({1})", localMovie.Quality, grabbedMovieHistory.Quality);
return Decision.Reject("Not an upgrade for existing movie file(s)");
}
return Decision.Accept();
}
}
}

@ -34,7 +34,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
}
var grabbedHistory = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
.Where(h => h.EventType == HistoryEventType.Grabbed)
.Where(h => h.EventType == MovieHistoryEventType.Grabbed)
.ToList();
if (grabbedHistory.Empty())

@ -1,44 +0,0 @@
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
{
public class SameFileSpecification : IImportDecisionEngineSpecification
{
private readonly Logger _logger;
public SameFileSpecification(Logger logger)
{
_logger = logger;
}
public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{
var movieFile = localMovie.Movie.MovieFile;
if (localMovie.Movie.MovieFileId == 0)
{
_logger.Debug("No existing movie file, skipping");
return Decision.Accept();
}
if (movieFile == null)
{
var movie = localMovie.Movie;
_logger.Trace("Unable to get movie file details from the DB. MovieId: {0} MovieFileId: {1}", movie.Id, movie.MovieFileId);
return Decision.Accept();
}
if (movieFile.Size == localMovie.Size)
{
_logger.Debug("'{0}' Has the same filesize as existing file", localMovie.Path);
return Decision.Reject("Has the same filesize as existing file");
}
return Decision.Accept();
}
}
}

@ -23,13 +23,13 @@ namespace NzbDrone.Core.Parser.Augmenters
{
get
{
return typeof(History.History);
return typeof(MovieHistory);
}
}
public ParsedMovieInfo AugmentMovieInfo(ParsedMovieInfo movieInfo, object helper)
{
if (helper is History.History history && history.EventType == HistoryEventType.Grabbed)
if (helper is MovieHistory history && history.EventType == MovieHistoryEventType.Grabbed)
{
//First we create a release info from history data.
var releaseInfo = new ReleaseInfo();

@ -73,7 +73,7 @@ namespace NzbDrone.Core.Queue
DownloadId = trackedDownload.DownloadItem.DownloadId,
Protocol = trackedDownload.Protocol,
Movie = movie,
DownloadClient = trackedDownload.DownloadItem.DownloadClient,
DownloadClient = trackedDownload.DownloadItem.DownloadClientInfo.Name,
Indexer = trackedDownload.Indexer,
OutputPath = trackedDownload.DownloadItem.OutputPath.ToString()
};

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;

@ -41,7 +41,7 @@ namespace Radarr.Api.V3.History
Post("/failed", x => MarkAsFailed());
}
protected HistoryResource MapToResource(NzbDrone.Core.History.History model, bool includeMovie)
protected HistoryResource MapToResource(MovieHistory model, bool includeMovie)
{
if (model.Movie == null)
{
@ -65,7 +65,7 @@ namespace Radarr.Api.V3.History
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
{
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, NzbDrone.Core.History.History>("date", SortDirection.Descending);
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, MovieHistory>("date", SortDirection.Descending);
var includeMovie = Request.GetBooleanQueryParameter("includeMovie");
var eventTypeFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "eventType");
@ -73,7 +73,7 @@ namespace Radarr.Api.V3.History
if (eventTypeFilter != null)
{
var filterValue = (HistoryEventType)Convert.ToInt32(eventTypeFilter.Value);
var filterValue = (MovieHistoryEventType)Convert.ToInt32(eventTypeFilter.Value);
pagingSpec.FilterExpressions.Add(v => v.EventType == filterValue);
}
@ -97,12 +97,12 @@ namespace Radarr.Api.V3.History
}
DateTime date = DateTime.Parse(queryDate.Value);
HistoryEventType? eventType = null;
MovieHistoryEventType? eventType = null;
var includeMovie = Request.GetBooleanQueryParameter("includeMovie");
if (queryEventType.HasValue)
{
eventType = (HistoryEventType)Convert.ToInt32(queryEventType.Value);
eventType = (MovieHistoryEventType)Convert.ToInt32(queryEventType.Value);
}
return _historyService.Since(date, eventType).Select(h => MapToResource(h, includeMovie)).ToList();
@ -119,12 +119,12 @@ namespace Radarr.Api.V3.History
}
int movieId = Convert.ToInt32(queryMovieId.Value);
HistoryEventType? eventType = null;
MovieHistoryEventType? eventType = null;
var includeMovie = Request.GetBooleanQueryParameter("includeMovie");
if (queryEventType.HasValue)
{
eventType = (HistoryEventType)Convert.ToInt32(queryEventType.Value);
eventType = (MovieHistoryEventType)Convert.ToInt32(queryEventType.Value);
}
return _historyService.GetByMovieId(movieId, eventType).Select(h => MapToResource(h, includeMovie)).ToList();

@ -21,7 +21,7 @@ namespace Radarr.Api.V3.History
public DateTime Date { get; set; }
public string DownloadId { get; set; }
public HistoryEventType EventType { get; set; }
public MovieHistoryEventType EventType { get; set; }
public Dictionary<string, string> Data { get; set; }
@ -30,7 +30,7 @@ namespace Radarr.Api.V3.History
public static class HistoryResourceMapper
{
public static HistoryResource ToResource(this NzbDrone.Core.History.History model, ICustomFormatCalculationService formatCalculator)
public static HistoryResource ToResource(this MovieHistory model, ICustomFormatCalculationService formatCalculator)
{
if (model == null)
{

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy;

@ -3,7 +3,6 @@ using System.Linq;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Profiles;
using Radarr.Api.V3.CustomFormats;
using Radarr.Http.REST;
namespace Radarr.Api.V3.Profiles.Quality

@ -149,12 +149,9 @@ namespace Radarr.Api.V3.Queue
_failedDownloadService.MarkAsFailed(trackedDownload.DownloadItem.DownloadId);
}
if (!removeFromClient && !blacklist)
if (!removeFromClient && !blacklist && !_ignoredDownloadService.IgnoreDownload(trackedDownload))
{
if (!_ignoredDownloadService.IgnoreDownload(trackedDownload))
{
return null;
}
return null;
}
return trackedDownload;

Loading…
Cancel
Save