Fixed: Pneumatic now has a watch folder (for importing strm files)

pull/6/head
Mark McDowall 10 years ago
parent e67136ae64
commit 57448fd29a

@ -49,15 +49,14 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
title = FileNameBuilder.CleanFileName(title); title = FileNameBuilder.CleanFileName(title);
//Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) //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); _logger.Debug("Downloading NZB from: {0} to: {1}", url, nzbFile);
_httpProvider.DownloadFile(url, filename); _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); WriteStrmFile(title, nzbFile);
_diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents);
return null; return null;
} }
@ -72,7 +71,40 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
public override IEnumerable<DownloadClientItem> GetItems() public override IEnumerable<DownloadClientItem> 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) public override void RemoveItem(String id)
@ -98,6 +130,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
protected override void Test(List<ValidationFailure> failures) protected override void Test(List<ValidationFailure> failures)
{ {
failures.AddIfNotNull(TestWrite(Settings.NzbFolder, "NzbFolder")); failures.AddIfNotNull(TestWrite(Settings.NzbFolder, "NzbFolder"));
failures.AddIfNotNull(TestWrite(Settings.StrmFolder, "StrmFolder"));
} }
private ValidationFailure TestWrite(String folder, String propertyName) private ValidationFailure TestWrite(String folder, String propertyName)
@ -121,5 +154,28 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
return null; 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);
}
} }
} }

@ -1,7 +1,6 @@
using System; using System;
using FluentValidation; using FluentValidation;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation.Paths; using NzbDrone.Core.Validation.Paths;
@ -12,8 +11,8 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
{ {
public PneumaticSettingsValidator() public PneumaticSettingsValidator()
{ {
//Todo: Validate that the path actually exists
RuleFor(c => c.NzbFolder).IsValidPath(); 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(); 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; } 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() public ValidationResult Validate()
{ {
return Validator.Validate(this); return Validator.Validate(this);

Loading…
Cancel
Save