From 05559fdfbe1e0ad03757fc234a3fa9068869cb77 Mon Sep 17 00:00:00 2001
From: AshleyDeo <35739765+AshleyDeo@users.noreply.github.com>
Date: Wed, 24 Jul 2024 09:20:27 -0400
Subject: [PATCH] Update opf and add ISBN (#108)
---
.../Providers/ISBNExternalId.cs | 26 +++++++++
.../Providers/OpfReader.cs | 53 +++++++++++++++++--
2 files changed, 74 insertions(+), 5 deletions(-)
create mode 100644 Jellyfin.Plugin.Bookshelf/Providers/ISBNExternalId.cs
diff --git a/Jellyfin.Plugin.Bookshelf/Providers/ISBNExternalId.cs b/Jellyfin.Plugin.Bookshelf/Providers/ISBNExternalId.cs
new file mode 100644
index 0000000..3ea08d9
--- /dev/null
+++ b/Jellyfin.Plugin.Bookshelf/Providers/ISBNExternalId.cs
@@ -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
+{
+ ///
+ public class ISBNExternalId : IExternalId
+ {
+ ///
+ public string ProviderName => "ISBN";
+
+ ///
+ public string Key => "ISBN";
+
+ ///
+ public ExternalIdMediaType? Type => null;
+
+ ///
+ public string? UrlFormatString => "https://search.worldcat.org/search?q=bn:{0}";
+
+ ///
+ public bool Supports(IHasProviderIds item) => item is Book;
+ }
+}
diff --git a/Jellyfin.Plugin.Bookshelf/Providers/OpfReader.cs b/Jellyfin.Plugin.Bookshelf/Providers/OpfReader.cs
index 3768242..a7b6dff 100644
--- a/Jellyfin.Plugin.Bookshelf/Providers/OpfReader.cs
+++ b/Jellyfin.Plugin.Bookshelf/Providers/OpfReader.cs
@@ -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 { 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)
+ {
+ 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 commitResult)
{
var resultElement = _document.SelectSingleNode(xPath, _namespaceManager);