10-28-2015, 09:42 AM | #1 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
|
Accessing the author of a KF8 book
Hi,
I'm trying to retrieve the author from an instance of Code:
from calibre.ebooks.mobi.reader.mobi6 import MobiReader Code:
book.book_header.title could someone point me in the right direction? with thanks |
10-28-2015, 09:44 AM | #2 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
metadata/meta.py
|
10-28-2015, 10:03 AM | #3 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
|
thanks!
|
10-28-2015, 12:20 PM | #4 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
|
hi, me again :P
looking at metadata/meta.py, the code calls: get_file_type_metadata() from calibre.customize.ui calibre/customize/ui.py contains a lot of plugin stuff, so presumably it works its way through the plugin system for each file type. in the case of kf8, i assume it ends up in the get_metadata() function of `calibre/ebooks/metadata/mobi.py` this function's job is to place all the meta information in MetaInformation object called mi, see below: Code:
if mh.exth is not None: if mh.exth.mi is not None: mi = mh.exth.mi else: size = 1024**3 if hasattr(stream, 'seek') and hasattr(stream, 'tell'): pos = stream.tell() stream.seek(0, 2) size = stream.tell() stream.seek(pos) if size < 4*1024*1024: with TemporaryDirectory('_mobi_meta_reader') as tdir: with CurrentDir(tdir): mr = MobiReader(stream, log) parse_cache = {} mr.extract_content(tdir, parse_cache) if mr.embedded_mi is not None: mi = mr.embedded_mi Code:
self.check_for_drm() with thanks |
10-28-2015, 12:58 PM | #5 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Just do
get_metadata(open(filename, 'rb'), stream_type='mobi') That will work exactly like reading metadata in all of calibre. |
10-28-2015, 01:01 PM | #6 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
|
yup, i get that. i'm just trying to understand the internals.
but my question was whether i'm understanding the code correctly, and whether it's possible to read the author when the book has DRM. with thanks |
10-28-2015, 01:05 PM | #7 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you want to answer that question, get hold of a book with DRM and add it to calibre or use the ebook-metadata command line tool and see if calibre reads metadata. As far as I recall metadata in MOBI files is not DRMed.
|
10-28-2015, 02:07 PM | #8 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
|
hmm, yes, you're right. it is still able to read the author, etc. when the book has DRM... though i have no idea where calibre does this :P
i did find a way of getting the author though, the fetchEXTHFields() function of the moby.py MetadataReader doesn't read the author, but i can modify it so it does: Code:
def fetchEXTHFields(self): stream = self.stream record0 = self.record0 # 20:24 = mobiHeaderLength, 16=PDBHeader size exth_off = unpack('>I', record0[20:24])[0] + 16 + record0.start image_base, = unpack('>I', record0[108:112]) # Fetch EXTH block exth = self.exth = StreamSlicer(stream, exth_off, record0.stop) nitems, = unpack('>I', exth[8:12]) pos = 12 # Store any EXTH fields not specifiable in GUI for i in xrange(nitems): id, size = unpack('>II', exth[pos:pos + 8]) content = exth[pos + 8: pos + size] pos += size self.original_exth_records[id] = content if id == 100: # added this print(content) # content is the author |
10-29-2015, 10:20 AM | #9 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
|
OK! i just thought i'd fill you in, i've got it all to work!
it turns out i'd failed to include the EXTHHeader class definition in my project (i've been separating some of this code from the rest of calibre, so i don't have a 60+ meg dependency of course, this was just being caught and reported as an "Invalid EXTH header". once i got this included properly, and stripped out the dependencies, my project can read all the metadata, extract covers, etc. so it all works! thanks for your help |
Tags |
kf8 ebook |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Anyone know what these tags will do in a KF8 book | user743 | Kindle Formats | 3 | 04-30-2014 10:44 AM |
Can't sideload a KF8 book without being flagged as Personal Doc | Julius Caesar | Amazon Kindle | 10 | 09-24-2013 09:29 PM |
Aura HD Accessing Book Information | Gilgamesh | Kobo Reader | 3 | 08-09-2013 01:36 AM |
Content KF8 only or combined KF8/Mobi | JSWolf | Amazon Kindle | 9 | 06-03-2012 09:11 PM |
epub3 and kf8: What happened to the "book" in e-book? | Nathanael | General Discussions | 19 | 12-22-2011 12:06 AM |