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

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

Notices

Reply
 
Thread Tools Search this Thread
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
Old 10-08-2017, 12:15 AM   #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: 33,398
Karma: 10205094
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]
kovidgoyal is offline   Reply With Quote
Advert
Old 10-08-2017, 02:49 PM   #3
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
Quote:
Originally Posted by kovidgoyal View Post
Code:
from calibre.ebooks.metadata.opf import get_metadata
get_metadata(open('/t/p/input/index.opf'))[0]
Thank you!

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]
but this (raw string) fails:
Code:
get_metadata(open(r'd:\1.mi'))[0]
with
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
Any idea why? It's so strange, i'm sure i have used the r'strings' before for paths.. Fals seem to happen on I18n stuff (it's mistakenly thinking that _ is a call object thing instead of translation stuff).

Last edited by botmtl; 10-08-2017 at 02:52 PM.
botmtl is offline   Reply With Quote
Old 10-08-2017, 10:49 PM   #4
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: 33,398
Karma: 10205094
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.
kovidgoyal is offline   Reply With Quote
Old 10-09-2017, 02:04 PM   #5
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
Quote:
Originally Posted by kovidgoyal View Post
I doubt it is the use of a raw string.
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.
botmtl is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 12:22 AM.


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