From 57448fd29a4517150af615387041ec9adc106bf1 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 1 Sep 2014 09:24:17 -0700 Subject: [PATCH] Fixed: Pneumatic now has a watch folder (for importing strm files) --- .../Download/Clients/Pneumatic/Pneumatic.cs | 70 +++++++++++++++++-- .../Clients/Pneumatic/PneumaticSettings.cs | 8 ++- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index 6ad451295..3127f0e2d 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -49,15 +49,14 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic title = FileNameBuilder.CleanFileName(title); //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) - var filename = Path.Combine(Settings.NzbFolder, title + ".nzb"); + var nzbFile = Path.Combine(Settings.NzbFolder, title + ".nzb"); - _logger.Debug("Downloading NZB from: {0} to: {1}", url, filename); - _httpProvider.DownloadFile(url, filename); + _logger.Debug("Downloading NZB from: {0} to: {1}", url, nzbFile); + _httpProvider.DownloadFile(url, nzbFile); - _logger.Debug("NZB Download succeeded, saved to: {0}", filename); + _logger.Debug("NZB Download succeeded, saved to: {0}", nzbFile); - var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title); - _diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents); + WriteStrmFile(title, nzbFile); return null; } @@ -72,7 +71,40 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic public override IEnumerable GetItems() { - return new DownloadClientItem[0]; + foreach (var videoFile in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly)) + { + if (Path.GetExtension(videoFile) != ".strm") + { + continue; + } + + var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile)); + + var historyItem = new DownloadClientItem + { + DownloadClient = Definition.Name, + DownloadClientId = Definition.Name + "_" + Path.GetFileName(videoFile) + "_" + _diskProvider.FileGetLastWriteUtc(videoFile).Ticks, + Title = title, + + TotalSize = _diskProvider.GetFileSize(videoFile), + + OutputPath = videoFile + }; + + if (_diskProvider.IsFileLocked(videoFile)) + { + historyItem.Status = DownloadItemStatus.Downloading; + } + else + { + historyItem.Status = DownloadItemStatus.Completed; + } + + historyItem.RemoteEpisode = GetRemoteEpisode(historyItem.Title); + if (historyItem.RemoteEpisode == null) continue; + + yield return historyItem; + } } public override void RemoveItem(String id) @@ -98,6 +130,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic protected override void Test(List failures) { failures.AddIfNotNull(TestWrite(Settings.NzbFolder, "NzbFolder")); + failures.AddIfNotNull(TestWrite(Settings.StrmFolder, "StrmFolder")); } private ValidationFailure TestWrite(String folder, String propertyName) @@ -121,5 +154,28 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic return null; } + + private void WriteStrmFile(String title, String nzbFile) + { + String folder; + + if (Settings.StrmFolder.IsNullOrWhiteSpace()) + { + folder = _configService.DownloadedEpisodesFolder; + + if (folder.IsNullOrWhiteSpace()) + { + throw new DownloadClientException("Strm Folder needs to be set for Pneumatic Downloader"); + } + } + + else + { + folder = Settings.StrmFolder; + } + + 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); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs index 29b414c26..c0a400559 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs @@ -1,7 +1,6 @@ using System; using FluentValidation; using FluentValidation.Results; -using NzbDrone.Common.Disk; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation.Paths; @@ -12,8 +11,8 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic { public PneumaticSettingsValidator() { - //Todo: Validate that the path actually exists RuleFor(c => c.NzbFolder).IsValidPath(); + RuleFor(c => c.StrmFolder).IsValidPath(); } } @@ -21,9 +20,12 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic { private static readonly PneumaticSettingsValidator Validator = new PneumaticSettingsValidator(); - [FieldDefinition(0, Label = "Nzb Folder", Type = FieldType.Path)] + [FieldDefinition(0, Label = "Nzb Folder", Type = FieldType.Path, HelpText = "This folder will need to be reachable from XBMC")] public String NzbFolder { get; set; } + [FieldDefinition(1, Label = "Strm Folder", Type = FieldType.Path, HelpText = ".strm files in this folder will be import by drone")] + public String StrmFolder { get; set; } + public ValidationResult Validate() { return Validator.Validate(this);