]> git.draconx.ca Git - scripts.git/blob - replaygain.zsh
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / replaygain.zsh
1 #!/usr/bin/env zsh
2 #
3 # Copyright (C) 2009 Nick Bowler
4 #
5 # Adds replaygain tags to the flac files in a directory.  Assumes that all
6 # the tracks from a CD are located in the same directory.  Unless the -f flag
7 # is specified, directories already containing replaygain tags will not be
8 # processed.
9 #
10 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
11 # This is free software: you are free to do what the fuck you want to.
12 # There is NO WARRANTY, to the extent permitted by law.
13
14 alias flactags='metaflac --export-tags-to=-'
15
16 is_disc_dir() {
17         local files
18
19         [[ -d $1 ]] || return 1
20
21         files=($1/*.flac(N))
22         [[ $#files > 0 ]] || return 1
23 }
24
25 has_replay_gain() {
26         local files
27
28         files=($1/*.flac(N))
29         for i in $files; do
30                 (flactags $i | grep -q REPLAYGAIN_REFERENCE) || return 1
31         done
32 }
33
34 force=0
35 while getopts 'f' opt $@; do
36         case $opt in
37         f) force=1 ;;
38         \?) exit 1 ;;
39         esac
40 done
41
42 shift $((OPTIND-1))
43
44 if [[ $# == 0 ]]; then
45         printf 'usage: %s [-f] directory [directory ...]\n' $0
46         exit 1
47 fi
48
49 for dir in $@; do
50         printf '%s: ' $dir
51
52         if ! is_disc_dir $dir; then
53                 printf 'not an album directory, skipping.\n'
54                 continue
55         fi
56
57         if [[ $force == 0 ]] && has_replay_gain $dir; then
58                 printf 'already done, skipping.\n'
59                 continue
60         fi
61
62         metaflac --add-replay-gain $dir/*.flac
63         printf 'done.\n'
64 done