Debian Codegraph @

manual/plugin_examples/helloworld/__init__.py

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3
4
5 __license__ = 'GPL v3'
6 __copyright__ = '2011, Kovid Goyal <[email protected]>'
7 __docformat__ = 'restructuredtext en'
8
9 import os
10
11 from calibre.customize import FileTypePlugin
12
13
14 class HelloWorld(FileTypePlugin):
15 name = 'Hello World Plugin' # Name of the plugin
16 description = 'Set the publisher to Hello World for all new conversions'
17 supported_platforms = ['windows', 'osx', 'linux'] # Platforms this plugin will run on
18 author = 'Acme Inc.' # The author of this plugin
19 version = (1, 0, 0) # The version number of this plugin
20 file_types = {'epub', 'mobi'} # The file types that this plugin will be applied to
21 on_postprocess = True # Run this plugin after conversion is complete
22 minimum_calibre_version = (0, 7, 53)
23
24 def run(self, path_to_ebook):
25 from calibre.ebooks.metadata.meta import get_metadata, set_metadata
26
27 with open(path_to_ebook, 'r+b') as file:
28 ext = os.path.splitext(path_to_ebook)[-1][1:].lower()
29 mi = get_metadata(file, ext)
30 mi.publisher = 'Hello World'
31 set_metadata(file, mi, ext)
32 return path_to_ebook