mirror of
https://github.com/Readarr/Readarr
synced 2026-01-08 00:22:42 +01:00
parent
7c662d4628
commit
665d87b8d7
2 changed files with 38 additions and 10 deletions
31
src/NzbDrone.Core.Test/MediaFiles/EbookTagServiceFixture.cs
Normal file
31
src/NzbDrone.Core.Test/MediaFiles/EbookTagServiceFixture.cs
Normal file
|
|
@ -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 @@ private ParsedTrackInfo ReadPdf(string file)
|
|||
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…
Reference in a new issue