Skip to content

Commit

Permalink
Parse opf roles
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDeo committed Jul 24, 2024
1 parent e6aa7ae commit c0d2177
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions Jellyfin.Plugin.Bookshelf/Providers/OpfReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -221,18 +223,48 @@ private string FindMainTitle()

private void FindAuthors(MetadataResult<Book> book)
{
var resultElement = _document.SelectNodes("//dc:creator[@opf:role='aut']", _namespaceManager);
var resultElement = _document.SelectNodes("//dc:creator", _namespaceManager);
if (resultElement != null && resultElement.Count > 0)
{
foreach (XmlElement author in resultElement)
foreach (XmlElement creator in resultElement)
{
var authorName = author.InnerText;
var person = new PersonInfo { Name = authorName, Type = PersonKind.Author };
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);
Expand Down

0 comments on commit c0d2177

Please sign in to comment.