Advanced event hooks

Where can I find out how to configure beets to do specific tasks on import, and more importantly, on write?
I would like to create a par2 set for each music track after verifying it with the badfiles plugin. Also, every time a file is changed (i.e., tags are written), it should trigger a delete and recreation said par2 file.

Hi! Have you seen the hook plugin?
https://beets.readthedocs.io/en/stable/plugins/hook.html

That looks great. I was looking at the events and I have a question. Is the after_write event fired after each imported file is written? The description makes it sound like it is only fired when updated tags are written.
Also, the documentation shows methods of the Item class, but it does not show the names of the fields. I know one of them is Item.path. It looks like that is the full path, however, I need just the filename. Is there a listing of the available fields in the Item class?

Hmm, can you maybe clarify your question? “After each imported file is written” and “updated tags are written” sound like the same thing to me…

Some place to look for the fields available are the beet fields command and the source code for the Item class. For the filename, though, I think you probably just want the Python standard library:
https://docs.python.org/3.8/library/os.path.html#os.path.basename

Will the after_write event be fired after a file is imported even if import is set to not Auto tag?

Aha, no—maybe you want item_imported instead?

That says it is only called for singletons, but I will be importing my music directory first which is organized by album, and then I will import an album at a time as I rip new cds.
Do I need to hook into item_imported and album_imported?
Having to hook into album_imported will make my script programming much more difficult.

Oh, and I need the event that I hook into to be fired after all operations on the file are done and the file handle is closed.

Yeah, you might want to handle both, and just use a shell for loop over the items for the album case. Give it a shot and see how it goes!

EDIT: figured it out

I can’t figure this hook config out. I formed it like in the documentation but it is giving me an error.

configuration error: file /Users/phire/.config/beets/config.yaml could not be read: mapping values are not allowed here
  in "/Users/phire/.config/beets/config.yaml", line 45, column 20

and my config file is

directory: /Volumes/data/My Documents/Music
library: /Volumes/data/My Documents/Music/musiclibrary.db

import:
copy: yes
autotag: yes
bell: yes

match:
ignored_media: [‘Data CD’, ‘DVD’, ‘DVD-Video’, ‘Blu-ray’, ‘HD-DVD’, ‘VCD’, ‘SVCD’, ‘UMD’, ‘VHS’]

threaded: yes

ui:
color: yes

plugins: badfiles lastimport lastgenre replaygain fetchart embedart lyrics hook playlist smartplaylist

lyrics:
sources: google lyricwiki musixmatch genius

embedart:
remove_art_file: yes

replaygain:
backend: gstreamer

lastgenre:
canonical: yes
source: track

lastfm:
user: me

playlist:
playlist_dir: /Volumes/data/My Documents/Music/playlists
auto: yes

paths:
default: $albumartist/$album%aunique{}/$track $title

hook:
hooks:
- event: after_write
command: ~/bin/createpar “{item.path}”