View Single Post
Old 07-03-2017, 10:01 PM   #208
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
Problem with bk.setmetadataxml()

Hi everyone...I'm currently writing an edit plugin for my own use called Split2TOC. This plugin only works on imported html files and does the following:

* Splits the html file into separate xhtml files at heading boundaries
* Allows you to choose which heading style to use to split your file
* Adds the guides for cover, TOC and begin read(set to Chapter 1 or default)
* Removes any existing doc TOC
* Creates a Level 1 TOC file in the epub
* Creates a TOC CSS
* Adds the book cover
* Adds the metadata

Everything is working fine except when I try to add the epub metadata using setmetadataxml().

Here is my function that tries to set the metadata in the epub:

Spoiler:
Code:
def addOPFMetadata(bk, **meta):
   
    lang = getdefaultlocale()[0]
    if lang == None:
        lang = 'en'
    if '_' in lang:    
        lang = lang.split("_")[0]

    # add the metadata
    data =  ('  <metadata>')
    data += ('    <dc:date opf:event="creation">' + meta['date'] + '</dc:date>')
    data += ('    <dc:title>' + meta['title'].strip() + '</dc:title>\n')
    data += ('    <dc:identifier id="PrimaryID">urn:uuid:' + meta['book id'] + '</dc:identifier>\n')
    data += ('    <dc:language>' + lang + '</dc:language>\n')
    data += ('    <dc:creator opf:role="aut">' + meta['author'].strip() + '</dc:creator>\n')
    data += ('    <dc:publisher>' + meta['publisher'].strip() + '</dc:publisher>\n')
    data += ('    <dc:rights>Worldwide Copyright ©' + meta['year'] + ' ' +  meta['author'].strip() + \
                     '. All Rights Reserved.</dc:rights>\n')
    data += ('    <meta name="cover" content="cover-img" />\n')
    data += ('  </metadata>')

    bk.setmetadataxml(data)

    return(0)


And this is what I get in the epub opf metadata section after running that function:

Spoiler:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<package unique-identifier="BookId" version="2.0" xmlns="http://www.idpf.org/2007/opf">
  <metadata>
    <date event="creation">2017-07-04</date>
    <title>Test Book</title>
    <identifier id="PrimaryID">urn:uuid:c8b2a9e5-abcdef-ae9d-ef72-9d15c76a8be3</identifier>
    <language>en</language>
    <creator role="aut">John Smith</creator>
    <publisher>John Smith</publisher>
    <rights>Worldwide Copyright ©2017 John Smith. All Rights Reserved.</rights>
    <meta content="cover-img" name="cover"></meta>
  </metadata>


As you can see, the 'dc:' tag prefix/suffix is missing on all metadata items in the epub. It appears that setmetadaxml() is deliberately removing 'dc:' from my data. What am I missing or is this a known problem with setmetadataxml()? Any ideas?

Last edited by slowsmile; 07-03-2017 at 10:42 PM.
slowsmile is offline   Reply With Quote