From 6b9c4af5916e0546498c3989567e95355b544277 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 2 Nov 2015 22:21:27 -0800 Subject: [PATCH] Fixed: Magnet links with torrent blackhole --- .../Blackhole/TorrentBlackholeFixture.cs | 26 +++++++++++++++++++ .../Download/TorrentClientBase.cs | 11 +++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs index e37562f13..9356a8e39 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs @@ -9,7 +9,9 @@ using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.TorrentBlackhole; +using NzbDrone.Core.Exceptions; using NzbDrone.Core.MediaFiles.TorrentInfo; +using NzbDrone.Core.Parser.Model; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole @@ -67,6 +69,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole .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] public void completed_download_should_have_required_properties() { @@ -116,6 +133,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), It.IsAny()), 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(() => Subject.Download(remoteEpisode)); + } + [Test] public void GetItems_should_considered_locked_files_queued() { diff --git a/src/NzbDrone.Core/Download/TorrentClientBase.cs b/src/NzbDrone.Core/Download/TorrentClientBase.cs index 1f810b38f..dd2e93b52 100644 --- a/src/NzbDrone.Core/Download/TorrentClientBase.cs +++ b/src/NzbDrone.Core/Download/TorrentClientBase.cs @@ -51,8 +51,8 @@ namespace NzbDrone.Core.Download string magnetUrl = null; string torrentUrl = null; - - if (remoteEpisode.Release.DownloadUrl.StartsWith("magnet:")) + + if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && remoteEpisode.Release.DownloadUrl.StartsWith("magnet:")) { magnetUrl = remoteEpisode.Release.DownloadUrl; } @@ -76,11 +76,16 @@ namespace NzbDrone.Core.Download } 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); } } - if (hash == null && !torrentUrl.IsNullOrWhiteSpace()) + if (hash == null && torrentUrl.IsNotNullOrWhiteSpace()) { hash = DownloadFromWebUrl(remoteEpisode, torrentUrl); }