From 7dc64c595cfcf97965eb01ca1f414b58958c4b49 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 20 Jun 2024 00:16:53 +0300 Subject: [PATCH] Fixed: Exclude invalid releases from Newznab and Torznab parsers (cherry picked from commit fb060730c7d52cd342484dc68595698a9430df7b) --- .../Indexers/Newznab/NewznabRssParser.cs | 9 +++-- src/NzbDrone.Core/Indexers/RssParser.cs | 38 +++++++++---------- .../Indexers/Torznab/TorznabRssParser.cs | 9 +++-- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index 90dd766a9..56806f3f8 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -72,16 +72,17 @@ namespace NzbDrone.Core.Indexers.Newznab protected override bool PostProcess(IndexerResponse indexerResponse, List items, List releases) { var enclosureTypes = items.SelectMany(GetEnclosures).Select(v => v.Type).Distinct().ToArray(); + if (enclosureTypes.Any() && enclosureTypes.Intersect(PreferredEnclosureMimeTypes).Empty()) { if (enclosureTypes.Intersect(TorrentEnclosureMimeTypes).Any()) { _logger.Warn("{0} does not contain {1}, found {2}, did you intend to add a Torznab indexer?", indexerResponse.Request.Url, NzbEnclosureMimeType, enclosureTypes[0]); + + return false; } - else - { - _logger.Warn("{1} does not contain {1}, found {2}.", indexerResponse.Request.Url, NzbEnclosureMimeType, enclosureTypes[0]); - } + + _logger.Warn("{0} does not contain {1}, found {2}.", indexerResponse.Request.Url, NzbEnclosureMimeType, enclosureTypes[0]); } return true; diff --git a/src/NzbDrone.Core/Indexers/RssParser.cs b/src/NzbDrone.Core/Indexers/RssParser.cs index 090982be9..239cebc4d 100644 --- a/src/NzbDrone.Core/Indexers/RssParser.cs +++ b/src/NzbDrone.Core/Indexers/RssParser.cs @@ -264,26 +264,26 @@ namespace NzbDrone.Core.Indexers protected virtual RssEnclosure[] GetEnclosures(XElement item) { var enclosures = item.Elements("enclosure") - .Select(v => - { - try - { - return new RssEnclosure - { - Url = v.Attribute("url")?.Value, - Type = v.Attribute("type")?.Value, - Length = v.Attribute("length")?.Value?.ParseInt64() ?? 0 - }; - } - catch (Exception e) - { - _logger.Warn(e, "Failed to get enclosure for: {0}", item.Title()); - } + .Select(v => + { + try + { + return new RssEnclosure + { + Url = v.Attribute("url")?.Value, + Type = v.Attribute("type")?.Value, + Length = v.Attribute("length")?.Value?.ParseInt64() ?? 0 + }; + } + catch (Exception ex) + { + _logger.Warn(ex, "Failed to get enclosure for: {0}", item.Title()); + } - return null; - }) - .Where(v => v != null) - .ToArray(); + return null; + }) + .Where(v => v != null) + .ToArray(); return enclosures; } diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs index edaa44506..556fa76ae 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs @@ -76,16 +76,17 @@ namespace NzbDrone.Core.Indexers.Torznab protected override bool PostProcess(IndexerResponse indexerResponse, List items, List releases) { var enclosureTypes = items.SelectMany(GetEnclosures).Select(v => v.Type).Distinct().ToArray(); + if (enclosureTypes.Any() && enclosureTypes.Intersect(PreferredEnclosureMimeTypes).Empty()) { if (enclosureTypes.Intersect(UsenetEnclosureMimeTypes).Any()) { _logger.Warn("{0} does not contain {1}, found {2}, did you intend to add a Newznab indexer?", indexerResponse.Request.Url, TorrentEnclosureMimeType, enclosureTypes[0]); + + return false; } - else - { - _logger.Warn("{1} does not contain {1}, found {2}.", indexerResponse.Request.Url, TorrentEnclosureMimeType, enclosureTypes[0]); - } + + _logger.Warn("{0} does not contain {1}, found {2}.", indexerResponse.Request.Url, TorrentEnclosureMimeType, enclosureTypes[0]); } return true;