10-07-2017, 06:18 PM | #1 |
Enthusiast
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) 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 Code:
o=OPF(r"D:\pathtomyfile\99999999.mi") o.to_book_metadata() 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 Code:
from calibre.ebooks.metadata.meta import opf_metadata 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 What am I doing wrong? Can anyone help out? |
10-08-2017, 12:15 AM | #2 |
creator of calibre
Posts: 43,749
Karma: 22446736
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
from calibre.ebooks.metadata.opf import get_metadata get_metadata(open('/t/p/input/index.opf'))[0] |
Advert | |
|
10-08-2017, 02:49 PM | #3 | |
Enthusiast
Posts: 43
Karma: 70238
Join Date: Jun 2014
Device: none
|
Quote:
I finally found where everything goes wrong ... but I have no idea why. Running this works fine: Code:
get_metadata(open('d:\\1.mi'))[0] Code:
get_metadata(open(r'd:\1.mi'))[0] Code:
File "<console>", line 1, in <module> File "site-packages\calibre\ebooks\metadata\opf.py", line 44, in get_metadata 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: 'list' object is not callable Last edited by botmtl; 10-08-2017 at 02:52 PM. |
|
10-08-2017, 10:49 PM | #4 |
creator of calibre
Posts: 43,749
Karma: 22446736
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I doubt it is the use of a raw string that is causing it, it's likely something else that is different somewhere. Try creating a minimal script to run with calibre-debug that reporduces it, that might help narrow it down.
|
10-09-2017, 02:04 PM | #5 |
Enthusiast
Posts: 43
Karma: 70238
Join Date: Jun 2014
Device: none
|
I made quite a few tests, the results being more baffling every time I tried something new until I thought of trying the code in a new terminal.
I haven't been able to reproduce any of the weird behavior in the new terminal and I (stupidly) closed the original terminal I was on so I will never know exactly what was wrong. My best guess is that the codepage value my terminal was on was a very weird value, probably due to running vcpkg (which changes the cp value). Mind you this is just a guess. Thank you for your help pointing me in the right direction. |
Advert | |
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Reading Metadata from OPF file in Zip Archive | DMTaylor | Library Management | 6 | 01-02-2017 09:31 AM |
No metadata.opf file. Why? | chaot | Library Management | 6 | 06-30-2015 05:48 AM |
How to delete/suppress Calibre-specific metadata in .opf file? | Doitsu | Calibre | 1 | 10-30-2012 06:31 AM |
TWO OPF files or something like Media Queries in the OPF file for KF8 and MOBI? | DHahn | Kindle Formats | 3 | 04-17-2012 04:06 AM |
Manually trimming the metadata.opf and toc.ncx file | ProDigit | ePub | 22 | 04-16-2012 10:01 AM |