mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
feat: Enhance series metadata handling in Calibre OPDS integration and Epub extraction
This commit is contained in:
@@ -89,6 +89,40 @@ def test_calibre_opds_feed_extracts_series_from_categories() -> None:
|
||||
assert entry.series_index == 5.0
|
||||
|
||||
|
||||
def test_calibre_opds_does_not_map_author_into_series_from_categories() -> None:
|
||||
client = CalibreOPDSClient("http://example.com/catalog")
|
||||
xml_payload = """<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<feed xmlns=\"http://www.w3.org/2005/Atom\"
|
||||
xmlns:dc=\"http://purl.org/dc/terms/\"
|
||||
xmlns:calibre=\"http://calibre.kovidgoyal.net/2009/catalog\">
|
||||
<id>catalog</id>
|
||||
<title>Example Catalog</title>
|
||||
<entry>
|
||||
<id>book-author-series-bug</id>
|
||||
<title>Sample Book</title>
|
||||
<author>
|
||||
<name>Alexandre Dumas</name>
|
||||
</author>
|
||||
<category
|
||||
scheme=\"http://calibre.kovidgoyal.net/2009/series\"
|
||||
term=\"Books: Alexandre Dumas\"
|
||||
label=\"Books: Alexandre Dumas\" />
|
||||
<link rel=\"http://opds-spec.org/acquisition\"
|
||||
href=\"books/sample.epub\"
|
||||
type=\"application/epub+zip\" />
|
||||
</entry>
|
||||
</feed>
|
||||
"""
|
||||
|
||||
feed = client._parse_feed(xml_payload, base_url="http://example.com/catalog")
|
||||
assert feed.entries
|
||||
entry = feed.entries[0]
|
||||
|
||||
assert entry.authors == ["Alexandre Dumas"]
|
||||
assert entry.series is None
|
||||
assert entry.series_index is None
|
||||
|
||||
|
||||
def test_calibre_opds_extracts_tags_and_rating_from_summary() -> None:
|
||||
client = CalibreOPDSClient("http://example.com/catalog")
|
||||
xml_payload = """<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
from ebooklib import epub
|
||||
|
||||
from abogen.text_extractor import extract_from_path
|
||||
from abogen.utils import calculate_text_length
|
||||
|
||||
@@ -25,3 +27,30 @@ def test_epub_metadata_composer_matches_artist():
|
||||
assert composer
|
||||
assert composer == artist
|
||||
assert composer != "Narrator"
|
||||
|
||||
|
||||
def test_epub_series_metadata_extracted_from_opf_meta(tmp_path):
|
||||
book = epub.EpubBook()
|
||||
book.set_identifier("id")
|
||||
book.set_title("Example Title")
|
||||
book.set_language("en")
|
||||
book.add_author("Example Author")
|
||||
|
||||
# Calibre-style series metadata
|
||||
book.add_metadata("OPF", "meta", "", {"name": "calibre:series", "content": "Example Saga"})
|
||||
book.add_metadata("OPF", "meta", "", {"name": "calibre:series_index", "content": "2"})
|
||||
|
||||
chapter = epub.EpubHtml(title="Chapter 1", file_name="chap_01.xhtml", lang="en")
|
||||
chapter.content = "<h1>Chapter 1</h1><p>Hello</p>"
|
||||
book.add_item(chapter)
|
||||
book.spine = ["nav", chapter]
|
||||
book.add_item(epub.EpubNcx())
|
||||
book.add_item(epub.EpubNav())
|
||||
|
||||
path = tmp_path / "example.epub"
|
||||
epub.write_epub(str(path), book)
|
||||
|
||||
result = extract_from_path(path)
|
||||
|
||||
assert result.metadata.get("series") == "Example Saga"
|
||||
assert result.metadata.get("series_index") == "2"
|
||||
|
||||
Reference in New Issue
Block a user