From bf1547a5245287a3acf3c862211dafa8f583025e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 1 Sep 2014 11:14:54 -0700 Subject: [PATCH] Pneumatic will set the download client ID for strm files --- .../EpisodeImport/SampleServiceFixture.cs | 10 +++++++ .../Download/Clients/Pneumatic/Pneumatic.cs | 30 ++++++++++++------- .../MediaFiles/EpisodeImport/SampleService.cs | 6 ++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/SampleServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/SampleServiceFixture.cs index 17fa05811..e15234f93 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/SampleServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/SampleServiceFixture.cs @@ -70,6 +70,16 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport Mocker.GetMock().Verify(c => c.GetRunTime(It.IsAny()), Times.Never()); } + [Test] + public void should_return_false_for_strm() + { + _localEpisode.Path = @"C:\Test\some.show.s01e01.strm"; + + ShouldBeFalse(); + + Mocker.GetMock().Verify(c => c.GetRunTime(It.IsAny()), Times.Never()); + } + [Test] public void should_use_runtime() { diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index 3127f0e2d..44834d277 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -56,7 +56,8 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic _logger.Debug("NZB Download succeeded, saved to: {0}", nzbFile); - WriteStrmFile(title, nzbFile); + var strmFile = WriteStrmFile(title, nzbFile); + return GetDownloadClientId(strmFile); return null; } @@ -71,27 +72,27 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic public override IEnumerable GetItems() { - foreach (var videoFile in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly)) + foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly)) { - if (Path.GetExtension(videoFile) != ".strm") + if (Path.GetExtension(file) != ".strm") { continue; } - var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile)); + var title = FileNameBuilder.CleanFileName(Path.GetFileName(file)); var historyItem = new DownloadClientItem { DownloadClient = Definition.Name, - DownloadClientId = Definition.Name + "_" + Path.GetFileName(videoFile) + "_" + _diskProvider.FileGetLastWriteUtc(videoFile).Ticks, + DownloadClientId = GetDownloadClientId(file), Title = title, - TotalSize = _diskProvider.GetFileSize(videoFile), + TotalSize = _diskProvider.GetFileSize(file), - OutputPath = videoFile + OutputPath = file }; - if (_diskProvider.IsFileLocked(videoFile)) + if (_diskProvider.IsFileLocked(file)) { historyItem.Status = DownloadItemStatus.Downloading; } @@ -155,7 +156,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic return null; } - private void WriteStrmFile(String title, String nzbFile) + private String WriteStrmFile(String title, String nzbFile) { String folder; @@ -175,7 +176,16 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic } var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", nzbFile, title); - _diskProvider.WriteAllText(Path.Combine(folder, title + ".strm"), contents); + var filename = Path.Combine(folder, title + ".strm"); + + _diskProvider.WriteAllText(filename, contents); + + return filename; + } + + private String GetDownloadClientId(String filename) + { + return Definition.Name + "_" + Path.GetFileName(filename) + "_" + _diskProvider.FileGetLastWriteUtc(filename).Ticks; } } } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/SampleService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/SampleService.cs index 12b3ed26c..0515a0aa6 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/SampleService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/SampleService.cs @@ -50,6 +50,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport return false; } + if (extension != null && extension.Equals(".strm", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Debug("Skipping sample check for .strm file"); + return false; + } + try { var runTime = _videoFileInfoReader.GetRunTime(path);