fix: return the publisher an EPUB declares

The lookup discarded its own result and fell off the end of the function, so
no EPUB ever contributed a publisher.
This commit is contained in:
2026-08-16 00:01:02 -04:00
parent ff75f2c758
commit 2e0d556c33
2 changed files with 19 additions and 1 deletions
@@ -571,7 +571,7 @@ class EpubExtractor(FileExtractor):
@classmethod @classmethod
def _extract_publisher(cls, epub: epub.EpubBook) -> str | None: def _extract_publisher(cls, epub: epub.EpubBook) -> str | None:
try: try:
epub.get_metadata("DC", "publisher")[0][0] return epub.get_metadata("DC", "publisher")[0][0]
except Exception: except Exception:
return None return None
@@ -1,4 +1,5 @@
import pytest import pytest
from ebooklib import epub
from pathlib import Path from pathlib import Path
from datetime import date from datetime import date
from chitai.services.metadata_extractor import ( from chitai.services.metadata_extractor import (
@@ -172,3 +173,20 @@ class TestEditionFromFiles:
assert metadata["title"] == "The Project Gutenberg eBook #33283: Calculus Made Easy" assert metadata["title"] == "The Project Gutenberg eBook #33283: Calculus Made Easy"
assert metadata["edition"] == 2 assert metadata["edition"] == 2
class TestEpubPublisher:
"""The publisher was looked up and then dropped on the floor."""
def test_a_declared_publisher_is_returned(self) -> None:
"""
The lookup discarded its own result and fell off the end of the function, so
every EPUB reported no publisher no matter what it said.
"""
book = epub.EpubBook()
book.add_metadata("DC", "publisher", "No Starch Press")
assert EpubExtractor._extract_publisher(book) == "No Starch Press"
def test_no_publisher_is_none(self) -> None:
assert EpubExtractor._extract_publisher(epub.EpubBook()) is None