Quote:
Originally Posted by DiapDealer
This plugin prints the xml snippet that bk.getmetadata() returns, prints the soup made from that snippet, adds the dc:language entry if not present, serializes the soup and prints the results, then ultimately writes the xml snippet back with bk.setmetadata().
|
Thats the expected result, but it adds a second (third foruth and so on) dc_language element all the time

From the documentation find() returns None if it finds nothing and in that case if adds it and sets the language ex_us.
So whats wrong with if not dc_language: ? If should not insert something, just changing.
Before:
Code:
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:7967fadc-d511-42ee-aad1-a472e662546a</dc:identifier>
<dc:language>de</dc:language>
<dc:title>[Title here]</dc:title>
</metadata>
After
Code:
<?xml version="1.0" encoding="utf-8" ?>
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:7967fadc-d511-42ee-aad1-a472e662546a</dc:identifier>
<dc:language>de</dc:language>
<dc:title>[Title here]</dc:title>
<dc:language>en-US</dc:language>
</metadata>
By the way, the parser adds the xml starting declaration. At least, that doesnt mess up the content.opf file.
What my Python abilities now exceed is that if not dc_language statement does work. Debugging the code with print(): the content of the Variable is None
Vroni