From 2c472d6e3ec0ec169b60c632d5ce9a9ff2ecc916 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 17 Jun 2015 19:47:03 +0200 Subject: [PATCH] Fixed: BTN will now use http/https for grabbing downloads as specified by the settings instead of by the feed. --- .../BroadcastheNetFixture.cs | 22 +++++++++++++++++++ .../Indexers/BroadcastheNet/BroadcastheNet.cs | 2 +- .../BroadcastheNet/BroadcastheNetParser.cs | 11 +++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs index d15fb3e85..d6c0c901e 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs @@ -127,5 +127,27 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests ExceptionVerification.ExpectedWarns(1); } + + [Test] + public void should_replace_https_http_as_needed() + { + var recentFeed = ReadAllText(@"Files/Indexers/BroadcastheNet/RecentFeed.json"); + + recentFeed = recentFeed.Replace("http:", "https:"); + + Mocker.GetMock() + .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.POST))) + .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); + + var releases = Subject.FetchRecent(); + + releases.Should().HaveCount(2); + releases.First().Should().BeOfType(); + + var torrentInfo = releases.First() as TorrentInfo; + + torrentInfo.DownloadUrl.Should().Be("http://broadcasthe.net/torrents.php?action=download&id=123&authkey=123&torrent_pass=123"); + torrentInfo.InfoUrl.Should().Be("http://broadcasthe.net/torrents.php?id=237457&torrentid=123"); + } } } diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs index c1cb086af..a36ce0040 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet { get { - return "BroadcasttheNet"; + return "BroadcastheNet"; } } diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs index 3ce6fa66f..8379869b8 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Text.RegularExpressions; using NzbDrone.Common.Http; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Parser.Model; @@ -9,6 +10,8 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet { public class BroadcastheNetParser : IParseIndexerResponse { + private static readonly Regex RegexProtocol = new Regex("^https?:", RegexOptions.Compiled); + public IList ParseResponse(IndexerResponse indexerResponse) { var results = new List(); @@ -41,15 +44,17 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet return results; } + var protocol = indexerResponse.HttpRequest.Url.Scheme + ":"; + foreach (var torrent in jsonResponse.Result.Torrents.Values) { var torrentInfo = new TorrentInfo(); - torrentInfo.Guid = String.Format("BTN-{0}", torrent.TorrentID); + torrentInfo.Guid = string.Format("BTN-{0}", torrent.TorrentID); torrentInfo.Title = torrent.ReleaseName; torrentInfo.Size = torrent.Size; - torrentInfo.DownloadUrl = torrent.DownloadURL; - torrentInfo.InfoUrl = String.Format("https://broadcasthe.net/torrents.php?id={0}&torrentid={1}", torrent.GroupID, torrent.TorrentID); + torrentInfo.DownloadUrl = RegexProtocol.Replace(torrent.DownloadURL, protocol); + torrentInfo.InfoUrl = string.Format("{0}//broadcasthe.net/torrents.php?id={1}&torrentid={2}", protocol, torrent.GroupID, torrent.TorrentID); //torrentInfo.CommentUrl = if (torrent.TvrageID.HasValue) {