mirror of https://github.com/Radarr/Radarr
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
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,7 @@ using NUnit.Framework;
|
|||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
||||
|
@ -79,5 +80,23 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
|||
|
||||
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 @@ namespace NzbDrone.Core.Indexers.Newznab
|
|||
|
||||
protected override List<Language> GetLanguages(XElement item)
|
||||
{
|
||||
var languages = TryGetMultipleNewznabAttributes(item, "language");
|
||||
var languageElements = TryGetMultipleNewznabAttributes(item, "language");
|
||||
var results = new List<Language>();
|
||||
|
||||
// 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