Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 11-30-2011, 10:49 PM   #1
dinya
Member
dinya began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Aug 2011
Device: none
Add data in user_metadata dictionary

Hello all.

I'm writing plugin.
It should add to book record some data in user_metadata structure (defined in library metadata) on book adding.

Code is following:

============

import os
from calibre.customize import FileTypePlugin

class AddField(FileTypePlugin):

....name = 'Add field on start'
....description = ''
....supported_platforms = ['windows', 'osx', 'linux']
....author = ''
....version = (1, 0, 0)
....file_types = set(['pdf','djvu'])
....on_import = True
....minimum_calibre_version = (0, 7, 53)

....def run(self, path_to_ebook):
........from calibre.ebooks.metadata.meta import get_metadata, set_metadata

........file = open(path_to_ebook, 'r+b')
........ext = os.path.splitext(path_to_ebook)[-1][1:].lower()
........mi = get_metadata(file, ext)
........field_value = 'This is Field'
........print "[1] Field is:", mi.get_user_metadata("#field",False)
........field = {"#value#": field_value, 'datatype': 'text'}
........mi.set_user_metadata('#field', field)
........mi.title = "This is Title"
........set_metadata(file, mi, ext)
........mi = get_metadata(file, ext)
........print "[2] Field is:", mi.get_user_metadata("#field",False)
........return path_to_ebook

=============

In debug mode we have the following

=============
[PASS]
calibre 0.8.28
Windows-7-6.1.7600
Windows
('Windows', '7', '6.1.7600')
Python 2.7.1
Windows: ('7', '6.1.7600', '', 'Multiprocessor Free')
Starting up...
[PASS]
Started up in 6.05700016022 with 436 books
Worker Launch took: 1.30799984932
Job: 1 Read metadata (0 of 1) finished
Read metadata (0 of 1)
[1] Field is: None
[2] Field is: None

Added This is Title to db in: 1.71900010109 seconds
=============

1) "[1] Field is: None" is proper. But why the second is "None" too? How to make calibre to set field in desirable way?

2) Is it possible to add and to fill new fields in user_metadata, which not exist?
dinya is offline   Reply With Quote
Old 11-30-2011, 10:54 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,826
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre does not read custom metadata from ebook files. Instead of creating a filetype plugin create a UserInterface plugin that sets the metadata explicitly after adding the book via set_custom_metadata
kovidgoyal is online now   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify the Dictionary meta data yaodis Amazon Kindle 0 10-29-2011 05:16 AM
Help:how to add CSS additional data by converting books Nick_1964 Calibre 14 10-26-2010 09:47 AM
How do I edit/add Meta Data 4jacks Kindle Formats 4 10-07-2010 04:33 AM
Add books - Meta Data format wwaldo Calibre 2 03-17-2010 07:38 PM
Office 2003/XP Add-in: Remove Hidden Data Alexander Turcic Lounge 0 01-07-2004 05:09 AM


All times are GMT -4. The time now is 09:13 AM.


MobileRead.com is a privately owned, operated and funded community.