mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-20 18:02:44 +01:00
Fixed: Parsing of multiple languages from Newznab/Torznab indexer releases
(cherry picked from commit 2a241294b5eeb9e95c46e030828191da09d05e88) Closes #9159
This commit is contained in:
parent
1c4b5f2abf
commit
18f22d7ada
1927
src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_language.xml
Normal file
1927
src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_language.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@
|
|||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Indexers.Newznab;
|
using NzbDrone.Core.Indexers.Newznab;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
||||||
@ -79,5 +80,23 @@ public void should_not_use_pagesize_over_100_even_if_reported_in_caps()
|
|||||||
|
|
||||||
Subject.PageSize.Should().Be(100);
|
Subject.PageSize.Should().Be(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task should_parse_languages()
|
||||||
|
{
|
||||||
|
var recentFeed = ReadAllText(@"Files/Indexers/Newznab/newznab_language.xml");
|
||||||
|
|
||||||
|
Mocker.GetMock<IHttpClient>()
|
||||||
|
.Setup(o => o.ExecuteAsync(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
||||||
|
.Returns<HttpRequest>(r => Task.FromResult(new HttpResponse(r, new HttpHeader(), recentFeed)));
|
||||||
|
|
||||||
|
var releases = await Subject.FetchRecent();
|
||||||
|
|
||||||
|
releases.Should().HaveCount(100);
|
||||||
|
|
||||||
|
releases[0].Languages.Should().BeEquivalentTo(new[] { Language.English, Language.Japanese });
|
||||||
|
releases[1].Languages.Should().BeEquivalentTo(new[] { Language.English, Language.Spanish });
|
||||||
|
releases[2].Languages.Should().BeEquivalentTo(new[] { Language.French });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,22 +107,28 @@ protected override string GetCommentUrl(XElement item)
|
|||||||
|
|
||||||
protected override List<Language> GetLanguages(XElement item)
|
protected override List<Language> GetLanguages(XElement item)
|
||||||
{
|
{
|
||||||
var languages = TryGetMultipleNewznabAttributes(item, "language");
|
var languageElements = TryGetMultipleNewznabAttributes(item, "language");
|
||||||
var results = new List<Language>();
|
var results = new List<Language>();
|
||||||
|
|
||||||
// Try to find <language> elements for some indexers that suck at following the rules.
|
// Try to find <language> elements for some indexers that suck at following the rules.
|
||||||
if (languages.Count == 0)
|
if (languageElements.Count == 0)
|
||||||
{
|
{
|
||||||
languages = item.Elements("language").Select(e => e.Value).ToList();
|
languageElements = item.Elements("language").Select(e => e.Value).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var language in languages)
|
foreach (var languageElement in languageElements)
|
||||||
{
|
{
|
||||||
var mappedLanguage = IsoLanguages.FindByName(language)?.Language ?? null;
|
var languages = languageElement.Split(',',
|
||||||
|
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
|
|
||||||
if (mappedLanguage != null)
|
foreach (var language in languages)
|
||||||
{
|
{
|
||||||
results.Add(mappedLanguage);
|
var mappedLanguage = IsoLanguages.FindByName(language)?.Language ?? null;
|
||||||
|
|
||||||
|
if (mappedLanguage != null)
|
||||||
|
{
|
||||||
|
results.Add(mappedLanguage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user