View Single Post
Old 09-02-2023, 10:50 PM   #1
dragonscythe
Junior Member
dragonscythe began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Sep 2023
Device: PC
Assigning custom column metadata

Hi! I have been reading through the documentation and searching these threads, but I'm still a bit stuck. Please help

I've got this so far (this is working):

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']

# 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!')


What I want to do is learn how to assign custom fields. I have a Genre/Setting column with the lookup/search name #genre.

I'm sure this is simple, but I've hit a wall in this and will be incredibly thankful for any help!
dragonscythe is offline   Reply With Quote