From 1fc79f9e9b9617e513a841413dd6de383bdc7a09 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 23 Apr 2023 18:11:43 -0500 Subject: [PATCH] New: Use languages from Torznab/Newznab attributes if given (cherry picked from commit 9c5a07f62a6e32832c10c80813cd3b98c5859989) --- .../Headphones/HeadphonesRssParser.cs | 22 +++++++++++++++++++ .../Definitions/Newznab/NewznabRssParser.cs | 22 +++++++++++++++++++ .../Definitions/Torznab/TorznabRssParser.cs | 22 +++++++++++++++++++ src/NzbDrone.Core/Indexers/RssParser.cs | 6 +++++ 4 files changed, 72 insertions(+) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs index 7768751c4..9aac83bed 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs @@ -126,6 +126,28 @@ namespace NzbDrone.Core.Indexers.Headphones return results; } + protected override List GetLanguages(XElement item) + { + var languges = TryGetMultipleNewznabAttributes(item, "language"); + var results = new List(); + + // Try to find elements for some indexers that suck at following the rules. + if (languges.Count == 0) + { + languges = item.Elements("language").Select(e => e.Value).ToList(); + } + + foreach (var language in languges) + { + if (language.IsNotNullOrWhiteSpace()) + { + results.Add(language); + } + } + + return results; + } + protected override long GetSize(XElement item) { long size; diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs index 1f4388b87..85783338b 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs @@ -154,6 +154,28 @@ namespace NzbDrone.Core.Indexers.Newznab return results; } + protected override List GetLanguages(XElement item) + { + var languges = TryGetMultipleNewznabAttributes(item, "language"); + var results = new List(); + + // Try to find elements for some indexers that suck at following the rules. + if (languges.Count == 0) + { + languges = item.Elements("language").Select(e => e.Value).ToList(); + } + + foreach (var language in languges) + { + if (language.IsNotNullOrWhiteSpace()) + { + results.Add(language); + } + } + + return results; + } + protected override long GetSize(XElement item) { long size; diff --git a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs index 953ec9f21..4630916bf 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs @@ -125,6 +125,28 @@ namespace NzbDrone.Core.Indexers.Torznab return ParseUrl(item.TryGetValue("comments")); } + protected override List GetLanguages(XElement item) + { + var languges = TryGetMultipleTorznabAttributes(item, "language"); + var results = new List(); + + // Try to find elements for some indexers that suck at following the rules. + if (languges.Count == 0) + { + languges = item.Elements("language").Select(e => e.Value).ToList(); + } + + foreach (var language in languges) + { + if (language.IsNotNullOrWhiteSpace()) + { + results.Add(language); + } + } + + return results; + } + protected override long GetSize(XElement item) { long size; diff --git a/src/NzbDrone.Core/Indexers/RssParser.cs b/src/NzbDrone.Core/Indexers/RssParser.cs index b24a92020..6994bb626 100644 --- a/src/NzbDrone.Core/Indexers/RssParser.cs +++ b/src/NzbDrone.Core/Indexers/RssParser.cs @@ -166,6 +166,7 @@ namespace NzbDrone.Core.Indexers releaseInfo.InfoUrl = GetInfoUrl(item); releaseInfo.CommentUrl = GetCommentUrl(item); releaseInfo.Categories = GetCategory(item); + releaseInfo.Languages = GetLanguages(item); try { @@ -237,6 +238,11 @@ namespace NzbDrone.Core.Indexers return ParseUrl((string)item.Element("comments")); } + protected virtual List GetLanguages(XElement item) + { + return new List(); + } + protected virtual long GetSize(XElement item) { if (UseEnclosureLength)