about summary refs log tree commit diff stats
path: root/pkgs/by-name/so/sort_song/sort_song.sh
blob: e2978507a1f739bdcf1090b3243b590de58c7130 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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