Organize TrackImport Directory and Fix Tests (#72)

* Organize TrackImport Folder and Fix Tests

* Remove Commented Out Line

* Remove Old Code
pull/76/head
Qstick 7 years ago committed by GitHub
parent ffc2fb5f60
commit bcd72367d9

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Core.MediaFiles.EpisodeImport.Manual; using NzbDrone.Core.MediaFiles.TrackImport.Manual;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
namespace NzbDrone.Api.ManualImport namespace NzbDrone.Api.ManualImport
@ -40,4 +40,4 @@ namespace NzbDrone.Api.ManualImport
return item; return item;
} }
} }
} }

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Api.Episodes; using NzbDrone.Api.Episodes;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
@ -26,7 +26,7 @@ namespace NzbDrone.Api.ManualImport
public static class ManualImportResourceMapper public static class ManualImportResourceMapper
{ {
public static ManualImportResource ToResource(this Core.MediaFiles.EpisodeImport.Manual.ManualImportItem model) public static ManualImportResource ToResource(this Core.MediaFiles.TrackImport.Manual.ManualImportItem model)
{ {
if (model == null) return null; if (model == null) return null;
@ -48,7 +48,7 @@ namespace NzbDrone.Api.ManualImport
}; };
} }
public static List<ManualImportResource> ToResource(this IEnumerable<Core.MediaFiles.EpisodeImport.Manual.ManualImportItem> models) public static List<ManualImportResource> ToResource(this IEnumerable<Core.MediaFiles.TrackImport.Manual.ManualImportItem> models)
{ {
return models.Select(ToResource).ToList(); return models.Select(ToResource).ToList();
} }

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Nancy; using Nancy;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
@ -12,7 +12,7 @@ using Marr.Data;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
@ -149,4 +149,4 @@ namespace NzbDrone.Api.Music
} }
} }
} }
} }

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
@ -10,7 +10,6 @@ using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.History; using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.MediaFiles.TrackImport; using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
@ -7,7 +7,7 @@ using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
@ -360,4 +360,4 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist), Times.Once()); .Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist), Times.Once());
} }
} }
} }

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
@ -7,7 +7,6 @@ using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.TrackImport; using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
@ -376,4 +375,4 @@ namespace NzbDrone.Core.Test.MediaFiles
Times.Once()); Times.Once());
} }
} }
} }

@ -1,11 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles; using NzbDrone.Core.Profiles;
@ -15,7 +15,7 @@ using NzbDrone.Core.Music;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using FizzWare.NBuilder; using FizzWare.NBuilder;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport namespace NzbDrone.Core.Test.MediaFiles.TrackImport
{ {
[TestFixture] [TestFixture]
public class ImportDecisionMakerFixture : CoreTest<ImportDecisionMaker> public class ImportDecisionMakerFixture : CoreTest<ImportDecisionMaker>
@ -318,33 +318,6 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
.Verify(c => c.GetLocalTrack(It.IsAny<string>(), It.IsAny<Artist>(), null), Times.Never()); .Verify(c => c.GetLocalTrack(It.IsAny<string>(), It.IsAny<Artist>(), null), Times.Never());
} }
//[Test]
//public void should_use_folder_when_only_one_video_file_and_a_sample() /// WE DONT HAVE SAMPLES IN MUSIC
//{
// var audioFiles = new[]
// {
// @"C:\Test\Unsorted\Artist.Name.S01E01\S01E01.mkv".AsOsAgnostic(),
// @"C:\Test\Unsorted\Artist.Name.S01E01\S01E01.sample.mkv".AsOsAgnostic()
// };
// GivenSpecifications(_pass1);
// GivenVideoFiles(audioFiles.ToList());
// Mocker.GetMock<IDetectSample>()
// .Setup(s => s.IsSample(_artist, It.IsAny<QualityModel>(), It.Is<string>(c => c.Contains("sample")), It.IsAny<long>(), It.IsAny<bool>()))
// .Returns(true);
// var folderInfo = Parser.Parser.ParseMusicTitle("Artist.Name.S01E01");
// Subject.GetImportDecisions(_audioFiles, _artist, folderInfo);
// Mocker.GetMock<IParsingService>()
// .Verify(c => c.GetLocalTrack(It.IsAny<string>(), It.IsAny<Artist>(), It.IsAny<ParsedTrackInfo>()), Times.Exactly(2));
// Mocker.GetMock<IParsingService>()
// .Verify(c => c.GetLocalTrack(It.IsAny<string>(), It.IsAny<Artist>(), null), Times.Never());
//}
[Test] [Test]
public void should_not_use_folder_name_if_file_name_is_scene_name() public void should_not_use_folder_name_if_file_name_is_scene_name()
{ {

@ -1,17 +1,17 @@
using System; using System;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport namespace NzbDrone.Core.Test.MediaFiles.TrackImport
{ {
[TestFixture] [TestFixture]
public class SampleServiceFixture : CoreTest<DetectSample> public class SampleServiceFixture : CoreTest<DetectSample>

@ -1,4 +1,4 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
@ -6,48 +6,46 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications; using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Music;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
{ {
[TestFixture] [TestFixture]
public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification> public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification>
{ {
private Series _series; private Artist _artist;
private LocalEpisode _localEpisode; private LocalTrack _localTrack;
private string _rootFolder; private string _rootFolder;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_rootFolder = @"C:\Test\TV".AsOsAgnostic(); _rootFolder = @"C:\Test\Music".AsOsAgnostic();
_series = Builder<Series>.CreateNew() _artist = Builder<Artist>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard) .With(s => s.Path = Path.Combine(_rootFolder, "Alice in Chains"))
.With(s => s.Path = Path.Combine(_rootFolder, "30 Rock"))
.Build(); .Build();
var episodes = Builder<Episode>.CreateListOfSize(1) var tracks = Builder<Track>.CreateListOfSize(1)
.All() .All()
.With(e => e.SeasonNumber = 1)
.Build() .Build()
.ToList(); .ToList();
_localEpisode = new LocalEpisode _localTrack = new LocalTrack
{ {
Path = @"C:\Test\Unsorted\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(), Path = @"C:\Test\Unsorted\Alice in Chains\Alice in Chains - track1.mp3".AsOsAgnostic(),
Episodes = episodes, Tracks = tracks,
Series = _series Artist = _artist
}; };
} }
private void GivenFileSize(long size) private void GivenFileSize(long size)
{ {
_localEpisode.Size = size; _localTrack.Size = size;
} }
private void GivenFreeSpace(long? size) private void GivenFreeSpace(long? size)
@ -63,7 +61,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenFileSize(100.Megabytes()); GivenFileSize(100.Megabytes());
GivenFreeSpace(80.Megabytes()); GivenFreeSpace(80.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
@ -73,7 +71,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenFileSize(100.Megabytes()); GivenFileSize(100.Megabytes());
GivenFreeSpace(150.Megabytes()); GivenFreeSpace(150.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
@ -83,16 +81,16 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenFileSize(100.Megabytes()); GivenFileSize(100.Megabytes());
GivenFreeSpace(1.Gigabytes()); GivenFreeSpace(1.Gigabytes());
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
public void should_use_series_paths_parent_for_free_space_check() public void should_use_artist_paths_parent_for_free_space_check()
{ {
GivenFileSize(100.Megabytes()); GivenFileSize(100.Megabytes());
GivenFreeSpace(1.Gigabytes()); GivenFreeSpace(1.Gigabytes());
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetAvailableSpace(_rootFolder), Times.Once()); .Verify(v => v.GetAvailableSpace(_rootFolder), Times.Once());
@ -104,7 +102,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenFileSize(100.Megabytes()); GivenFileSize(100.Megabytes());
GivenFreeSpace(null); GivenFreeSpace(null);
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
@ -116,16 +114,16 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
.Setup(s => s.GetAvailableSpace(It.IsAny<string>())) .Setup(s => s.GetAvailableSpace(It.IsAny<string>()))
.Throws(new TestException()); .Throws(new TestException());
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
ExceptionVerification.ExpectedErrors(1); ExceptionVerification.ExpectedErrors(1);
} }
[Test] [Test]
public void should_skip_check_for_files_under_series_folder() public void should_skip_check_for_files_under_artist_folder()
{ {
_localEpisode.ExistingFile = true; _localTrack.ExistingFile = true;
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(s => s.GetAvailableSpace(It.IsAny<string>()), Times.Never()); .Verify(s => s.GetAvailableSpace(It.IsAny<string>()), Times.Never());
@ -140,7 +138,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
.Setup(s => s.GetAvailableSpace(It.IsAny<string>())) .Setup(s => s.GetAvailableSpace(It.IsAny<string>()))
.Returns(freeSpace); .Returns(freeSpace);
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
@ -150,7 +148,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
.Setup(s => s.SkipFreeSpaceCheckWhenImporting) .Setup(s => s.SkipFreeSpaceCheckWhenImporting)
.Returns(true); .Returns(true);
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
} }
} }

@ -1,22 +1,22 @@
using System; using System;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications; using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Music;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
{ {
[TestFixture] [TestFixture]
public class NotUnpackingSpecificationFixture : CoreTest<NotUnpackingSpecification> public class NotUnpackingSpecificationFixture : CoreTest<NotUnpackingSpecification>
{ {
private LocalEpisode _localEpisode; private LocalTrack _localTrack;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -25,17 +25,17 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
.SetupGet(s => s.DownloadClientWorkingFolders) .SetupGet(s => s.DownloadClientWorkingFolders)
.Returns("_UNPACK_|_FAILED_"); .Returns("_UNPACK_|_FAILED_");
_localEpisode = new LocalEpisode _localTrack = new LocalTrack
{ {
Path = @"C:\Test\Unsorted TV\30.rock\30.rock.s01e01.avi".AsOsAgnostic(), Path = @"C:\Test\Unsorted Music\Kid.Rock\Kid.Rock.Cowboy.mp3".AsOsAgnostic(),
Size = 100, Size = 100,
Series = Builder<Series>.CreateNew().Build() Artist = Builder<Artist>.CreateNew().Build()
}; };
} }
private void GivenInWorkingFolder() private void GivenInWorkingFolder()
{ {
_localEpisode.Path = @"C:\Test\Unsorted TV\_UNPACK_30.rock\someSubFolder\30.rock.s01e01.avi".AsOsAgnostic(); _localTrack.Path = @"C:\Test\Unsorted Music\_UNPACK_Kid.Rock\someSubFolder\Kid.Rock.Cowboy.mp3".AsOsAgnostic();
} }
private void GivenLastWriteTimeUtc(DateTime time) private void GivenLastWriteTimeUtc(DateTime time)
@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
[Test] [Test]
public void should_return_true_if_not_in_working_folder() public void should_return_true_if_not_in_working_folder()
{ {
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
@ -59,7 +59,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenInWorkingFolder(); GivenInWorkingFolder();
GivenLastWriteTimeUtc(DateTime.UtcNow.AddHours(-1)); GivenLastWriteTimeUtc(DateTime.UtcNow.AddHours(-1));
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenInWorkingFolder(); GivenInWorkingFolder();
GivenLastWriteTimeUtc(DateTime.UtcNow); GivenLastWriteTimeUtc(DateTime.UtcNow);
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
} }
[Test] [Test]
@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
GivenInWorkingFolder(); GivenInWorkingFolder();
GivenLastWriteTimeUtc(DateTime.UtcNow.AddDays(-5)); GivenLastWriteTimeUtc(DateTime.UtcNow.AddDays(-5));
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
} }
} }
} }

@ -1,156 +1,155 @@
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Marr.Data; using Marr.Data;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications; using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles; using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Music;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
{ {
[TestFixture] [TestFixture]
public class UpgradeSpecificationFixture : CoreTest<UpgradeSpecification> public class UpgradeSpecificationFixture : CoreTest<UpgradeSpecification>
{ {
private Series _series; private Artist _artist;
private LocalEpisode _localEpisode; private LocalTrack _localTrack;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_series = Builder<Series>.CreateNew() _artist = Builder<Artist>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard)
.With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() }) .With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() })
.Build(); .Build();
_localEpisode = new LocalEpisode _localTrack = new LocalTrack
{ {
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi", Path = @"C:\Test\Imagine Dragons\Imagine.Dragons.Song.1.mp3",
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)), Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)),
Series = _series Artist = _artist
}; };
} }
[Test] [Test]
public void should_return_true_if_no_existing_episodeFile() public void should_return_true_if_no_existing_trackFile()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1) _localTrack.Tracks = Builder<Track>.CreateListOfSize(1)
.All() .All()
.With(e => e.EpisodeFileId = 0) .With(e => e.TrackFileId = 0)
.With(e => e.EpisodeFile = null) .With(e => e.TrackFile = null)
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
public void should_return_true_if_no_existing_episodeFile_for_multi_episodes() public void should_return_true_if_no_existing_trackFile_for_multi_tracks()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2) _localTrack.Tracks = Builder<Track>.CreateListOfSize(2)
.All() .All()
.With(e => e.EpisodeFileId = 0) .With(e => e.TrackFileId = 0)
.With(e => e.EpisodeFile = null) .With(e => e.TrackFile = null)
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
public void should_return_true_if_upgrade_for_existing_episodeFile() public void should_return_true_if_upgrade_for_existing_trackFile()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1) _localTrack.Tracks = Builder<Track>.CreateListOfSize(1)
.All() .All()
.With(e => e.EpisodeFileId = 1) .With(e => e.TrackFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>( .With(e => e.TrackFile = new LazyLoaded<TrackFile>(
new EpisodeFile new TrackFile
{ {
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)) Quality = new QualityModel(Quality.MP3_192, new Revision(version: 1))
})) }))
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
public void should_return_true_if_upgrade_for_existing_episodeFile_for_multi_episodes() public void should_return_true_if_upgrade_for_existing_trackFile_for_multi_tracks()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2) _localTrack.Tracks = Builder<Track>.CreateListOfSize(2)
.All() .All()
.With(e => e.EpisodeFileId = 1) .With(e => e.TrackFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>( .With(e => e.TrackFile = new LazyLoaded<TrackFile>(
new EpisodeFile new TrackFile
{ {
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)) Quality = new QualityModel(Quality.MP3_192, new Revision(version: 1))
})) }))
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeTrue();
} }
[Test] [Test]
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile() public void should_return_false_if_not_an_upgrade_for_existing_trackFile()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1) _localTrack.Tracks = Builder<Track>.CreateListOfSize(1)
.All() .All()
.With(e => e.EpisodeFileId = 1) .With(e => e.TrackFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>( .With(e => e.TrackFile = new LazyLoaded<TrackFile>(
new EpisodeFile new TrackFile
{ {
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)) Quality = new QualityModel(Quality.FLAC, new Revision(version: 1))
})) }))
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
} }
[Test] [Test]
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile_for_multi_episodes() public void should_return_false_if_not_an_upgrade_for_existing_trackFile_for_multi_tracks()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2) _localTrack.Tracks = Builder<Track>.CreateListOfSize(2)
.All() .All()
.With(e => e.EpisodeFileId = 1) .With(e => e.TrackFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>( .With(e => e.TrackFile = new LazyLoaded<TrackFile>(
new EpisodeFile new TrackFile
{ {
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)) Quality = new QualityModel(Quality.FLAC, new Revision(version: 1))
})) }))
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
} }
[Test] [Test]
public void should_return_false_if_not_an_upgrade_for_one_existing_episodeFile_for_multi_episode() public void should_return_false_if_not_an_upgrade_for_one_existing_trackFile_for_multi_track()
{ {
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2) _localTrack.Tracks = Builder<Track>.CreateListOfSize(2)
.TheFirst(1) .TheFirst(1)
.With(e => e.EpisodeFileId = 1) .With(e => e.TrackFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>( .With(e => e.TrackFile = new LazyLoaded<TrackFile>(
new EpisodeFile new TrackFile
{ {
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)) Quality = new QualityModel(Quality.MP3_192, new Revision(version: 1))
})) }))
.TheNext(1) .TheNext(1)
.With(e => e.EpisodeFileId = 2) .With(e => e.TrackFileId = 2)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>( .With(e => e.TrackFile = new LazyLoaded<TrackFile>(
new EpisodeFile new TrackFile
{ {
Quality = new QualityModel(Quality.MP3_256, new Revision(version: 1)) Quality = new QualityModel(Quality.FLAC, new Revision(version: 1))
})) }))
.Build() .Build()
.ToList(); .ToList();
Subject.IsSatisfiedBy(_localEpisode).Accepted.Should().BeFalse(); Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
} }
} }
} }

@ -282,11 +282,11 @@
<Compile Include="MediaFiles\DownloadedEpisodesImportServiceFixture.cs" /> <Compile Include="MediaFiles\DownloadedEpisodesImportServiceFixture.cs" />
<Compile Include="MediaFiles\MediaInfo\MediaInfoFormatterTests\FormatAudioCodecFixture.cs" /> <Compile Include="MediaFiles\MediaInfo\MediaInfoFormatterTests\FormatAudioCodecFixture.cs" />
<Compile Include="MediaFiles\TrackFileMovingServiceTests\MoveTrackFileFixture.cs" /> <Compile Include="MediaFiles\TrackFileMovingServiceTests\MoveTrackFileFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\ImportDecisionMakerFixture.cs" /> <Compile Include="MediaFiles\TrackImport\ImportDecisionMakerFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\SampleServiceFixture.cs" /> <Compile Include="MediaFiles\TrackImport\SampleServiceFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\FreeSpaceSpecificationFixture.cs" /> <Compile Include="MediaFiles\TrackImport\Specifications\FreeSpaceSpecificationFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotUnpackingSpecificationFixture.cs" /> <Compile Include="MediaFiles\TrackImport\Specifications\NotUnpackingSpecificationFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecificationFixture.cs" /> <Compile Include="MediaFiles\TrackImport\Specifications\UpgradeSpecificationFixture.cs" />
<Compile Include="MediaFiles\ImportApprovedEpisodesFixture.cs" /> <Compile Include="MediaFiles\ImportApprovedEpisodesFixture.cs" />
<Compile Include="MediaFiles\MediaFileRepositoryFixture.cs" /> <Compile Include="MediaFiles\MediaFileRepositoryFixture.cs" />
<Compile Include="Messaging\Commands\CommandQueueManagerFixture.cs" /> <Compile Include="Messaging\Commands\CommandQueueManagerFixture.cs" />

@ -1,4 +1,4 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using NLog; using NLog;
@ -9,7 +9,6 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.History; using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -10,7 +10,6 @@ using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -212,4 +211,4 @@ namespace NzbDrone.Core.MediaFiles
} }
} }
} }
} }

@ -1,10 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
@ -268,4 +267,4 @@ namespace NzbDrone.Core.MediaFiles
//return new ImportResult(new ImportDecision(localEpisode, new Rejection("Unknown Series")), message); //return new ImportResult(new ImportDecision(localEpisode, new Rejection("Unknown Series")), message);
} }
} }
} }

@ -1,38 +0,0 @@
using System;
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{
public class SameEpisodesImportSpecification : IImportDecisionEngineSpecification
{
private readonly SameEpisodesSpecification _sameEpisodesSpecification;
private readonly Logger _logger;
public SameEpisodesImportSpecification(SameEpisodesSpecification sameEpisodesSpecification, Logger logger)
{
_sameEpisodesSpecification = sameEpisodesSpecification;
_logger = logger;
}
public RejectionType Type => RejectionType.Permanent;
public Decision IsSatisfiedBy(LocalEpisode localEpisode)
{
if (_sameEpisodesSpecification.IsSatisfiedBy(localEpisode.Episodes))
{
return Decision.Accept();
}
_logger.Debug("Episode file on disk contains more episodes than this file contains");
return Decision.Reject("Episode file on disk contains more episodes than this file contains");
}
public Decision IsSatisfiedBy(LocalTrack localTrack)
{
return Decision.Accept();
throw new NotImplementedException();
}
}
}

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using NLog; using NLog;
@ -6,7 +6,7 @@ using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MediaFiles.EpisodeImport namespace NzbDrone.Core.MediaFiles.TrackImport
{ {
public interface IDetectSample public interface IDetectSample
{ {

@ -1,11 +1,10 @@
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport namespace NzbDrone.Core.MediaFiles.TrackImport
{ {
public interface IImportDecisionEngineSpecification public interface IImportDecisionEngineSpecification
{ {
Decision IsSatisfiedBy(LocalEpisode localEpisode);
Decision IsSatisfiedBy(LocalTrack localTrack); Decision IsSatisfiedBy(LocalTrack localTrack);
} }
} }

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -12,10 +12,10 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Extras; using NzbDrone.Core.Extras;
using NzbDrone.Core.MediaFiles.TrackImport;
namespace NzbDrone.Core.MediaFiles.EpisodeImport namespace NzbDrone.Core.MediaFiles.TrackImport
{ {
[Obsolete("Used by Sonarr, not by Lidarr")]
public interface IImportApprovedEpisodes public interface IImportApprovedEpisodes
{ {
List<ImportResult> Import(List<ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto); List<ImportResult> Import(List<ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto);

@ -1,8 +1,7 @@
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -9,18 +9,14 @@ using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using NzbDrone.Core.MediaFiles.TrackImport;
namespace NzbDrone.Core.MediaFiles.EpisodeImport namespace NzbDrone.Core.MediaFiles.TrackImport
{ {
public interface IMakeImportDecision public interface IMakeImportDecision
{ {
//List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series);
List<ImportDecision> GetImportDecisions(List<string> musicFiles, Artist artist); List<ImportDecision> GetImportDecisions(List<string> musicFiles, Artist artist);
//List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, ParsedEpisodeInfo folderInfo, bool sceneSource);
List<ImportDecision> GetImportDecisions(List<string> musicFiles, Artist artist, ParsedTrackInfo folderInfo); List<ImportDecision> GetImportDecisions(List<string> musicFiles, Artist artist, ParsedTrackInfo folderInfo);
} }
@ -51,28 +47,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
_logger = logger; _logger = logger;
} }
//public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series)
//{
// return GetImportDecisions(videoFiles, series, null, false);
//}
//public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Artist series, ParsedEpisodeInfo folderInfo, bool sceneSource)
//{
// var newFiles = _mediaFileService.FilterExistingFiles(videoFiles.ToList(), series);
// _logger.Debug("Analyzing {0}/{1} files.", newFiles.Count, videoFiles.Count());
// var shouldUseFolderName = ShouldUseFolderName(videoFiles, series, folderInfo);
// var decisions = new List<ImportDecision>();
// foreach (var file in newFiles)
// {
// decisions.AddIfNotNull(GetDecision(file, series, folderInfo, sceneSource, shouldUseFolderName));
// }
// return decisions;
//}
public List<ImportDecision> GetImportDecisions(List<string> musicFiles, Artist artist) public List<ImportDecision> GetImportDecisions(List<string> musicFiles, Artist artist)
{ {
return GetImportDecisions(musicFiles, artist, null); return GetImportDecisions(musicFiles, artist, null);
@ -171,28 +145,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
return null; return null;
} }
private Rejection EvaluateSpec(IImportDecisionEngineSpecification spec, LocalEpisode localEpisode)
{
try
{
var result = spec.IsSatisfiedBy(localEpisode);
if (!result.Accepted)
{
return new Rejection(result.Reason);
}
}
catch (Exception e)
{
//e.Data.Add("report", remoteEpisode.Report.ToJson());
//e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo.ToJson());
_logger.Error(e, "Couldn't evaluate decision on {0}", localEpisode.Path);
return new Rejection($"{spec.GetType().Name}: {e.Message}");
}
return null;
}
private bool ShouldUseFolderName(List<string> musicFiles, Artist artist, ParsedTrackInfo folderInfo) private bool ShouldUseFolderName(List<string> musicFiles, Artist artist, ParsedTrackInfo folderInfo)
{ {
if (folderInfo == null) if (folderInfo == null)

@ -1,8 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.MediaFiles.TrackImport;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{ {
public class ManualImportCommand : Command public class ManualImportCommand : Command
{ {

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{ {
public class ManualImportFile public class ManualImportFile
{ {

@ -1,9 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{ {
public class ManualImportItem public class ManualImportItem
{ {

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -15,9 +15,8 @@ using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.MediaFiles.TrackImport;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{ {
public interface IManualImportService public interface IManualImportService
{ {

@ -1,7 +1,6 @@
using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.MediaFiles.TrackImport;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{ {
public class ManuallyImportedFile public class ManuallyImportedFile
{ {

@ -1,4 +1,4 @@
using System; using System;
using System.IO; using System.IO;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -6,7 +6,7 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications
{ {
public class FreeSpaceSpecification : IImportDecisionEngineSpecification public class FreeSpaceSpecification : IImportDecisionEngineSpecification
{ {
@ -21,49 +21,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
_logger = logger; _logger = logger;
} }
public Decision IsSatisfiedBy(LocalEpisode localEpisode)
{
if (_configService.SkipFreeSpaceCheckWhenImporting)
{
_logger.Debug("Skipping free space check when importing");
return Decision.Accept();
}
try
{
if (localEpisode.ExistingFile)
{
_logger.Debug("Skipping free space check for existing episode");
return Decision.Accept();
}
var path = Directory.GetParent(localEpisode.Series.Path);
var freeSpace = _diskProvider.GetAvailableSpace(path.FullName);
if (!freeSpace.HasValue)
{
_logger.Debug("Free space check returned an invalid result for: {0}", path);
return Decision.Accept();
}
if (freeSpace < localEpisode.Size + 100.Megabytes())
{
_logger.Warn("Not enough free space ({0}) to import: {1} ({2})", freeSpace, localEpisode, localEpisode.Size);
return Decision.Reject("Not enough free space");
}
}
catch (DirectoryNotFoundException ex)
{
_logger.Error(ex, "Unable to check free disk space while importing.");
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to check free disk space while importing. {0}", localEpisode.Path);
}
return Decision.Accept();
}
public Decision IsSatisfiedBy(LocalTrack localTrack) public Decision IsSatisfiedBy(LocalTrack localTrack)
{ {
if (_configService.SkipFreeSpaceCheckWhenImporting) if (_configService.SkipFreeSpaceCheckWhenImporting)
@ -76,7 +33,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{ {
if (localTrack.ExistingFile) if (localTrack.ExistingFile)
{ {
_logger.Debug("Skipping free space check for existing episode"); _logger.Debug("Skipping free space check for existing track");
return Decision.Accept(); return Decision.Accept();
} }

@ -1,4 +1,4 @@
using System; using System;
using System.IO; using System.IO;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -7,7 +7,7 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications
{ {
public class NotUnpackingSpecification : IImportDecisionEngineSpecification public class NotUnpackingSpecification : IImportDecisionEngineSpecification
{ {
@ -22,30 +22,30 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
_logger = logger; _logger = logger;
} }
public Decision IsSatisfiedBy(LocalEpisode localEpisode) public Decision IsSatisfiedBy(LocalTrack localTrack)
{ {
if (localEpisode.ExistingFile) if (localTrack.ExistingFile)
{ {
_logger.Debug("{0} is in series folder, skipping unpacking check", localEpisode.Path); _logger.Debug("{0} is in artist folder, skipping unpacking check", localTrack.Path);
return Decision.Accept(); return Decision.Accept();
} }
foreach (var workingFolder in _configService.DownloadClientWorkingFolders.Split('|')) foreach (var workingFolder in _configService.DownloadClientWorkingFolders.Split('|'))
{ {
DirectoryInfo parent = Directory.GetParent(localEpisode.Path); DirectoryInfo parent = Directory.GetParent(localTrack.Path);
while (parent != null) while (parent != null)
{ {
if (parent.Name.StartsWith(workingFolder)) if (parent.Name.StartsWith(workingFolder))
{ {
if (OsInfo.IsNotWindows) if (OsInfo.IsNotWindows)
{ {
_logger.Debug("{0} is still being unpacked", localEpisode.Path); _logger.Debug("{0} is still being unpacked", localTrack.Path);
return Decision.Reject("File is still being unpacked"); return Decision.Reject("File is still being unpacked");
} }
if (_diskProvider.FileGetLastWrite(localEpisode.Path) > DateTime.UtcNow.AddMinutes(-5)) if (_diskProvider.FileGetLastWrite(localTrack.Path) > DateTime.UtcNow.AddMinutes(-5))
{ {
_logger.Debug("{0} appears to be unpacking still", localEpisode.Path); _logger.Debug("{0} appears to be unpacking still", localTrack.Path);
return Decision.Reject("File is still being unpacked"); return Decision.Reject("File is still being unpacked");
} }
} }
@ -56,11 +56,5 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
return Decision.Accept(); return Decision.Accept();
} }
public Decision IsSatisfiedBy(LocalTrack localTrack)
{
return Decision.Accept();
throw new NotImplementedException();
}
} }
} }

@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NLog; using NLog;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications
@ -22,11 +21,6 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications
public RejectionType Type => RejectionType.Permanent; public RejectionType Type => RejectionType.Permanent;
public Decision IsSatisfiedBy(LocalEpisode localEpisode)
{
throw new NotImplementedException();
}
public Decision IsSatisfiedBy(LocalTrack localTrack) public Decision IsSatisfiedBy(LocalTrack localTrack)
{ {
if (_sameTracksSpecification.IsSatisfiedBy(localTrack.Tracks)) if (_sameTracksSpecification.IsSatisfiedBy(localTrack.Tracks))

@ -1,11 +1,11 @@
using System; using System;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications namespace NzbDrone.Core.MediaFiles.TrackImport.Specifications
{ {
public class UpgradeSpecification : IImportDecisionEngineSpecification public class UpgradeSpecification : IImportDecisionEngineSpecification
{ {
@ -27,17 +27,5 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
return Decision.Accept(); return Decision.Accept();
} }
public Decision IsSatisfiedBy(LocalEpisode localEpisode)
{
var qualityComparer = new QualityModelComparer(localEpisode.Series.Profile);
if (localEpisode.Episodes.Any(e => e.EpisodeFileId != 0 && qualityComparer.Compare(e.EpisodeFile.Value.Quality, localEpisode.Quality) > 0))
{
_logger.Debug("This file isn't an upgrade for all episodes. Skipping {0}", localEpisode.Path);
return Decision.Reject("Not an upgrade for existing episode file(s)");
}
return Decision.Accept();
}
} }
} }

@ -743,20 +743,19 @@
</Compile> </Compile>
<Compile Include="MediaFiles\DownloadedAlbumsCommandService.cs" /> <Compile Include="MediaFiles\DownloadedAlbumsCommandService.cs" />
<Compile Include="MediaFiles\EpisodeFile.cs" /> <Compile Include="MediaFiles\EpisodeFile.cs" />
<Compile Include="MediaFiles\EpisodeImport\IImportDecisionEngineSpecification.cs" /> <Compile Include="MediaFiles\TrackImport\IImportDecisionEngineSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs" /> <Compile Include="MediaFiles\TrackImport\ImportApprovedEpisodes.cs" />
<Compile Include="MediaFiles\EpisodeImport\ImportDecisionMaker.cs" /> <Compile Include="MediaFiles\TrackImport\ImportDecisionMaker.cs" />
<Compile Include="MediaFiles\TrackImport\ImportResultType.cs" /> <Compile Include="MediaFiles\TrackImport\ImportResultType.cs" />
<Compile Include="MediaFiles\EpisodeImport\Manual\ManualImportFile.cs" /> <Compile Include="MediaFiles\TrackImport\Manual\ManualImportFile.cs" />
<Compile Include="MediaFiles\EpisodeImport\Manual\ManualImportCommand.cs" /> <Compile Include="MediaFiles\TrackImport\Manual\ManualImportCommand.cs" />
<Compile Include="MediaFiles\EpisodeImport\Manual\ManualImportItem.cs" /> <Compile Include="MediaFiles\TrackImport\Manual\ManualImportItem.cs" />
<Compile Include="MediaFiles\EpisodeImport\Manual\ManualImportService.cs" /> <Compile Include="MediaFiles\TrackImport\Manual\ManualImportService.cs" />
<Compile Include="MediaFiles\EpisodeImport\DetectSample.cs" /> <Compile Include="MediaFiles\TrackImport\DetectSample.cs" />
<Compile Include="MediaFiles\EpisodeImport\Manual\ManuallyImportedFile.cs" /> <Compile Include="MediaFiles\TrackImport\Manual\ManuallyImportedFile.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\FreeSpaceSpecification.cs" /> <Compile Include="MediaFiles\TrackImport\Specifications\FreeSpaceSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotUnpackingSpecification.cs" /> <Compile Include="MediaFiles\TrackImport\Specifications\NotUnpackingSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\SameEpisodesImportSpecification.cs" /> <Compile Include="MediaFiles\TrackImport\Specifications\UpgradeSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" />
<Compile Include="MediaFiles\Events\ArtistRenamedEvent.cs" /> <Compile Include="MediaFiles\Events\ArtistRenamedEvent.cs" />
<Compile Include="MediaFiles\Events\ArtistScannedEvent.cs" /> <Compile Include="MediaFiles\Events\ArtistScannedEvent.cs" />
<Compile Include="MediaFiles\Events\ArtistScanSkippedEvent.cs" /> <Compile Include="MediaFiles\Events\ArtistScanSkippedEvent.cs" />

Loading…
Cancel
Save