mdisk: Delete unnecessary use of `strip_diskname` and use it elsewhere
[sunny256-utils.git] / wav_to_mp3
blob0de1170100480c92bfda6885146527f7fad84c9d
1 #!/usr/bin/env bash
3 #=======================================================================
4 # wav_to_mp3
5 # File ID: ffabc804-0665-11e3-a941-a088b4ddef28
6 # Convert .wav files to .mp3
7 # [Description]
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=wav_to_mp3
14 VERSION=0.1.1
16 ARGS="$(getopt -o "\
20 " -l "\
21 help,\
22 quiet,\
23 verbose,\
24 version,\
25 " -n "$progname" -- "$@")"
26 test "$?" = "0" || exit 1
27 eval set -- "$ARGS"
29 opt_help=0
30 opt_quiet=0
31 opt_verbose=0
32 while :; do
33 case "$1" in
34 -h|--help) opt_help=1; shift ;;
35 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
36 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
37 --version) echo $progname $VERSION; exit 0 ;;
38 --) shift; break ;;
39 *) echo $progname: Internal error >&2; exit 1 ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1" -o -z "$1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Usage: $progname [options] wav_file [...]
50 Options:
52 -h, --help
53 Show this help.
54 -q, --quiet
55 Be more quiet. Can be repeated to increase silence.
56 -v, --verbose
57 Increase level of verbosity. Can be repeated.
58 --version
59 Print version information.
61 END
62 if test -n "$1"; then
63 exit 0
64 else
65 exit 1
69 tmpuuid=$(suuid -m -t c_wav_to_mp3 -wa -c "Starting conversion")
70 test -z "$tmpuuid" && { echo "$progname: Broken suuid(1)" >&2; exit 1; }
71 for curr in "$@"; do
72 echo
73 echo ======== $(ls -l --si "$curr")
74 noext=$(basename "$curr" .wav)
75 wavfile="$noext.wav"
76 mp3file="$noext.mp3"
77 test -e "$mp3file" && { echo $mp3file: File already exists >&2; continue; }
78 wavid=$(finduuid "$wavfile")
79 wavid_str=
80 test -n "$wavid" && wavid_str=" (File ID $wavid)"
81 lame -h --tc $(suuid -m -t encode,c_wav_to_mp3 -wa -c "Converting $wavfile$wavid_str to mp3") "$wavfile" "$mp3file"
82 done