From d317c3dd60bdbd401fc116d2cbb7b663e754f1aa Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 30 Apr 2023 16:51:27 +0300 Subject: [PATCH] Fixed: (Headphones) Use custom download request Closes #3595 --- .../HeadphonesTests/HeadphonesFixture.cs | 7 +++--- .../Download/UsenetClientBase.cs | 6 ----- .../Indexers/Headphones/Headphones.cs | 22 +++++++++++++------ .../Headphones/HeadphonesRssParser.cs | 22 ------------------- src/NzbDrone.Core/Indexers/RssParser.cs | 6 ----- src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs | 1 - 6 files changed, 18 insertions(+), 46 deletions(-) delete mode 100644 src/NzbDrone.Core/Indexers/Headphones/HeadphonesRssParser.cs diff --git a/src/NzbDrone.Core.Test/IndexerTests/HeadphonesTests/HeadphonesFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/HeadphonesTests/HeadphonesFixture.cs index 418ad45fc..a2e4aef56 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/HeadphonesTests/HeadphonesFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/HeadphonesTests/HeadphonesFixture.cs @@ -20,10 +20,10 @@ namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests [SetUp] public void Setup() { - Subject.Definition = new IndexerDefinition() + Subject.Definition = new IndexerDefinition { Name = "Headphones VIP", - Settings = new HeadphonesSettings() + Settings = new HeadphonesSettings { Categories = new int[] { 3000 }, Username = "user", @@ -51,12 +51,11 @@ namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests releases.Should().HaveCount(16); releases.First().Should().BeOfType(); - var releaseInfo = releases.First() as ReleaseInfo; + var releaseInfo = releases.First(); releaseInfo.Title.Should().Be("Lady Gaga Born This Way 2CD FLAC 2011 WRE"); releaseInfo.DownloadProtocol.Should().Be(DownloadProtocol.Usenet); releaseInfo.DownloadUrl.Should().Be("https://indexer.codeshy.com/api?t=g&guid=123456&apikey=123456789"); - releaseInfo.BasicAuthString.Should().Be("dXNlcjpwYXNz"); releaseInfo.Indexer.Should().Be(Subject.Definition.Name); releaseInfo.PublishDate.Should().Be(DateTime.Parse("2013/06/02 08:58:54")); releaseInfo.Size.Should().Be(917347414); diff --git a/src/NzbDrone.Core/Download/UsenetClientBase.cs b/src/NzbDrone.Core/Download/UsenetClientBase.cs index 1a304900f..d078cc61f 100644 --- a/src/NzbDrone.Core/Download/UsenetClientBase.cs +++ b/src/NzbDrone.Core/Download/UsenetClientBase.cs @@ -47,12 +47,6 @@ namespace NzbDrone.Core.Download var request = indexer?.GetDownloadRequest(url) ?? new HttpRequest(url); request.RateLimitKey = remoteAlbum?.Release?.IndexerId.ToString(); - // TODO: Look into moving download request handling to indexer - if (remoteAlbum.Release.BasicAuthString.IsNotNullOrWhiteSpace()) - { - request.Headers.Set("Authorization", "Basic " + remoteAlbum.Release.BasicAuthString); - } - nzbData = _httpClient.Get(request).ResponseData; _logger.Debug("Downloaded nzb for release '{0}' finished ({1} bytes from {2})", remoteAlbum.Release.Title, nzbData.Length, url); diff --git a/src/NzbDrone.Core/Indexers/Headphones/Headphones.cs b/src/NzbDrone.Core/Indexers/Headphones/Headphones.cs index eb2c1fc63..0e70cef3d 100644 --- a/src/NzbDrone.Core/Indexers/Headphones/Headphones.cs +++ b/src/NzbDrone.Core/Indexers/Headphones/Headphones.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Parser; namespace NzbDrone.Core.Indexers.Headphones @@ -20,6 +21,12 @@ namespace NzbDrone.Core.Indexers.Headphones public override int PageSize => _capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize; + public Headphones(IHeadphonesCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger) + : base(httpClient, indexerStatusService, configService, parsingService, logger) + { + _capabilitiesProvider = capabilitiesProvider; + } + public override IIndexerRequestGenerator GetRequestGenerator() { return new HeadphonesRequestGenerator(_capabilitiesProvider) @@ -31,16 +38,17 @@ namespace NzbDrone.Core.Indexers.Headphones public override IParseIndexerResponse GetParser() { - return new HeadphonesRssParser - { - Settings = Settings - }; + return new NewznabRssParser(); } - public Headphones(IHeadphonesCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger) - : base(httpClient, indexerStatusService, configService, parsingService, logger) + public override HttpRequest GetDownloadRequest(string link) { - _capabilitiesProvider = capabilitiesProvider; + var request = new HttpRequest(link) + { + Credentials = new BasicNetworkCredential(Settings.Username, Settings.Password) + }; + + return request; } protected override void Test(List failures) diff --git a/src/NzbDrone.Core/Indexers/Headphones/HeadphonesRssParser.cs b/src/NzbDrone.Core/Indexers/Headphones/HeadphonesRssParser.cs deleted file mode 100644 index 9ee7cff5d..000000000 --- a/src/NzbDrone.Core/Indexers/Headphones/HeadphonesRssParser.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Text; -using NzbDrone.Core.Indexers.Newznab; - -namespace NzbDrone.Core.Indexers.Headphones -{ - public class HeadphonesRssParser : NewznabRssParser - { - public HeadphonesSettings Settings { get; set; } - - public HeadphonesRssParser() - { - PreferredEnclosureMimeTypes = UsenetEnclosureMimeTypes; - UseEnclosureUrl = true; - } - - protected override string GetBasicAuth() - { - return Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{Settings.Username}:{Settings.Password}")); - } - } -} diff --git a/src/NzbDrone.Core/Indexers/RssParser.cs b/src/NzbDrone.Core/Indexers/RssParser.cs index fd50c7de5..1d7f1794e 100644 --- a/src/NzbDrone.Core/Indexers/RssParser.cs +++ b/src/NzbDrone.Core/Indexers/RssParser.cs @@ -156,7 +156,6 @@ namespace NzbDrone.Core.Indexers releaseInfo.Title = GetTitle(item); releaseInfo.PublishDate = GetPublishDate(item); releaseInfo.DownloadUrl = GetDownloadUrl(item); - releaseInfo.BasicAuthString = GetBasicAuth(); releaseInfo.InfoUrl = GetInfoUrl(item); releaseInfo.CommentUrl = GetCommentUrl(item); @@ -199,11 +198,6 @@ namespace NzbDrone.Core.Indexers return XElementExtensions.ParseDate(dateString); } - protected virtual string GetBasicAuth() - { - return null; - } - protected virtual string GetDownloadUrl(XElement item) { if (UseEnclosureUrl) diff --git a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs index a996ba0ee..1d56b893e 100644 --- a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs @@ -10,7 +10,6 @@ namespace NzbDrone.Core.Parser.Model public string Title { get; set; } public long Size { get; set; } public string DownloadUrl { get; set; } - public string BasicAuthString { get; set; } public string InfoUrl { get; set; } public string CommentUrl { get; set; } public int IndexerId { get; set; }