How do I automatically create a subdirectory on moving/importing an album?

I keep album covers and other non-track metadata in a meta/ directory under each album directory to segregate them from actual music tracks. Currently, whenever I import new music I need to:

  • Import the music once
  • Create the meta directories,
  • Rerun beets to fetch any album art

with a similar process needed whenever I move files. Is there any way to get beets to create these meta directories automatically before moving/importing files?

A straightforward hack could be to use the hook plugin:
https://beets.readthedocs.io/en/stable/plugins/hook.html

You could listen to the album_imported event and use something like mkdir os.path.join(album.path, 'meta')? That idea probably needs some tweaking, but it could be the right direction.

1 Like

Solved it with a hook and a few scripts in the end,

Hook config

hook:
  hooks:
    # create meta directory before an item is moved
    - event: before_item_moved
      command: mkmeta.sh "{destination}"

    # move items from meta directories
    - event: before_item_moved
      command: mvmeta.sh "{source}" "{destination}"

mkmeta.sh

FPATH="$1"
MDIR="$(dirname "$FPATH")/meta"
mkdir -p "$MDIR"

mvmeta.sh

SPATH="$1"
DPATH="$2"
SMDIR="$(dirname "$SPATH")/meta"
DMDIR="$(dirname "$DPATH")/meta"
if [ "$SMDIR" != "$DMDIR" ] && [ -e "$SMDIR" ]; then
   if [ "$(ls -A "$SMDIR")" ]; then
    mv -v "${SMDIR}"/* "${DMDIR}/"
   fi
   rmdir "${SMDIR}"
fi