Thank you! Unfortunately, when I add that and run the script using calibre-debug, it still pulls the PDF in and doesn't throw any errors, but it doesn't fill the Genre/Setting (#genre) field.
Did I put that line in the right place? Do I need to do anything to pull in custom columns first?
from calibre.ebooks.metadata.meta import get_metadata
from calibre.ebooks.metadata.book.base import Metadata
from calibre.library import db
# Path to PDF file
pdf_path = 'E:\\CalibreClaudeProject\\testPDFExtraction\\In The Ruins.pdf'
# Get metadata from PDF
mi = Metadata(get_metadata(open(pdf_path, 'rb'), stream_type='pdf'))
# Add custom metadata if needed
mi.title = 'Custom Title'
mi.authors = ['Author Name']
mi.publisher = 'Some Publisher'
mi.tags = ['myTag', 'myTag2']
mi.set('#genre', 'whatever')
# Open connection to Calibre library
db = db('F:\\CalibreLibrary').new_api
# Add PDF file to Calibre
db.add_books([(mi, {'PDF': pdf_path})])
print('PDF added to Calibre!')
|