Fixed: Parsing of multiple languages from Newznab/Torznab indexer releases
Closes #6004
This commit is contained in:
parent
5f09f2b25f
commit
2a241294b5
File diff suppressed because it is too large
Load Diff
|
@ -9,6 +9,7 @@ using NUnit.Framework;
|
|||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
@ -135,5 +136,23 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
|||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,15 +105,20 @@ 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 languageElement in languageElements)
|
||||
{
|
||||
var languages = languageElement.Split(',',
|
||||
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
foreach (var language in languages)
|
||||
{
|
||||
var mappedLanguage = IsoLanguages.FindByName(language)?.Language ?? null;
|
||||
|
@ -123,6 +128,7 @@ namespace NzbDrone.Core.Indexers.Newznab
|
|||
results.Add(mappedLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue