View Single Post
Old 10-07-2017, 06:18 PM   #1
botmtl
Enthusiast
botmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel isbotmtl really knows where his or her towel is
 
botmtl's Avatar
 
Posts: 43
Karma: 70238
Join Date: Jun 2014
Device: none
OPF file to Metadata?

I can usually hack at the code until I get it, but I've been at this for a while now, ... and no luck.

I would like to load opf files and convert them to a Metadata object. Working in the calibre-debug console - so far - I have tried:
Code:
from calibre.ebooks.metadata.utils import parse_opf
from calibre.ebooks.metadata.opf import get_metadata_from_parsed
miparsed=parse_opf(r"D:\pathtomyfile\99999999.mi")
get_metadata_from_parsed(mistr)
but that fails with:
Code:
  File "site-packages\calibre\ebooks\metadata\opf.py", line 37, in get_metadata_from_parsed
  File "site-packages\calibre\ebooks\metadata\opf.py", line 27, in get_metadata2
  File "site-packages\calibre\ebooks\metadata\opf2.py", line 640, in to_book_metadata
  File "site-packages\calibre\ebooks\metadata\__init__.py", line 337, in MetaInformation
  File "site-packages\calibre\ebooks\metadata\book\base.py", line 90, in __init__
  File "site-packages\calibre\ebooks\metadata\book\base.py", line 475, in smart_update
TypeError: 'lxml.etree._Element' object is not callable
Then I tried
Code:
o=OPF(r"D:\pathtomyfile\99999999.mi")
o.to_book_metadata()
but that fails with
Code:
  File "<console>", line 1, in <module>
  File "site-packages\calibre\ebooks\metadata\opf2.py", line 640, in to_book_metadata
  File "site-packages\calibre\ebooks\metadata\__init__.py", line 337, in MetaInformation
  File "site-packages\calibre\ebooks\metadata\book\base.py", line 90, in __init__
  File "site-packages\calibre\ebooks\metadata\book\base.py", line 475, in smart_update
TypeError: 'OPF' object is not callable
Lastly I tried:
Code:
from calibre.ebooks.metadata.meta import opf_metadata
but just trying to import that method blew up in my face
Code:
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "site-packages\calibre\ebooks\metadata\meta.py", line 11, in <module>
  File "site-packages\calibre\customize\__init__.py", line 25, in <module>
  File "site-packages\calibre\customize\__init__.py", line 59, in Plugin
TypeError: 'OPF' object is not callable
And that's where I gave up. Why would an import blow up? Arg!


What am I doing wrong? Can anyone help out?
botmtl is offline   Reply With Quote