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 08-01-2013, 06:41 PM   #1
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
Conversion output plugins?

I'm trying to make a conversion output plugin, but I'm not too sure where to start. I don't see any examples. I'm not looking to make a brand new plugin, at least I don't think so; I think that extending the ePub conversion output class would be fine. Basically, I want a conversion output plugin that produces the same end result that my KoboTouchExtended driver plugin does.

For a first step, I looked at calibre.ebooks.conversion.plugins.epub_output.EPUB Output and made a subclass KEPubOutput that extends EPUBOutput and does nothing but change the three variables at the top of the class
Code:
name = 'KePub Output'
author = '<me>'
file_type = 'kepub.epub'
The file_type change worked (I think?); I saw 'KEPUB.EPUB' in the list of output formats, and when I selected it the resulting file had the 'kepub.epub' extension, but the 'EPUB Output' option on the left side of the conversion window didn't change to 'KePub Output' like I was expecting.

Is there a sample of a conversion output plugin somewhere I can reference, or is there some other documentation I missed?
jgoguen is offline   Reply With Quote
Old 08-01-2013, 10:32 PM   #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: 44,526
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre is not going to work with file extensions that have dots in them, the assumption that they do not, is in too many places in the code. And generally speaking, once you allow extensions with dots, there is no robust way of knowing what the extension of a given file is, you essentially have to maintain a list of know dotted extensions and test for them every time.

Try changing the file type to .kepub instead.
kovidgoyal is offline   Reply With Quote
Advert
Old 08-03-2013, 09:15 PM   #3
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
I switched file_type to 'kepub' and made a few other tweaks and now when I select 'KEPUB' from the output format list I get the expected 'KePub Output' option. But, how do I go about adding options to that screen? Can I include a modified copy of epub_output.ui somewhere in the plugin, do I need to copy and modify calibre.gui2.convert.epub_output_ui.Ui_Form in my PluginWidget instance, or is there something even easier I'm missing?
jgoguen is offline   Reply With Quote
Old 08-04-2013, 12:07 AM   #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: 44,526
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You have to implement gui_configuration_widget(), see the base class implementation for an example. You may run into issues, as I dont think anyone has ever tested that with third party plugins, but in principle, it should work.

Just remember to not put any GUI related imports at the top of your plugin modules as the plugins are also used in ebook-convert, so they should not unecessarily incur the overhead of importing PyQt
kovidgoyal is offline   Reply With Quote
Old 08-04-2013, 09:33 PM   #5
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
I think I found one of those problems Calibre seems to find my KEPubOutput class just fine, and recognizes that it's for the 'kepub' file type, but when I actually press "OK" it raises ValueError saying there's no output format plugin for file type 'kepub'.

I put some print() statements in calibre.customize.ui (output_format_plugins() and plugins_for_output_format()), calibre.ebooks.conversion.plumber (Plumber.__init__()), calibre.utils.ipc.worker (main()), and calibre.gui2.convert.gui_conversion (gui_convert()) to try and trace the problem and I'm stumped. Here's my calibre log (including the output from all the extra print statements I added) up to the point where I say I want to convert a book (it defaults to 'EPUB' as the output format) and I select 'KEPUB' from the output format list:
Spoiler:

calibre 0.9.42 isfrozen: False is64bit: True
Linux-3.9.11-200.fc18.x86_64-x86_64-with-fedora-18-Spherical_Cow Linux ('64bit', 'ELF')
('Linux', '3.9.11-200.fc18.x86_64', '#1 SMP Mon Jul 22 21:04:50 UTC 2013')
Python 2.7.3
Linux: ('Fedora', '18', 'Spherical Cow')
Starting up...
loaded the Generic plugin

DEBUG: 0.0 No Kobo Touch, Glo or Mini appears to be connected
Started up in 2.11 seconds with 1529 books
output_format_plugin() :: <calibre_plugins.kobotouch_extended.conversion.kep ub_output.KEPubOutput object at 0x23f4490>
output_format_plugin() :: Trying plugin for kepub
output_format_plugin() :: <calibre.ebooks.conversion.plugins.epub_output.EPU BOutput object at 0x2a62dd0>
output_format_plugin() :: Trying plugin for epub
output_format_plugin() :: <calibre.ebooks.conversion.plugins.fb2_output.FB2O utput object at 0x2a62e50>
output_format_plugin() :: Trying plugin for fb2
output_format_plugin() :: <calibre.ebooks.conversion.plugins.lit_output.LITO utput object at 0x2a62ed0>
output_format_plugin() :: Trying plugin for lit
output_format_plugin() :: <calibre.ebooks.conversion.plugins.lrf_output.LRFO utput object at 0x2a62f50>
output_format_plugin() :: Trying plugin for lrf
output_format_plugin() :: <calibre.ebooks.conversion.plugins.mobi_output.MOB IOutput object at 0x2a62fd0>
output_format_plugin() :: Trying plugin for mobi
output_format_plugin() :: <calibre.ebooks.conversion.plugins.mobi_output.AZW 3Output object at 0x2a61090>
output_format_plugin() :: Trying plugin for azw3
output_format_plugin() :: <calibre.ebooks.conversion.plugins.oeb_output.OEBO utput object at 0x2a61110>
output_format_plugin() :: Trying plugin for oeb
output_format_plugin() :: <calibre.ebooks.conversion.plugins.pdb_output.PDBO utput object at 0x2a61190>
output_format_plugin() :: Trying plugin for pdb
output_format_plugin() :: <calibre.ebooks.conversion.plugins.pdf_output.PDFO utput object at 0x2a61210>
output_format_plugin() :: Trying plugin for pdf
output_format_plugin() :: <calibre.ebooks.conversion.plugins.pml_output.PMLO utput object at 0x2a61290>
output_format_plugin() :: Trying plugin for pmlz
output_format_plugin() :: <calibre.ebooks.conversion.plugins.rb_output.RBOut put object at 0x2a61310>
output_format_plugin() :: Trying plugin for rb
output_format_plugin() :: <calibre.ebooks.conversion.plugins.rtf_output.RTFO utput object at 0x2a61390>
output_format_plugin() :: Trying plugin for rtf
output_format_plugin() :: <calibre.ebooks.conversion.plugins.tcr_output.TCRO utput object at 0x2a61410>
output_format_plugin() :: Trying plugin for tcr
output_format_plugin() :: <calibre.ebooks.conversion.plugins.txt_output.TXTO utput object at 0x2a61490>
output_format_plugin() :: Trying plugin for txt
output_format_plugin() :: <calibre.ebooks.conversion.plugins.txt_output.TXTZ Output object at 0x2a61510>
output_format_plugin() :: Trying plugin for txtz
output_format_plugin() :: <calibre.ebooks.conversion.plugins.html_output.HTM LOutput object at 0x2a61590>
output_format_plugin() :: Trying plugin for zip
output_format_plugin() :: <calibre.ebooks.conversion.plugins.htmlz_output.HT MLZOutput object at 0x2a61610>
output_format_plugin() :: Trying plugin for htmlz
output_format_plugin() :: <calibre.ebooks.conversion.plugins.snb_output.SNBO utput object at 0x2a61690>
output_format_plugin() :: Trying plugin for snb
__init__() :: Output: /home/jgoguen/dummy.epub
__init__() :: Output format: epub
output_format_plugin() :: <calibre_plugins.kobotouch_extended.conversion.kep ub_output.KEPubOutput object at 0x23f4490>
output_format_plugin() :: Trying plugin for kepub
output_format_plugin() :: <calibre.ebooks.conversion.plugins.epub_output.EPU BOutput object at 0x2a62dd0>
output_format_plugin() :: Trying plugin for epub
plugin_for_output_format() :: Using plugin: <calibre.ebooks.conversion.plugins.epub_output.EPU BOutput object at 0x2a62dd0>
__init__() :: <calibre.ebooks.conversion.plugins.epub_output.EPU BOutput object at 0x2a62dd0>
__init__() :: Output: /home/jgoguen/dummy.kepub
__init__() :: Output format: kepub
output_format_plugin() :: <calibre_plugins.kobotouch_extended.conversion.kep ub_output.KEPubOutput object at 0x23f4490>
output_format_plugin() :: Trying plugin for kepub
plugin_for_output_format() :: Using plugin: <calibre_plugins.kobotouch_extended.conversion.kep ub_output.KEPubOutput object at 0x23f4490>
__init__() :: <calibre_plugins.kobotouch_extended.conversion.kep ub_output.KEPubOutput object at 0x23f4490>


Once I actually click "OK", I get this output if I set CALIBRE_PYTHON_PATH:
Spoiler:

main() :: Name: gui_convert_override
Convert book 1 of 1 (The Spirit Thief)
Module: calibre.gui2.convert.gui_conversion
Func: gui_convert_override
Failed to initialize plugin: '/home/jgoguen/.config/calibre/plugins/KePub Output.zip'
gui_convert() :: Input: /tmp/calibre_0.9.42_tmp_SXwM3z/2QEzFG.epub
gui_convert() :: Output: /tmp/calibre_0.9.42_tmp_SXwM3z/aYej4e.kepub
__init__() :: Output: /tmp/calibre_0.9.42_tmp_SXwM3z/aYej4e.kepub
__init__() :: Output format: kepub
output_format_plugin() :: <calibre.ebooks.conversion.plugins.epub_output.EPU BOutput object at 0x2b55490>
output_format_plugin() :: Trying plugin for epub
output_format_plugin() :: <calibre.ebooks.conversion.plugins.fb2_output.FB2O utput object at 0x2b55510>
output_format_plugin() :: Trying plugin for fb2
output_format_plugin() :: <calibre.ebooks.conversion.plugins.lit_output.LITO utput object at 0x2b55590>
output_format_plugin() :: Trying plugin for lit
output_format_plugin() :: <calibre.ebooks.conversion.plugins.lrf_output.LRFO utput object at 0x2b55610>
output_format_plugin() :: Trying plugin for lrf
output_format_plugin() :: <calibre.ebooks.conversion.plugins.mobi_output.MOB IOutput object at 0x2b55690>
output_format_plugin() :: Trying plugin for mobi
output_format_plugin() :: <calibre.ebooks.conversion.plugins.mobi_output.AZW 3Output object at 0x2b55710>
output_format_plugin() :: Trying plugin for azw3
output_format_plugin() :: <calibre.ebooks.conversion.plugins.oeb_output.OEBO utput object at 0x2b55790>
output_format_plugin() :: Trying plugin for oeb
output_format_plugin() :: <calibre.ebooks.conversion.plugins.pdb_output.PDBO utput object at 0x2b55810>
output_format_plugin() :: Trying plugin for pdb
output_format_plugin() :: <calibre.ebooks.conversion.plugins.pdf_output.PDFO utput object at 0x2b55890>
output_format_plugin() :: Trying plugin for pdf
output_format_plugin() :: <calibre.ebooks.conversion.plugins.pml_output.PMLO utput object at 0x2b55910>
output_format_plugin() :: Trying plugin for pmlz
output_format_plugin() :: <calibre.ebooks.conversion.plugins.rb_output.RBOut put object at 0x2b55990>
output_format_plugin() :: Trying plugin for rb
output_format_plugin() :: <calibre.ebooks.conversion.plugins.rtf_output.RTFO utput object at 0x2b55a10>
output_format_plugin() :: Trying plugin for rtf
output_format_plugin() :: <calibre.ebooks.conversion.plugins.tcr_output.TCRO utput object at 0x2b55a90>
output_format_plugin() :: Trying plugin for tcr
output_format_plugin() :: <calibre.ebooks.conversion.plugins.txt_output.TXTO utput object at 0x2b55b10>
output_format_plugin() :: Trying plugin for txt
output_format_plugin() :: <calibre.ebooks.conversion.plugins.txt_output.TXTZ Output object at 0x2b55b90>
output_format_plugin() :: Trying plugin for txtz
output_format_plugin() :: <calibre.ebooks.conversion.plugins.html_output.HTM LOutput object at 0x2b55c10>
output_format_plugin() :: Trying plugin for zip
output_format_plugin() :: <calibre.ebooks.conversion.plugins.htmlz_output.HT MLZOutput object at 0x2b55c90>
output_format_plugin() :: Trying plugin for htmlz
output_format_plugin() :: <calibre.ebooks.conversion.plugins.snb_output.SNBO utput object at 0x2b55d10>
output_format_plugin() :: Trying plugin for snb
__init__() :: None
__init__() raising ValueError :: Output: /tmp/calibre_0.9.42_tmp_SXwM3z/aYej4e.kepub
__init__() raising ValueError :: Output format: kepub
Traceback (most recent call last):
File "/usr/bin/calibre-parallel", line 20, in <module>
sys.exit(main())
File "/home/jgoguen/Copy/Code/calibre/src/calibre/utils/ipc/worker.py", line 191, in main
result = func(*args, **kwargs)
File "/home/jgoguen/Copy/Code/calibre/src/calibre/gui2/convert/gui_conversion.py", line 33, in gui_convert_override
override_input_metadata=True)
File "/home/jgoguen/Copy/Code/calibre/src/calibre/gui2/convert/gui_conversion.py", line 24, in gui_convert
override_input_metadata=override_input_metadata)
File "/home/jgoguen/Copy/Code/calibre/src/calibre/ebooks/conversion/plumber.py", line 726, in __init__
raise ValueError('No plugin to handle output format: '+output_fmt)
ValueError: No plugin to handle output format: kepub


And this if I only set CALIBRE_DEVELOP_FROM but not CALIBRE_PYTHON_PATH:
Spoiler:


Convert book 1 of 1 (The Spirit Thief)
Failed to initialize plugin: '/home/jgoguen/.config/calibre/plugins/KePub Output.zip'
Traceback (most recent call last):
File "/usr/bin/calibre-parallel", line 20, in <module>
sys.exit(main())
File "/usr/lib64/calibre/calibre/utils/ipc/worker.py", line 188, in main
result = func(*args, **kwargs)
File "/usr/lib64/calibre/calibre/gui2/convert/gui_conversion.py", line 31, in gui_convert_override
override_input_metadata=True)
File "/usr/lib64/calibre/calibre/gui2/convert/gui_conversion.py", line 22, in gui_convert
override_input_metadata=override_input_metadata)
File "/usr/lib64/calibre/calibre/ebooks/conversion/plumber.py", line 720, in __init__
raise ValueError('No plugin to handle output format: '+output_fmt)
ValueError: No plugin to handle output format: kepub


It almost looks like the workflow through calibre-parallel doesn't check third-party plugins? I'm not sure where to go from here.
jgoguen is offline   Reply With Quote
Advert
Old 08-04-2013, 10:03 PM   #6
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: 44,526
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I dont see what effect having a config widget would have on the conversion process. Was your plugin working before adding config? And you get the error when pressing OK in what? Since the gui and the worker process use the exact same code to load plugins, I find it odd that it is found in one and not the other.
kovidgoyal is offline   Reply With Quote
Old 08-05-2013, 01:48 PM   #7
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
It doesn't seem to matter if I have a configuration widget or not. I have been able to get the conversion to succeed with this code:
Code:
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai

__license__ = 'GPL v3'
__copyright__ = '2013, Joel Goguen <jgoguen@jgoguen.ca>'
__docformat__ = 'markdown en'

from calibre.customize.conversion import OptionRecommendation
from calibre.ebooks.conversion.plugins.epub_output import EPUBOutput

class KEPubOutput(EPUBOutput):
    name = 'KePub Output'
    author = 'Joel Goguen'
    file_type = 'kepub'

    def __init__(self, *args):
        self.options.add(
            OptionRecommendation(name='opt_kepub_enable_extended_features', recommended_value=True, level=OptionRecommendation.HIGH,
            help='Choose whether to enable extra customisations')
        )
        self.options.add(
            OptionRecommendation(name='opt_kepub_delete_unmanifested', recommended_value=False,
                                 level=OptionRecommendation.LOW,
                                 help='Select this to silently delete files that are not in the '
                                 'manifest if they are encountered during processing. If this '
                                 'option is not selected, files not in the manifest will be '
                                 'silently added to the manifest and processed as if they always '
                                 'were in the manifest.')
        )
        self.options.add(
            OptionRecommendation(name='opt_kepub_hyphenate', recommended_value=True,
                                 level=OptionRecommendation.MED,
                                 help='Select this to add a CSS file which enables hyphenation. '
                                 'The language used will be the language defined for the book in '
                                 'calibre. Please see the README file for directions on updating '
                                 'hyphenation dictionaries.')
        )
        self.options.add(
            OptionRecommendation(name='opt_kepub_replace_lang', recommended_value=True,
                                 level=OptionRecommendation.HIGH,
                                 help='Select this to replace the defined language in each '
                                 'content file inside the ePub.')
        )
        self.options.add(
            OptionRecommendation(name='opt_kepub_clean_markup', recommended_value=True,
                                 level=OptionRecommendation.MED,
                                 help='Select this to clean up the internal ePub markup.')
        )

        EPUBOutput.__init__(self, *args)
If I add either of the following methods to the above class, I get the same exception thrown saying that there's no format plugin for 'kepub'.
Code:
    def gui_configuration_widget(self, parent, get_option_by_name, get_option_help, db, book_id=None):
        return None
Code:
    def convert(self, oeb, output_path, input_plugin, opts, log):
        super(KEPubOutput, self).convert(oeb, output_path, input_plugin, opts, log)
jgoguen is offline   Reply With Quote
Old 08-05-2013, 02:12 PM   #8
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: 44,526
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Some things that jump out at me:

You should not change self.options in __init__ as it is meant to be a class level variable. Instead define your own options and set the epub output options explicitly before calling the base class convert()

You should have **kwargs in __init__

Generally speaking, I'd suggest not subclassing EPUbOutput, instead create your own plugin class, and simply call the epub output plugin in your convert() method. Since this is python, you dont really need ot sub-class, you can monkey patch instead.
kovidgoyal is offline   Reply With Quote
Old 08-05-2013, 06:26 PM   #9
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
Things seem to be going a lot better so far. What did it for me was not subclassing EPUBOutput. Now I can create a file with the KePub extension that's identical to the output of the EPUB output format, so hopefully the rest of what I'm looking to accomplish should be fairly straightforward.
jgoguen is offline   Reply With Quote
Old 08-05-2013, 10:04 PM   #10
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
So I was almost right, almost everything I want to do was straightforward

How can I get access to the calibre metadata of a book being converted? Specifically, I would like the ISO639 language identifier.

Also, what do I need to do in order to make 'kepub' show up as a selection in the list of formats a device can accept? When I open calibre's preferences, go to Plugins, and choose a device driver I can see all the formats calibre supports and some of them are selected according to what the device supports. Do I just need to add 'kepub' to the FORMATS list for the device driver?
jgoguen is offline   Reply With Quote
Old 08-05-2013, 10:21 PM   #11
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: 44,526
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use the oeb.metadata.language see the Metadata class in oeb/base.py for details. This class is unfortunately, a pain to use, but we are stuck with it for legacy reasons.

That list of formats is IIRC taken from the BOOK_EXTENSIONS constant. You can try adding kepub to that and it should work (this will need a change to calibre source code).
kovidgoyal is offline   Reply With Quote
Old 08-06-2013, 07:42 PM   #12
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
Your pointer to BOOK_EXTENSIONS led me to find that ConfigWidget gets its list of formats from the FORMATS set (or list) defined on the device. If the device driver defines USER_CAN_ADD_NEW_FORMATS=True (which is the default) this set from the driver is union()'d with BOOK_EXTENSIONS. So I was able to add kepub just by adding "FORMATS = set(['kepub'])" as a class-level variable. Haven't tested it yet, but that comes soon

For the metadata, the only thing I haven't seen yet is how to get an instance of the Metadata object for the book I'm currently converting. Nothing jumps out at me, not even how to get a unique identifier for the book being converted, but if the container's OPF file is updated with the metadata from calibre by the time convert() is called I'm perfectly OK with taking the (limited) information I'm looking for out of the OPF file.

EDIT: The OPF file is indeed updated and I've been able to get everything I was looking for! Now, to test with my driver to make sure these new 'kepub' files actually transfer correctly

Last edited by jgoguen; 08-06-2013 at 10:17 PM.
jgoguen is offline   Reply With Quote
Old 08-09-2013, 10:56 PM   #13
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
I'm running into an issue now getting the options to actually match the selections on the conversion options page. I've defined these recommendations as the set of options:
Code:
OptionRecommendation(name='kepub_hyphenate', recommended_value=True,
help='Select this to add a CSS file which enables hyphenation. '
'The language used will be the language defined for the book in '
'calibre. Please see the README file for directions on updating '
'hyphenation dictionaries.'),
OptionRecommendation(name='kepub_replace_lang', recommended_value=True,
help='Select this to replace the defined language in each content file inside the ePub.'),
OptionRecommendation(name='kepub_clean_markup', recommended_value=True,
help='Select this to clean up the internal ePub markup.')
With this, the resolved options always have these three options set to True no matter what I check off. If I set recommended_value to False, all three are always False. If I leave out recommended_value entirely, they're all always None.

I've also tried prepending 'opt_' to each of the names; in the plugin widget I set this (as an example of how all three options are added to the form:
Code:
self.opt_kepub_clean_markup = QtGui.QCheckBox(Form)
self.opt_kepub_clean_markup.setObjectName(_fromUtf8("opt_kepub_clean_markup"))
self.opt_kepub_clean_markup.setText("Clean ePub markup")
htext = "<div>%s</div>" % prepare_string_for_xml('\n'.join(w.wrap('Select this to clean up the internal ePub markup.')))
self.opt_kepub_clean_markup.setToolTip(htext)
self.opt_kepub_clean_markup.setWhatsThis(htext)
self.gridLayout.addWidget(self.opt_kepub_clean_markup, rows, 1, 1, 1)
For all this, I used the EPUB output classes as reference, but clearly I'm missing something. What do I need to do in order to get the three options I'm adding to the form to have their actual values in the resolved settings instead of their recommended values?
jgoguen is offline   Reply With Quote
Old 08-09-2013, 11:32 PM   #14
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: 44,526
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You remembered to register the options with the base class?
kovidgoyal is offline   Reply With Quote
Old 08-10-2013, 12:19 PM   #15
jgoguen
Generally Awesome Person
jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.jgoguen ought to be getting tired of karma fortunes by now.
 
Posts: 1,082
Karma: 2178847
Join Date: Jan 2013
Location: /dev/kmem
Device: Kobo Clara HD, Kindle Oasis
I thought I did, but after digging a little more it turns out I was doing it wrong. Thanks
jgoguen is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Output file name after conversion dbellefuil Calibre 2 06-14-2013 05:40 PM
Mimetypes icons should be plugin-based (for new input/output plugins, e.g.) SauliusP. Development 5 09-15-2012 02:15 PM
File Conversion Output Layout zobop Library Management 5 06-20-2012 06:17 PM
Conversion output folders TechieLady Conversion 6 01-19-2012 03:49 AM
AZW Conversion Output Plugin tylau0 Plugins 59 08-14-2011 11:36 PM


All times are GMT -4. The time now is 02:20 PM.


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