Quote:
Originally Posted by Quoth
Waste of time, often plagiarism, dubious quality and environmentally damaging.
AI is zero value for study as unless you are already expert you have no idea if the results are junk or totally misleading. Even ones that cite do it badly.
|
Nothing personal, I randomly chose your feedback from a long list of negative skeptics of any AI tool. I understand the resistance. There are areas I wouldn't bet my life on -- like medical advice. But I do think that these tools are useful especially if the results are reviewed by professionals.
As I mentioned earlier suggesting a plugin that incorporates AI analysis for books, I tried the process (manually, obviously) on several books and was impressed. Since I am not a plugin developer I decided to do another experiment - uploaded the entire Calibre manual to NotebookLM and asked it "How do you write a new plugin?". It created an impressive overview which I think gives a useful overview (but just an overview - one still needs to read the chapter to actually learn how to create a plugin). Here it is:
To write a new plugin for calibre, you can follow these general steps based on the information in the sources:
Spoiler:
**1. Understand the Basics of Calibre Plugins:**
- Calibre has a modular design where almost all functionality comes in the form of plugins.
- Plugins can be used for various purposes, such as conversion, downloading news (recipes), user interface components, device connections, and file processing.
- Calibre plugins are essentially ZIP files containing Python code and other necessary resources like images.
**2. Create the Basic Plugin Structure:**
- A basic plugin requires at least one Python file named `__init__.py`, which acts as the main file for your plugin.
- For more complex plugins with multiple files, you need to include an empty text file named `plugin-import-name-some_name.txt` in the ZIP file. This enables importing code from other `.py` files within the ZIP using the prefix `calibre_plugins.some_name`. The `some_name` part comes from the filename of this empty text file.
**3. Define Your Plugin Class:**
- In your `__init__.py` file, you need to define a class that inherits from one of the base plugin classes provided by calibre, depending on the type of plugin you want to create. Some common base classes include:
- **`FileTypePlugin`**: For plugins that operate on specific file types, such as modifying e-books after conversion. The "Hello World" plugin example demonstrates this, setting the publisher metadata for EPUB and MOBI files after conversion.
- **`InterfaceActionBase` and `InterfaceAction`**: For plugins that add components to the calibre user interface. The "Interface Plugin Demo" illustrates how to create a user interface plugin with menus, actions, and configuration options. Such plugins often involve separate files like `ui.py` for the interface and `main.py` for the logic.
- **`EditBookToolPlugin`**: For plugins that add tools to the calibre book editor. The "Edit Book plugin demo" shows how to create a tool that modifies font sizes. These tools are defined in `main.py` and inherit from `calibre.gui2.tweak_book.plugin.Tool`.
- **`Plugin`**: The base class for all plugins. Other plugin types like `MetadataReaderPlugin`, `MetadataWriterPlugin`, `CatalogPlugin`, `Metadata download plugins`, `Conversion plugins`, `Device drivers`, and `PreferencesPlugin` also inherit from this.
**4. Implement Required Methods and Attributes:**
- Each plugin class has specific attributes you need to define (like `name`, `description`, `supported_platforms`, `author`, `version`, `minimum_calibre_version`, `file_types` for `FileTypePlugin`).
- You also need to implement methods that define the plugin's functionality. For example:
- `FileTypePlugin` requires a `run(self, path_to_ebook)` method which is called for the specified file types.
- `InterfaceAction` plugins often have a `genesis(self)` method for initial setup and may define an `action_spec` to create a menu or toolbar action.
- `EditBookToolPlugin` requires a `create_action(self, for_toolbar=True)` method to create the toolbar or menu item and often an action method that performs the desired operation.
**5. Enable User Configuration (Optional but Recommended for UI Plugins):**
- To allow users to customize your plugin through Preferences -> Plugins, you need to:
- Make the base plugin class return `True` for the `is_customizable(self)` method.
- Implement the `config_widget(self)` method to return a `QWidget` for the configuration dialog. This widget's code can be in a separate file like `config.py`.
- Implement the `save_settings(self, config_widget)` method to save the user's settings.
- The recommended way to store configuration data is using the `JSONConfig` class.
**6. Access Resources from the Plugin ZIP File:**
- Calibre provides built-in functions to access files within your plugin's ZIP archive:
- `get_resources(name_or_list_of_names)`: Returns the contents of the specified files as bytes.
**7. Add Translations (Optional):**
- To make your plugin's user interface translatable, you need to:
- Mark all user-visible strings as translatable by surrounding them with `_()`.
- Generate `.po` files for each language you want to support.
- Compile the `.po` files into `.mo` files.
- Place the `.mo` files in a `translations` folder within your plugin.
- Call the `load_translations()` function at the top of your plugin's `.py` files that contain translatable strings (typically in `ui.py` for UI plugins).
**8. Debug Your Plugin:**
- Run calibre in debug mode using `calibre-debug -g` from the command line or by right-clicking the Preferences button (or Ctrl+Shift+R) within calibre.
- Insert `print` statements in your plugin code to track execution and identify issues.
- You can quickly test changes using `calibre-debug -s; calibre-customize -b /path/to/your/plugin/folder; calibre`.
**9. Package Your Plugin:**
- Once you have your plugin files, you need to package them into a ZIP file. The `__init__.py` file (and the `plugin-import-name-some_name.txt` file for multi-file plugins) should be at the root of the ZIP archive.
**10. Add Your Plugin to Calibre:**
- In calibre, go to Preferences -> Plugins -> Get new plugins (or Load plugin from file if you have the ZIP file).
**11. Share Your Plugin (Optional):**
- If you want to share your plugin with others, you can post it in the calibre plugins forum on Mobileread.
By following these steps and referring to the more detailed examples and API documentation mentioned in the sources, you can create your own plugins to extend the functionality of calibre. Remember to choose the appropriate base class for your plugin type and implement the necessary methods and attributes.