mp3-tags-to-folders (1229B)
1 #!/bin/sh 2 # Places all MP3 files in a directory into folders based on the artist and album. 3 # If you want to make changes in the current dir, run `mp3-tags-to-folders . .` 4 die() { printf "%s\n" "$1" >&2; exit 1; } 5 command -v ffprobe 1>/dev/null 2>&1 || die "ffprobe not installed." 6 [ $# -eq 2 ] || die "Arguments required: path to music directory, path to destination" 7 [ -d "$1" ] || die "Path $1 is not a directory." 8 set -x 9 cd "$2" || die "Could not cd to $1" 10 mkdir -p _failed || die "Directory ./_failed already exists" 11 find "$1" -name "*.mp3" 2>/dev/null | \ 12 while read -r i; do 13 artist="$(ffprobe -loglevel error -show_entries format_tags=album_artist -of default=noprint_wrappers=1:nokey=1 "$i" | tr -d ':' | tr '!@#$%^&*:?"\\>' '_' | sed 's/\.\.*$//')" 14 [ -n "$artist" ] || { mv "$i" _failed/ && continue; } 15 album="$(ffprobe -loglevel error -show_entries format_tags=album -of default=noprint_wrappers=1:nokey=1 "$i" | tr -d ':' | tr '!@#$%^&*:?>\\"' '_' | sed 's/\.\.*$//')" 16 [ -n "$album" ] || { mv "$i" _failed/ && continue; } 17 mkdir -p "$artist/$album" 18 mv "$i" "$artist/$album" 19 done 20 rmdir _failed 1>/dev/null 2>&1 || printf "Some tracks were not organised automatically, they are in ./_failed/"