mirror of
https://github.com/jellyfin/jellyfin-plugin-bookshelf.git
synced 2024-11-26 23:20:27 +00:00
Update opf and add ISBN (#108)
This commit is contained in:
parent
f6cf80923e
commit
05559fdfbe
26
Jellyfin.Plugin.Bookshelf/Providers/ISBNExternalId.cs
Normal file
26
Jellyfin.Plugin.Bookshelf/Providers/ISBNExternalId.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user