@@ -316,11 +316,12 @@ def __init__(self, filepath: str):
316316 self .calibre_env = os .environ .copy ()
317317 self .calibre_env ["HOME" ] = "/config" # Enable plugins under /config
318318
319+ self .metadata_db = os .path .join (self .library_dir , "metadata.db" )
319320 # Split library support
320321 self .split_library = self .get_split_library ()
321322 if self .split_library :
323+ self .calibre_env ['CALIBRE_OVERRIDE_DATABASE_PATH' ] = self .metadata_db
322324 self .library_dir = self .split_library ["split_path" ]
323- self .calibre_env ['CALIBRE_OVERRIDE_DATABASE_PATH' ] = os .path .join (self .split_library ["db_path" ], "metadata.db" )
324325
325326 # Track the last added Calibre book id(s) from calibredb output
326327 self .last_added_book_id : int | None = None
@@ -554,8 +555,7 @@ def add_book_to_library(self, book_path:str, text: bool=True, format: str="text"
554555 pre_import_max_timestamp = None
555556 if self .cwa_settings .get ('auto_ingest_automerge' ) == 'overwrite' :
556557 try :
557- calibre_db_path = os .path .join (self .library_dir , 'metadata.db' )
558- with sqlite3 .connect (calibre_db_path , timeout = 30 ) as con :
558+ with sqlite3 .connect (self .metadata_db , timeout = 30 ) as con :
559559 cur = con .cursor ()
560560 pre_import_max_timestamp = cur .execute ('SELECT MAX(timestamp) FROM books' ).fetchone ()[0 ]
561561 except Exception as e :
@@ -668,8 +668,7 @@ def add_book_to_library(self, book_path:str, text: bool=True, format: str="text"
668668 # Update timestamp to last_modified for any rows changed by this import so sorting by 'new' reflects overwrites.
669669 if self .cwa_settings .get ('auto_ingest_automerge' ) == 'overwrite' :
670670 try :
671- calibre_db_path = os .path .join (self .library_dir , 'metadata.db' )
672- with sqlite3 .connect (calibre_db_path , timeout = 30 ) as con :
671+ with sqlite3 .connect (self .metadata_db , timeout = 30 ) as con :
673672 cur = con .cursor ()
674673 # pre_import_max_timestamp may be None (empty library) -> update all rows where timestamp < last_modified
675674 if pre_import_max_timestamp is None :
@@ -746,8 +745,7 @@ def fetch_metadata_if_enabled(self, book_title: str | None = None, book_id: int
746745 return
747746
748747 try :
749- calibre_db_path = os .path .join (self .library_dir , 'metadata.db' )
750- with sqlite3 .connect (calibre_db_path , timeout = 30 ) as con :
748+ with sqlite3 .connect (self .metadata_db , timeout = 30 ) as con :
751749 cur = con .cursor ()
752750 if book_id is not None :
753751 cur .execute ("SELECT id, title FROM books WHERE id = ?" , (int (book_id ),))
@@ -786,8 +784,7 @@ def trigger_auto_send_if_enabled(self, book_title: str | None = None, book_path:
786784 return
787785
788786 try :
789- calibre_db_path = os .path .join (self .library_dir , 'metadata.db' )
790- with sqlite3 .connect (calibre_db_path , timeout = 30 ) as con :
787+ with sqlite3 .connect (self .metadata_db , timeout = 30 ) as con :
791788 cur = con .cursor ()
792789 if book_id is not None :
793790 cur .execute ("SELECT id, title FROM books WHERE id = ?" , (int (book_id ),))
@@ -1100,8 +1097,7 @@ def main(filepath=None):
11001097 if nbp .last_added_book_id is not None :
11011098 target_book_id = nbp .last_added_book_id
11021099 else :
1103- calibre_db_path = os .path .join (nbp .library_dir , 'metadata.db' )
1104- with sqlite3 .connect (calibre_db_path , timeout = 30 ) as con :
1100+ with sqlite3 .connect (nbp .metadata_db , timeout = 30 ) as con :
11051101 cur = con .cursor ()
11061102 cur .execute ("SELECT id FROM books ORDER BY timestamp DESC LIMIT 1" )
11071103 res = cur .fetchone ()
0 commit comments