#!/usr/bin/env dash # shellcheck source=/dev/null SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH case "$("$1" | tr '[:upper:]' '[:lower:]')" in "lyrics") filter="LYRICS" directory="lyrics" ;; "instrumental") filter="INSTRUMENTAL" directory="instrumental" ;; *) die "Expected 'instrumental|lyrics' but got '$1'" ;; esac process() { mediainfo --Output=JSON "$1" | jq '.media.track | map(.Lyrics) | join("")' } mkdir "../$directory" fd . --extension=opus | while read -r file; do if [ "$(process "$file")" = '""' ] || [ "$(process "$file")" = '"Instrumental"' ] || [ "$(process "$file")" = '"instrumental"' ]; then echo "INSTRUMENTAL::$file" else echo "LYRICS::$file" fi done | grep "$filter" | awk 'BEGIN {FS="::"}{print $2}' | while read -r file; do ln -s "../all/$file" "../$directory/$file"; done # vim: ft=sh