Skip to content

Commit 837d8c9

Browse files
Fix for issue with kobos fetching covers
1 parent ec45fc1 commit 837d8c9

2 files changed

Lines changed: 4 additions & 72 deletions

File tree

CONTRIBUTORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CONTRIBUTORS
22

33
This file is automatically generated. DO NOT EDIT MANUALLY.
4-
Generated on: 2025-09-18T17:34:26.340597Z
4+
Generated on: 2025-09-18T18:30:10.537063Z
55

66
Upstream project: https://github.com/janeczku/calibre-web
77
Fork project (Calibre-Web Automated, since 2024): https://github.com/crocodilestick/calibre-web-automated

cps/metadata_helper.py

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
# See CONTRIBUTORS for full list of authors.
77

88
import json
9+
import os
910
from typing import Optional, List, Dict
1011

11-
from cps import logger, calibre_db, db
12+
from cps import logger, calibre_db, db, constants
1213
from cps.search_metadata import cl as metadata_providers
1314
import sys
1415
sys.path.insert(1, '/app/calibre-web-automated/scripts/')
@@ -297,75 +298,6 @@ def _apply_metadata_to_book(book, metadata, calibre_db_instance) -> bool:
297298
return updated
298299

299300
except Exception as e:
300-
log.error(f"Error applying metadata to book: {e}")
301-
return False
302-
if metadata.publisher and metadata.publisher.strip():
303-
publisher = calibre_db_instance.get_publisher_by_name(metadata.publisher.strip())
304-
if not publisher:
305-
publisher = db.Publishers(name=metadata.publisher.strip())
306-
calibre_db_instance.session.add(publisher)
307-
book.publishers.clear()
308-
book.publishers.append(publisher)
309-
updated = True
310-
311-
# Update publication date if available
312-
if metadata.publishedDate and metadata.publishedDate.strip():
313-
try:
314-
from datetime import datetime
315-
pub_date = datetime.strptime(metadata.publishedDate.strip(), "%Y-%m-%d")
316-
book.pubdate = pub_date
317-
updated = True
318-
except ValueError:
319-
pass # Invalid date format
320-
321-
# Update series if available
322-
if metadata.series and metadata.series.strip():
323-
series = calibre_db_instance.get_series_by_name(metadata.series.strip())
324-
if not series:
325-
series = db.Series(name=metadata.series.strip())
326-
calibre_db_instance.session.add(series)
327-
book.series.clear()
328-
book.series.append(series)
329-
if metadata.series_index:
330-
try:
331-
book.series_index = float(metadata.series_index)
332-
except (ValueError, TypeError):
333-
book.series_index = 1.0
334-
updated = True
335-
336-
# Update tags if available
337-
if metadata.tags and len(metadata.tags) > 0:
338-
book.tags.clear()
339-
for tag_name in metadata.tags:
340-
if tag_name and tag_name.strip():
341-
tag = calibre_db_instance.get_tag_by_name(tag_name.strip())
342-
if not tag:
343-
tag = db.Tags(name=tag_name.strip())
344-
calibre_db_instance.session.add(tag)
345-
book.tags.append(tag)
346-
updated = True
347-
348-
# Update rating if available
349-
if metadata.rating and float(metadata.rating) > 0:
350-
rating = calibre_db_instance.get_rating_by_name(int(float(metadata.rating) * 2)) # Convert to 10-point scale
351-
if rating:
352-
book.ratings.clear()
353-
book.ratings.append(rating)
354-
updated = True
355-
356-
# TODO: Handle cover image download and update
357-
# This would require downloading the cover from metadata.cover URL
358-
# and saving it to the book's directory
359-
360-
if updated:
361-
calibre_db_instance.session.commit()
362-
log.info(f"Metadata successfully applied to book: {book.title}")
363-
return True
364-
else:
365-
log.debug(f"No metadata improvements found for book: {book.title}")
366-
return False
367-
368-
except Exception as e:
369-
log.error(f"Error applying metadata to book {book.id}: {e}")
301+
log.error(f"Error applying metadata to book {getattr(book, 'id', 'unknown')}: {e}")
370302
calibre_db_instance.session.rollback()
371303
return False

0 commit comments

Comments
 (0)