From 04e3ed0ffe172d567a4525dbcbea79769698fe1c Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 18 Sep 2022 15:39:09 -0500 Subject: [PATCH] Fixed: (Gazelle) Download fails if out of FL tokens Fixes #1088 --- .../Indexers/Definitions/Gazelle/Gazelle.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/Gazelle.cs b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/Gazelle.cs index a30436849..ec9f3fe3a 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/Gazelle.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/Gazelle.cs @@ -80,6 +80,30 @@ namespace NzbDrone.Core.Indexers.Gazelle _logger.Debug("Gazelle authentication succeeded."); } + public override async Task Download(Uri link) + { + var response = await base.Download(link); + + if (response.Length >= 1 + && response[0] != 'd' // simple test for torrent vs HTML content + && link.Query.Contains("usetoken=1")) + { + var html = Encoding.GetString(response); + if (html.Contains("You do not have any freeleech tokens left.") + || html.Contains("You do not have enough freeleech tokens") + || html.Contains("This torrent is too large.") + || html.Contains("You cannot use tokens here")) + { + // download again with usetoken=0 + var requestLinkNew = link.ToString().Replace("usetoken=1", "usetoken=0"); + + response = await base.Download(new Uri(requestLinkNew)); + } + } + + return response; + } + protected override bool CheckIfLoginNeeded(HttpResponse response) { if (response.HasHttpRedirect || (response.Content != null && response.Content.Contains("\"bad credentials\"")))