Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 10-28-2015, 09:42 AM   #1
lisabeeren
Junior Member
lisabeeren began at the beginning.
 
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
but i'm having difficulty finding it. i can get the title from the:

Code:
book.book_header.title
but the author seems less straight forward.

could someone point me in the right direction?

with thanks
lisabeeren is offline   Reply With Quote
Old 10-28-2015, 09:44 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: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
metadata/meta.py
kovidgoyal is offline   Reply With Quote
Old 10-28-2015, 10:03 AM   #3
lisabeeren
Junior Member
lisabeeren began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Oct 2015
Device: Kindle
thanks!
lisabeeren is offline   Reply With Quote
Old 10-28-2015, 12:20 PM   #4
lisabeeren
Junior Member
lisabeeren began at the beginning.
 
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
none of the books i have satisfy the first if-statement, so they fall through to the else. this creates a MobileReader object, and calls extract_content() on that. now the very first (or second) thing that extract_content() calls is:

Code:
self.check_for_drm()
which throws an exception in the case of DRM. this being the case, does that mean that many books (at least all the ones i have), you cannot access the author without first removing the DRM?

with thanks
lisabeeren is offline   Reply With Quote
Old 10-28-2015, 12:58 PM   #5
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,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.
kovidgoyal is offline   Reply With Quote
Old 10-28-2015, 01:01 PM   #6
lisabeeren
Junior Member
lisabeeren began at the beginning.
 
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
lisabeeren is offline   Reply With Quote
Old 10-28-2015, 01:05 PM   #7
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,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.
kovidgoyal is offline   Reply With Quote
Old 10-28-2015, 02:07 PM   #8
lisabeeren
Junior Member
lisabeeren began at the beginning.
 
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
thanks for your help!
lisabeeren is offline   Reply With Quote
Old 10-29-2015, 10:20 AM   #9
lisabeeren
Junior Member
lisabeeren began at the beginning.
 
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
lisabeeren is offline   Reply With Quote
Reply

Tags
kf8 ebook


Forum Jump

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


All times are GMT -4. The time now is 12:17 PM.


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