Cleanup Disk Scan Service (#69)

* Cleanup Disk Scan Service

* Fix Encoding, Change mp4 to flac
pull/70/head
Qstick 7 years ago committed by GitHub
parent 9fba2458d8
commit 19414912ad

@ -66,7 +66,7 @@ namespace NzbDrone.Api.FileSystem
return new string[0].AsResponse(); return new string[0].AsResponse();
} }
return _diskScanService.GetVideoFiles(path).Select(f => new { return _diskScanService.GetAudioFiles(path).Select(f => new {
Path = f, Path = f,
RelativePath = path.GetRelativePath(f), RelativePath = path.GetRelativePath(f),
Name = Path.GetFileName(f) Name = Path.GetFileName(f)

@ -80,7 +80,7 @@ namespace NzbDrone.Api.Music
return mappedArtist; return mappedArtist;
} }
var files = _diskScanService.GetMusicFiles(page.Path); var files = _diskScanService.GetAudioFiles(page.Path);
// Check for music files in directory // Check for music files in directory
if (files.Count() == 0) if (files.Count() == 0)
@ -149,4 +149,4 @@ namespace NzbDrone.Api.Music
} }
} }
} }
} }

@ -9,7 +9,6 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
@ -60,7 +59,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
} }
private void GivenSeriesFolder() private void GivenArtistFolder()
{ {
GivenRootFolder(_artist.Path); GivenRootFolder(_artist.Path);
} }
@ -87,7 +86,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_not_scan_if_series_root_folder_is_empty() public void should_not_scan_if_artist_root_folder_is_empty()
{ {
GivenRootFolder(); GivenRootFolder();
@ -106,7 +105,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_create_if_series_folder_does_not_exist_but_create_folder_enabled() public void should_create_if_artist_folder_does_not_exist_but_create_folder_enabled()
{ {
GivenRootFolder(_otherArtistFolder); GivenRootFolder(_otherArtistFolder);
@ -121,7 +120,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_not_create_if_series_folder_does_not_exist_and_create_folder_disabled() public void should_not_create_if_artist_folder_does_not_exist_and_create_folder_disabled()
{ {
GivenRootFolder(_otherArtistFolder); GivenRootFolder(_otherArtistFolder);
@ -136,7 +135,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_clean_but_not_import_if_series_folder_does_not_exist() public void should_clean_but_not_import_if_artist_folder_does_not_exist()
{ {
GivenRootFolder(_otherArtistFolder); GivenRootFolder(_otherArtistFolder);
@ -153,7 +152,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_clean_but_not_import_if_series_folder_does_not_exist_and_create_folder_enabled() public void should_clean_but_not_import_if_artist_folder_does_not_exist_and_create_folder_enabled()
{ {
GivenRootFolder(_otherArtistFolder); GivenRootFolder(_otherArtistFolder);
@ -171,14 +170,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_find_files_at_root_of_series_folder() public void should_find_files_at_root_of_artist_folder()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -190,15 +189,15 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_extras_subfolder() public void should_not_scan_extras_subfolder()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "EXTRAS", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "EXTRAS", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Extras", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Extras", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "EXTRAs", "file3.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "EXTRAs", "file3.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "ExTrAs", "file4.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "ExTrAs", "file4.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -213,13 +212,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_AppleDouble_subfolder() public void should_not_scan_AppleDouble_subfolder()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, ".AppleDouble", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".AppleDouble", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, ".appledouble", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".appledouble", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -229,20 +228,20 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_scan_extras_series_and_subfolders() public void should_scan_extras_artist_and_subfolders()
{ {
_artist.Path = @"C:\Test\TV\Extras".AsOsAgnostic(); _artist.Path = @"C:\Test\Music\Extras".AsOsAgnostic();
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "Extras", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Extras", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, ".AppleDouble", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".AppleDouble", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e02.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", "s01e02.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 2", "s02e01.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 2", "s02e01.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 2", "s02e02.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 2", "s02e02.flac").AsOsAgnostic(),
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -254,14 +253,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_subfolders_that_start_with_period() public void should_not_scan_subfolders_that_start_with_period()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, ".@__thumb", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".@__thumb", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, ".@__THUMB", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".@__THUMB", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, ".hidden", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".hidden", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -273,15 +272,15 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_subfolder_of_season_folder_that_starts_with_a_period() public void should_not_scan_subfolder_of_season_folder_that_starts_with_a_period()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "Season 1", ".@__thumb", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", ".@__thumb", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", ".@__THUMB", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", ".@__THUMB", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", ".hidden", "file2.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", ".hidden", "file2.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", ".AppleDouble", "s01e01.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", ".AppleDouble", "s01e01.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -293,12 +292,12 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_Synology_eaDir() public void should_not_scan_Synology_eaDir()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "@eaDir", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "@eaDir", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -310,12 +309,12 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_thumb_folder() public void should_not_scan_thumb_folder()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, ".@__thumb", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, ".@__thumb", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -327,14 +326,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_scan_dotHack_folder() public void should_scan_dotHack_folder()
{ {
_artist.Path = @"C:\Test\TV\.hack".AsOsAgnostic(); _artist.Path = @"C:\Test\Music\.hack".AsOsAgnostic();
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "Season 1", "file1.mkv").AsOsAgnostic(), Path.Combine(_artist.Path, "Season 1", "file1.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "Season 1", "s01e01.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -346,12 +345,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_exclude_osx_metadata_files() public void should_exclude_osx_metadata_files()
{ {
GivenSeriesFolder(); GivenArtistFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_artist.Path, "._24 The Status Quo Combustion.mp4").AsOsAgnostic(), Path.Combine(_artist.Path, ".DS_STORE").AsOsAgnostic(),
Path.Combine(_artist.Path, "24 The Status Quo Combustion.mkv").AsOsAgnostic() Path.Combine(_artist.Path, "._24 The Status Quo Combustion.flac").AsOsAgnostic(),
Path.Combine(_artist.Path, "24 The Status Quo Combustion.flac").AsOsAgnostic()
}); });
Subject.Scan(_artist); Subject.Scan(_artist);
@ -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());
} }
} }
} }

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.MediaFiles
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>())) Mocker.GetMock<IDiskScanService>().Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(_videoFiles); .Returns(_videoFiles);
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>())) Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
@ -95,13 +95,13 @@ namespace NzbDrone.Core.Test.MediaFiles
.Returns(true); .Returns(true);
Mocker.GetMock<IDiskScanService>() Mocker.GetMock<IDiskScanService>()
.Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>())) .Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]); .Returns(new string[0]);
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory)); Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskScanService>() Mocker.GetMock<IDiskScanService>()
.Verify(v => v.GetVideoFiles(It.IsAny<string>(), true), Times.Never()); .Verify(v => v.GetAudioFiles(It.IsAny<string>(), true), Times.Never());
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
@ -376,4 +376,4 @@ namespace NzbDrone.Core.Test.MediaFiles
Times.Once()); Times.Once());
} }
} }
} }

@ -351,7 +351,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\XemProxyFixture.cs" /> <Compile Include="Providers\XemProxyFixture.cs" />
<Compile Include="ProviderTests\DiskProviderTests\ArchiveProviderFixture.cs" /> <Compile Include="ProviderTests\DiskProviderTests\ArchiveProviderFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" /> <Compile Include="ProviderTests\DiskScanProviderTests\GetAudioFilesFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" /> <Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\DeleteDirectoryFixture.cs" /> <Compile Include="ProviderTests\RecycleBinProviderTests\DeleteDirectoryFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\DeleteFileFixture.cs" /> <Compile Include="ProviderTests\RecycleBinProviderTests\DeleteFileFixture.cs" />

@ -8,12 +8,12 @@ using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Music;
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
public class GetVideoFilesFixture : CoreTest<DiskScanService> public class GetAudioFilesFixture : CoreTest<DiskScanService>
{ {
private string[] _fileNames; private string[] _fileNames;
@ -22,10 +22,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
_fileNames = new[] _fileNames = new[]
{ {
@"30 Rock1.mkv", @"30 Rock1.mp3",
@"30 Rock2.avi", @"30 Rock2.flac",
@"30 Rock3.MP4", @"30 Rock3.ogg",
@"30 Rock4.wMv", @"30 Rock4.m4a",
@"30 Rock.avi",
@"movie.exe", @"movie.exe",
@"movie" @"movie"
}; };
@ -49,7 +50,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
var path = @"C:\Test\"; var path = @"C:\Test\";
Subject.GetVideoFiles(path); Subject.GetAudioFiles(path);
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
@ -60,7 +61,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
var path = @"C:\Test\"; var path = @"C:\Test\";
Subject.GetVideoFiles(path, true); Subject.GetAudioFiles(path, true);
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
@ -71,19 +72,19 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
var path = @"C:\Test\"; var path = @"C:\Test\";
Subject.GetVideoFiles(path, false); Subject.GetAudioFiles(path, false);
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never());
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once()); Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once());
} }
[Test] [Test]
public void should_return_video_files_only() public void should_return_audio_files_only()
{ {
var path = @"C:\Test\"; var path = @"C:\Test\";
GivenFiles(GetFiles(path)); GivenFiles(GetFiles(path));
Subject.GetVideoFiles(path).Should().HaveCount(4); Subject.GetAudioFiles(path).Should().HaveCount(4);
} }
[TestCase("Extras")] [TestCase("Extras")]
@ -99,13 +100,13 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var specialFiles = GetFiles(path, subFolder).ToList(); var specialFiles = GetFiles(path, subFolder).ToList();
var allFiles = files.Concat(specialFiles); var allFiles = files.Concat(specialFiles);
var series = Builder<Series>.CreateNew() var artist = Builder<Artist>.CreateNew()
.With(s => s.Path = path) .With(s => s.Path = path)
.Build(); .Build();
var filteredFiles = Subject.FilterFiles(series, allFiles); var filteredFiles = Subject.FilterFiles(artist, allFiles);
filteredFiles.Should().NotContain(specialFiles); filteredFiles.Should().NotContain(specialFiles);
filteredFiles.Count.Should().BeGreaterThan(0); filteredFiles.Count.Should().BeGreaterThan(0);
} }
} }
} }

@ -86,7 +86,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
yield return newWatchItem; yield return newWatchItem;
} }
foreach (var videoFile in _diskScanService.GetVideoFiles(watchFolder, false)) foreach (var videoFile in _diskScanService.GetAudioFiles(watchFolder, false))
{ {
var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile)); var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile));
@ -193,4 +193,4 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
return HashConverter.GetHash(data.ToString()).ToHexString(); return HashConverter.GetHash(data.ToString()).ToHexString();
} }
} }
} }

@ -10,7 +10,7 @@ using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Extras namespace NzbDrone.Core.Extras
{ {
public class ExistingExtraFileService : IHandle<SeriesScannedEvent> public class ExistingExtraFileService : IHandle<ArtistScannedEvent>
{ {
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly IDiskScanService _diskScanService; private readonly IDiskScanService _diskScanService;
@ -28,32 +28,34 @@ namespace NzbDrone.Core.Extras
_logger = logger; _logger = logger;
} }
public void Handle(SeriesScannedEvent message) public void Handle(ArtistScannedEvent message)
{ {
var series = message.Series; var artist = message.Artist;
var extraFiles = new List<ExtraFile>(); var extraFiles = new List<ExtraFile>();
if (!_diskProvider.FolderExists(series.Path)) if (!_diskProvider.FolderExists(artist.Path))
{ {
return; return;
} }
_logger.Debug("Looking for existing extra files in {0}", series.Path); _logger.Debug("Looking for existing extra files in {0}", artist.Path);
var filesOnDisk = _diskScanService.GetNonVideoFiles(series.Path); var filesOnDisk = _diskScanService.GetNonAudioFiles(artist.Path);
var possibleExtraFiles = _diskScanService.FilterFiles(series, filesOnDisk); var possibleExtraFiles = _diskScanService.FilterFiles(artist, filesOnDisk);
var filteredFiles = possibleExtraFiles; var filteredFiles = possibleExtraFiles;
var importedFiles = new List<string>(); var importedFiles = new List<string>();
foreach (var existingExtraFileImporter in _existingExtraFileImporters) foreach (var existingExtraFileImporter in _existingExtraFileImporters)
{ {
var imported = existingExtraFileImporter.ProcessFiles(series, filteredFiles, importedFiles); // TODO Implement existingExtraFileImporter for Audio Files
importedFiles.AddRange(imported.Select(f => Path.Combine(series.Path, f.RelativePath))); //var imported = existingExtraFileImporter.ProcessFiles(artist, filteredFiles, importedFiles);
//importedFiles.AddRange(imported.Select(f => Path.Combine(artist.Path, f.RelativePath)));
} }
_logger.Info("Found {0} extra files", extraFiles.Count); _logger.Info("Found {0} extra files", extraFiles.Count);
} }
} }
} }

@ -15,7 +15,6 @@ 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;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Tv.Events;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using NzbDrone.Core.Music.Events; using NzbDrone.Core.Music.Events;
using NzbDrone.Core.MediaFiles.TrackImport; using NzbDrone.Core.MediaFiles.TrackImport;
@ -25,10 +24,9 @@ namespace NzbDrone.Core.MediaFiles
public interface IDiskScanService public interface IDiskScanService
{ {
void Scan(Artist artist); void Scan(Artist artist);
string[] GetVideoFiles(string path, bool allDirectories = true); string[] GetAudioFiles(string path, bool allDirectories = true);
string[] GetMusicFiles(string path, bool allDirectories = true); string[] GetNonAudioFiles(string path, bool allDirectories = true);
string[] GetNonVideoFiles(string path, bool allDirectories = true); List<string> FilterFiles(Artist artist, IEnumerable<string> files);
List<string> FilterFiles(Series series, IEnumerable<string> files);
} }
public class DiskScanService : public class DiskScanService :
@ -40,7 +38,6 @@ namespace NzbDrone.Core.MediaFiles
private readonly IMakeImportDecision _importDecisionMaker; private readonly IMakeImportDecision _importDecisionMaker;
private readonly IImportApprovedTracks _importApprovedTracks; private readonly IImportApprovedTracks _importApprovedTracks;
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly ISeriesService _seriesService;
private readonly IArtistService _artistService; private readonly IArtistService _artistService;
private readonly IMediaFileTableCleanupService _mediaFileTableCleanupService; private readonly IMediaFileTableCleanupService _mediaFileTableCleanupService;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
@ -50,7 +47,6 @@ namespace NzbDrone.Core.MediaFiles
IMakeImportDecision importDecisionMaker, IMakeImportDecision importDecisionMaker,
IImportApprovedTracks importApprovedTracks, IImportApprovedTracks importApprovedTracks,
IConfigService configService, IConfigService configService,
ISeriesService seriesService,
IArtistService artistService, IArtistService artistService,
IMediaFileTableCleanupService mediaFileTableCleanupService, IMediaFileTableCleanupService mediaFileTableCleanupService,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
@ -60,7 +56,6 @@ namespace NzbDrone.Core.MediaFiles
_importDecisionMaker = importDecisionMaker; _importDecisionMaker = importDecisionMaker;
_importApprovedTracks = importApprovedTracks; _importApprovedTracks = importApprovedTracks;
_configService = configService; _configService = configService;
_seriesService = seriesService;
_artistService = artistService; _artistService = artistService;
_mediaFileTableCleanupService = mediaFileTableCleanupService; _mediaFileTableCleanupService = mediaFileTableCleanupService;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
@ -108,7 +103,7 @@ namespace NzbDrone.Core.MediaFiles
} }
var musicFilesStopwatch = Stopwatch.StartNew(); var musicFilesStopwatch = Stopwatch.StartNew();
var mediaFileList = FilterFiles(artist, GetMusicFiles(artist.Path)).ToList(); var mediaFileList = FilterFiles(artist, GetAudioFiles(artist.Path)).ToList();
musicFilesStopwatch.Stop(); musicFilesStopwatch.Stop();
_logger.Trace("Finished getting track files for: {0} [{1}]", artist, musicFilesStopwatch.Elapsed); _logger.Trace("Finished getting track files for: {0} [{1}]", artist, musicFilesStopwatch.Elapsed);
@ -129,34 +124,13 @@ namespace NzbDrone.Core.MediaFiles
_mediaFileTableCleanupService.Clean(artist, mediaFileList); _mediaFileTableCleanupService.Clean(artist, mediaFileList);
} }
//private void CompletedScanning(Series series)
//{
// _logger.Info("Completed scanning disk for {0}", series.Title);
// _eventAggregator.PublishEvent(new SeriesScannedEvent(series));
//}
private void CompletedScanning(Artist artist) private void CompletedScanning(Artist artist)
{ {
_logger.Info("Completed scanning disk for {0}", artist.Name); _logger.Info("Completed scanning disk for {0}", artist.Name);
_eventAggregator.PublishEvent(new ArtistScannedEvent(artist)); _eventAggregator.PublishEvent(new ArtistScannedEvent(artist));
} }
public string[] GetVideoFiles(string path, bool allDirectories = true) public string[] GetAudioFiles(string path, bool allDirectories = true)
{
_logger.Debug("Scanning '{0}' for video files", path);
var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var filesOnDisk = _diskProvider.GetFiles(path, searchOption).ToList();
var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file).ToLower()))
.ToList();
_logger.Trace("{0} files were found in {1}", filesOnDisk.Count, path);
_logger.Debug("{0} video files were found in {1}", mediaFileList.Count, path);
return mediaFileList.ToArray();
}
public string[] GetMusicFiles(string path, bool allDirectories = true)
{ {
_logger.Debug("Scanning '{0}' for music files", path); _logger.Debug("Scanning '{0}' for music files", path);
@ -171,7 +145,7 @@ namespace NzbDrone.Core.MediaFiles
return mediaFileList.ToArray(); return mediaFileList.ToArray();
} }
public string[] GetNonVideoFiles(string path, bool allDirectories = true) public string[] GetNonAudioFiles(string path, bool allDirectories = true)
{ {
_logger.Debug("Scanning '{0}' for non-music files", path); _logger.Debug("Scanning '{0}' for non-music files", path);
@ -186,13 +160,6 @@ namespace NzbDrone.Core.MediaFiles
return mediaFileList.ToArray(); return mediaFileList.ToArray();
} }
public List<string> FilterFiles(Series series, IEnumerable<string> files)
{
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(series.Path.GetRelativePath(file)))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
.ToList();
}
public List<string> FilterFiles(Artist artist, IEnumerable<string> files) public List<string> FilterFiles(Artist artist, IEnumerable<string> files)
{ {
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(artist.Path.GetRelativePath(file))) return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(artist.Path.GetRelativePath(file)))

@ -60,7 +60,7 @@ namespace NzbDrone.Core.MediaFiles
results.AddRange(folderResults); results.AddRange(folderResults);
} }
foreach (var videoFile in _diskScanService.GetNonVideoFiles(directoryInfo.FullName, false)) foreach (var videoFile in _diskScanService.GetNonAudioFiles(directoryInfo.FullName, false))
{ {
var fileResults = ProcessFile(new FileInfo(videoFile), ImportMode.Auto, null); var fileResults = ProcessFile(new FileInfo(videoFile), ImportMode.Auto, null);
results.AddRange(fileResults); results.AddRange(fileResults);
@ -101,7 +101,7 @@ namespace NzbDrone.Core.MediaFiles
public bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Series series) public bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Series series)
{ {
var videoFiles = _diskScanService.GetNonVideoFiles(directoryInfo.FullName); var videoFiles = _diskScanService.GetNonAudioFiles(directoryInfo.FullName);
var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".rar"); var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".rar");
foreach (var videoFile in videoFiles) foreach (var videoFile in videoFiles)
@ -268,4 +268,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);
} }
} }
} }
Loading…
Cancel
Save