Fixed: Prefer 13 character ISBN from epub metadata

Fixes #1210
book-monitor-toggle
ta264 3 years ago
parent 7c662d4628
commit 665d87b8d7

@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using VersOne.Epub.Schema;
namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
{
[TestFixture]
public class EbookTagServiceFixture : CoreTest<EBookTagService>
{
[Test]
public void should_prefer_isbn13()
{
var ids = Builder<EpubMetadataIdentifier>
.CreateListOfSize(2)
.TheFirst(1)
.With(x => x.Identifier = "4087738574")
.TheNext(1)
.With(x => x.Identifier = "9781455546176")
.Build()
.ToList();
Subject.GetIsbn(ids).Should().Be("9781455546176");
}
}
}

@ -377,18 +377,15 @@ namespace NzbDrone.Core.MediaFiles
return result;
}
private string GetIsbn(IEnumerable<EpubMetadataIdentifier> ids)
public string GetIsbn(IEnumerable<EpubMetadataIdentifier> ids)
{
foreach (var id in ids)
{
var isbn = StripIsbn(id?.Identifier);
if (isbn != null)
{
return isbn;
}
}
var candidates = ids.Select(x => StripIsbn(x?.Identifier))
.Where(x => x != null)
.OrderByDescending(x => x.Length);
return null;
return candidates.FirstOrDefault(x => x.StartsWith("978"))
?? candidates.FirstOrDefault(x => x.StartsWith("979"))
?? candidates.FirstOrDefault();
}
private string GetIsbnChars(string input)

Loading…
Cancel
Save