Fixed: Magnet links with torrent blackhole

pull/3113/head
Mark McDowall 9 years ago
parent c00c207517
commit 6b9c4af591

@ -9,7 +9,9 @@ using NzbDrone.Common.Disk;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.TorrentBlackhole; using NzbDrone.Core.Download.Clients.TorrentBlackhole;
using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.MediaFiles.TorrentInfo;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
@ -67,6 +69,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Returns(1000000); .Returns(1000000);
} }
protected override RemoteEpisode CreateRemoteEpisode()
{
var remoteEpisode = base.CreateRemoteEpisode();
var torrentInfo = new TorrentInfo();
torrentInfo.Title = remoteEpisode.Release.Title;
torrentInfo.DownloadUrl = remoteEpisode.Release.DownloadUrl;
torrentInfo.DownloadProtocol = remoteEpisode.Release.DownloadProtocol;
torrentInfo.MagnetUrl = "magnet:?xt=urn:btih:755248817d32b00cc853e633ecdc48e4c21bff15&dn=Series.S05E10.PROPER.HDTV.x264-DEFiNE%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710";
remoteEpisode.Release = torrentInfo;
return remoteEpisode;
}
[Test] [Test]
public void completed_download_should_have_required_properties() public void completed_download_should_have_required_properties()
{ {
@ -116,6 +133,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
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_throw_if_magnet_and_torrent_url_does_not_exist()
{
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = null;
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode));
}
[Test] [Test]
public void GetItems_should_considered_locked_files_queued() public void GetItems_should_considered_locked_files_queued()
{ {

@ -52,7 +52,7 @@ namespace NzbDrone.Core.Download
string magnetUrl = null; string magnetUrl = null;
string torrentUrl = null; string torrentUrl = null;
if (remoteEpisode.Release.DownloadUrl.StartsWith("magnet:")) if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && remoteEpisode.Release.DownloadUrl.StartsWith("magnet:"))
{ {
magnetUrl = remoteEpisode.Release.DownloadUrl; magnetUrl = remoteEpisode.Release.DownloadUrl;
} }
@ -76,11 +76,16 @@ namespace NzbDrone.Core.Download
} }
catch (NotSupportedException ex) catch (NotSupportedException ex)
{ {
if (torrentUrl.IsNullOrWhiteSpace())
{
throw new ReleaseDownloadException(remoteEpisode.Release, "Magnet not supported by download client. ({0})", ex.Message);
}
_logger.Debug("Magnet not supported by download client, trying torrent. ({0})", ex.Message); _logger.Debug("Magnet not supported by download client, trying torrent. ({0})", ex.Message);
} }
} }
if (hash == null && !torrentUrl.IsNullOrWhiteSpace()) if (hash == null && torrentUrl.IsNotNullOrWhiteSpace())
{ {
hash = DownloadFromWebUrl(remoteEpisode, torrentUrl); hash = DownloadFromWebUrl(remoteEpisode, torrentUrl);
} }

Loading…
Cancel
Save