Update opf and add ISBN (#108)

This commit is contained in:
AshleyDeo 2024-07-24 09:20:27 -04:00 committed by GitHub
parent f6cf80923e
commit 05559fdfbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 74 additions and 5 deletions

View File

@ -0,0 +1,26 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Bookshelf.Providers
{
/// <inheritdoc />
public class ISBNExternalId : IExternalId
{
/// <inheritdoc />
public string ProviderName => "ISBN";
/// <inheritdoc />
public string Key => "ISBN";
/// <inheritdoc />
public ExternalIdMediaType? Type => null;
/// <inheritdoc />
public string? UrlFormatString => "https://search.worldcat.org/search?q=bn:{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Book;
}
}

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
@ -104,11 +106,7 @@ namespace Jellyfin.Plugin.Bookshelf.Providers
var book = CreateBookFromOpf();
var bookResult = new MetadataResult<Book> { Item = book, HasMetadata = true };
ReadStringInto("//dc:creator", author =>
{
var person = new PersonInfo { Name = author, Type = PersonKind.Author };
bookResult.AddPerson(person);
});
FindAuthors(bookResult);
ReadStringInto("//dc:language", language => bookResult.ResultLanguage = language);
@ -126,6 +124,7 @@ namespace Jellyfin.Plugin.Bookshelf.Providers
ReadStringInto("//dc:publisher", publisher => book.AddStudio(publisher));
ReadStringInto("//dc:identifier[@opf:scheme='ISBN']", isbn => book.SetProviderId("ISBN", isbn));
ReadStringInto("//dc:identifier[@opf:scheme='AMAZON']", amazon => book.SetProviderId("Amazon", amazon));
ReadStringInto("//dc:identifier[@opf:scheme='GOOGLE']", google => book.SetProviderId("GoogleBooks", google));
ReadStringInto("//dc:date", date =>
{
@ -222,6 +221,50 @@ namespace Jellyfin.Plugin.Bookshelf.Providers
return titleSort;
}
private void FindAuthors(MetadataResult<Book> book)
{
var resultElement = _document.SelectNodes("//dc:creator", _namespaceManager);
if (resultElement != null && resultElement.Count > 0)
{
foreach (XmlElement creator in resultElement)
{
var creatorName = creator.InnerText;
string? role = creator.GetAttribute("opf:role");
var person = new PersonInfo { Name = creatorName, Type = GetRole(role) };
book.AddPerson(person);
}
}
}
private PersonKind GetRole(string role)
{
switch (role)
{
case "arr":
return PersonKind.Arranger;
case "art":
return PersonKind.Artist;
case "aut":
case "aqt":
case "aft":
case "aui":
default:
return PersonKind.Author;
case "edt":
return PersonKind.Editor;
case "ill":
return PersonKind.Illustrator;
case "lyr":
return PersonKind.Lyricist;
case "mus":
return PersonKind.AlbumArtist;
case "oth":
return PersonKind.Unknown;
case "trl":
return PersonKind.Translator;
}
}
private void ReadStringInto(string xPath, Action<string> commitResult)
{
var resultElement = _document.SelectSingleNode(xPath, _namespaceManager);