mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
New: Choose extension for magnet links in Torrent Blackhole
Closes #2165
This commit is contained in:
parent
8594a93cf5
commit
a550186337
@ -32,7 +32,6 @@ public void Setup()
|
|||||||
_completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
|
_completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
|
||||||
_blackholeFolder = @"c:\blackhole\torrent".AsOsAgnostic();
|
_blackholeFolder = @"c:\blackhole\torrent".AsOsAgnostic();
|
||||||
_filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic();
|
_filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic();
|
||||||
_magnetFilePath = Path.ChangeExtension(_filePath, ".magnet");
|
|
||||||
|
|
||||||
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
|
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
|
||||||
|
|
||||||
@ -79,6 +78,11 @@ protected void GivenCompletedItem()
|
|||||||
.Returns(1000000);
|
.Returns(1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void GivenMagnetFilePath(string extension = ".magnet")
|
||||||
|
{
|
||||||
|
_magnetFilePath = Path.ChangeExtension(_filePath, extension);
|
||||||
|
}
|
||||||
|
|
||||||
protected override RemoteEpisode CreateRemoteEpisode()
|
protected override RemoteEpisode CreateRemoteEpisode()
|
||||||
{
|
{
|
||||||
var remoteEpisode = base.CreateRemoteEpisode();
|
var remoteEpisode = base.CreateRemoteEpisode();
|
||||||
@ -145,6 +149,7 @@ public void Download_should_download_file_if_it_doesnt_exist()
|
|||||||
[Test]
|
[Test]
|
||||||
public void Download_should_save_magnet_if_enabled()
|
public void Download_should_save_magnet_if_enabled()
|
||||||
{
|
{
|
||||||
|
GivenMagnetFilePath();
|
||||||
Subject.Definition.Settings.As<TorrentBlackholeSettings>().SaveMagnetFiles = true;
|
Subject.Definition.Settings.As<TorrentBlackholeSettings>().SaveMagnetFiles = true;
|
||||||
|
|
||||||
var remoteEpisode = CreateRemoteEpisode();
|
var remoteEpisode = CreateRemoteEpisode();
|
||||||
@ -158,9 +163,29 @@ public void Download_should_save_magnet_if_enabled()
|
|||||||
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Download_should_save_magnet_using_specified_extension()
|
||||||
|
{
|
||||||
|
var magnetFileExtension = ".url";
|
||||||
|
GivenMagnetFilePath(magnetFileExtension);
|
||||||
|
Subject.Definition.Settings.As<TorrentBlackholeSettings>().SaveMagnetFiles = true;
|
||||||
|
Subject.Definition.Settings.As<TorrentBlackholeSettings>().MagnetFileExtension = magnetFileExtension;
|
||||||
|
|
||||||
|
var remoteEpisode = CreateRemoteEpisode();
|
||||||
|
remoteEpisode.Release.DownloadUrl = null;
|
||||||
|
|
||||||
|
Subject.Download(remoteEpisode);
|
||||||
|
|
||||||
|
Mocker.GetMock<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Never());
|
||||||
|
Mocker.GetMock<IDiskProvider>().Verify(c => c.OpenWriteStream(_filePath), Times.Never());
|
||||||
|
Mocker.GetMock<IDiskProvider>().Verify(c => c.OpenWriteStream(_magnetFilePath), Times.Once());
|
||||||
|
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Download_should_not_save_magnet_if_disabled()
|
public void Download_should_not_save_magnet_if_disabled()
|
||||||
{
|
{
|
||||||
|
GivenMagnetFilePath();
|
||||||
var remoteEpisode = CreateRemoteEpisode();
|
var remoteEpisode = CreateRemoteEpisode();
|
||||||
remoteEpisode.Release.DownloadUrl = null;
|
remoteEpisode.Release.DownloadUrl = null;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string
|
|||||||
|
|
||||||
title = FileNameBuilder.CleanFileName(title);
|
title = FileNameBuilder.CleanFileName(title);
|
||||||
|
|
||||||
var filepath = Path.Combine(Settings.TorrentFolder, string.Format("{0}.magnet", title));
|
var filepath = Path.Combine(Settings.TorrentFolder, $"{title}.{Settings.MagnetFileExtension.Trim('.')}");
|
||||||
|
|
||||||
var fileContent = Encoding.UTF8.GetBytes(magnetLink);
|
var fileContent = Encoding.UTF8.GetBytes(magnetLink);
|
||||||
using (var stream = _diskProvider.OpenWriteStream(filepath))
|
using (var stream = _diskProvider.OpenWriteStream(filepath))
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using NzbDrone.Core.Annotations;
|
using NzbDrone.Core.Annotations;
|
||||||
@ -14,6 +14,7 @@ public TorrentBlackholeSettingsValidator()
|
|||||||
{
|
{
|
||||||
//Todo: Validate that the path actually exists
|
//Todo: Validate that the path actually exists
|
||||||
RuleFor(c => c.TorrentFolder).IsValidPath();
|
RuleFor(c => c.TorrentFolder).IsValidPath();
|
||||||
|
RuleFor(c => c.MagnetFileExtension).NotEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ public class TorrentBlackholeSettings : IProviderConfig
|
|||||||
{
|
{
|
||||||
public TorrentBlackholeSettings()
|
public TorrentBlackholeSettings()
|
||||||
{
|
{
|
||||||
|
MagnetFileExtension = ".magnet";
|
||||||
ReadOnly = true;
|
ReadOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,12 +36,15 @@ public TorrentBlackholeSettings()
|
|||||||
|
|
||||||
[DefaultValue(false)]
|
[DefaultValue(false)]
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
||||||
[FieldDefinition(2, Label = "Save Magnet Files", Type = FieldType.Checkbox, HelpText = "Save a .magnet file with the magnet link if no .torrent file is available (only useful if the download client supports .magnet files)")]
|
[FieldDefinition(2, Label = "Save Magnet Files", Type = FieldType.Checkbox, HelpText = "Save the magnet link if no .torrent file is available (only useful if the download client supports magnets saved to a file)")]
|
||||||
public bool SaveMagnetFiles { get; set; }
|
public bool SaveMagnetFiles { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(3, Label = "Save Magnet Files", Type = FieldType.Textbox, HelpText = "Extension to use for magnet links, defaults to '.magnet'")]
|
||||||
|
public string MagnetFileExtension { get; set; }
|
||||||
|
|
||||||
[DefaultValue(false)]
|
[DefaultValue(false)]
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
||||||
[FieldDefinition(3, Label = "Read Only", Type = FieldType.Checkbox, HelpText = "Instead of moving files this will instruct Sonarr to Copy or Hardlink (depending on settings/system configuration)")]
|
[FieldDefinition(4, Label = "Read Only", Type = FieldType.Checkbox, HelpText = "Instead of moving files this will instruct Sonarr to Copy or Hardlink (depending on settings/system configuration)")]
|
||||||
public bool ReadOnly { get; set; }
|
public bool ReadOnly { get; set; }
|
||||||
|
|
||||||
public NzbDroneValidationResult Validate()
|
public NzbDroneValidationResult Validate()
|
||||||
|
Loading…
Reference in New Issue
Block a user