mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Fixing ebook paths during cover extraction. Testing cover extraction.
This commit is contained in:
parent
aa5eedc7d6
commit
1e0725c216
2 changed files with 14 additions and 3 deletions
|
|
@ -183,7 +183,7 @@ class EBook(ModelHelper, Base):
|
|||
cover_path.write_bytes(cover_bytes)
|
||||
return cover_path
|
||||
|
||||
logger.warning(f'Unable to generate cover for {self.ebook_path}')
|
||||
logger.warning(f'Unable to generate ebook cover for {self.file_group.primary_path}')
|
||||
|
||||
@property
|
||||
def cover_file(self) -> Optional[dict]:
|
||||
|
|
@ -236,8 +236,9 @@ def _model_ebook(ebook: EBook) -> EBook:
|
|||
else:
|
||||
# Extract cover because there is no cover file.
|
||||
cover_path = ebook.generate_cover()
|
||||
ebook.file_group.append_files(cover_path)
|
||||
ebook.file_group.data['cover_path'] = str(cover_path)
|
||||
if cover_path:
|
||||
ebook.file_group.append_files(cover_path)
|
||||
ebook.file_group.data['cover_path'] = str(cover_path)
|
||||
|
||||
if not ebook.file_group.title:
|
||||
# Book was not indexed above (probably a MOBI), use the file data.
|
||||
|
|
|
|||
|
|
@ -66,6 +66,16 @@ async def test_discover_local_cover(test_session, test_directory, example_epub,
|
|||
assert ebook.cover_path.read_bytes() == cover_path.read_bytes()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_extract_cover(test_session, test_directory, example_epub):
|
||||
"""First image is extracted from the Ebook and used as the cover."""
|
||||
await refresh_files()
|
||||
|
||||
ebook: EBook = test_session.query(EBook).one()
|
||||
# The WROLPi logo is the first image in the example epub.
|
||||
assert ebook.cover_path and ebook.cover_path.stat().st_size == 297099
|
||||
|
||||
|
||||
def test_search(test_session, test_client, example_epub):
|
||||
"""Ebooks are handled in File search results."""
|
||||
request, response = test_client.post('/api/files/refresh')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue