-
Notifications
You must be signed in to change notification settings - Fork 0
Plugins
Plugins are a way to extend the functionality of the program programatically.
Plugins are found in the batchpynamer/plugins/plugins/
folder or in the user configuration folder (~/.config/batchpynamer/plugins/
for linux, ~/AppData/Roaming/batchpynamer/plugins/
fow windows and ~/Library/Preferences/batchpynamer/plugins/
for mac).
The plugins are loaded dinamically and added to the plugin menu as found.
Starting from the plugins
directory, search recursively. Directories create a cascade menu with the directory name, and files add the classes defined in that file as menu buttons with the class name. The classes of each file are separated by a menu separator.
Files and classes starting with _
are ignored. Hidden files/directories are ignored.
Only classes that are child of BasePlugin
are added.
Keep in mind that when using the same dirname-basename structure, the plugins in the user config take precedence. That means, for example you can find with the base code some plugins already, one of them are under Metadata-Plugins/metadata.py
; so, if i were to create a the same directory structure in the user plugins directory, the files under the directory would be loaded to the same sub-menu, but if the there are any files in that structure with the same name, only the plugins in the user file would be loaded.
Examples:
Lets say we have plugins/Metadata-Plugins/metadata.py
and plugins/Selection-Plugins/selection.py
in the base code plugins folder.
And plugins/Metadata-Plugins/mymetadata.py
and plugins/Selection-Plugins/selection.py
in the user config plugins.
In this case a Metadata-Plugins
cascade menu would be added and it would be filled with the classes from metadata.py
and mymetadata.py
, another caascade menu would be created for Selection-Plugins
but this time only the classes from the user file would be added.
To run a plugin just click the menu button for it. It will be applied to each selected item (unless the code does otherwise)
- Format "tracknumber": formats the "tracknumber" of the selected items. Adds left 0s padding, removes anything that's after "/", inclusive (e.g: "1/12" would end "01")
- Format "date" as year: Format metadata date to just be the year
- Format full "date": Format metadata date to have dashes between year-month-day
- Delete Selection: Deletes the selection. files and empty dirs.
- Force Delete Selection: Also deletes non empty dirs
- Select last modified 24h: Selects the items that have been modified in the last 24 hours
Plugins must heredate from BasePlugin
class.
They Must define the run
method. If not, a NotImplementedError
will be raised.
They can also define the selection
, pre_hook
and post_hook
methods.
It also has a short_desc
, finished_msg
and allow_no_selection
attributes.
short_desc
will be used for displaying in GUI if available (with limited chars)
A NoSelectionError
will be raised if no selection unless allow_no_selection=True
When no selection and allow_no_selection=True
: run()
will be run once.
Else it will run on each selection item
from batchpynamer.plugins.plugins_base import BasePlugin
class MyPlugin(BasePlugin)
short_desc = "Name to display"
finished_msg = "MyPlugin finished"
allow_no_selection = False
def pre_hook(self):
super().pre_hook()
*do pre hook stuff*
def selection(self):
super().selection()
*do selection stuff*
def run(self, item, pre_hook_return=None):
*do stuff to each item*
def post_hook(self, run_return=None, pre_hook_return=None):
super().post_hook(run_return=None, pre_hook_return=None)
*do post hook stuff*
*Some more stuff that you want*
Get as creative as you want ;) and would love if you shared the plugins that you create.
You can find some examples already in the base code, and also I have a repository with some extra stuff Batch-Pynamer-Plugins
Batch-Pynamer wiki. Author: Alejandro Roldán