Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- me="${0##*/}"
- if [ -w "$TMPDIR" ]; then
- tdir="$TMPDIR"
- elif [ -w '/tmp' ]; then
- tdir='/tmp'
- elif [ -w "$HOME" ]; then
- tdir="$HOME"
- elif [ -w "$PWD" ]; then
- tdir="$PWD"
- else
- echo "$me: error: can't find a writable directory for creating the temporary file" 1>&2 ; exit 1
- fi
- tf="$( TMPDIR="$tdir" mktemp "${tdir}/${me}.XXXX" 2>/dev/null )"
- if [ -z "$tf" ]; then
- echo "$me: error: can't create temporary file" 1>&2 ; exit 1
- fi
- checkbits ()
- {
- local bps abps tbps=0 n=0
- bps="$( metaflac --show-bps "$1" )"
- flac -ac "$1" 2>/dev/null | fgrep 'wasted_bits' | cut -d '=' -f 3 | cut -f 1 > "$tf"
- while read wb; do
- tbps=$(( tbps + ( bps - wb ) ))
- ((n++))
- done < "$tf"
- abps=$(( ( ( tbps * 10 / n) + 5 ) / 10 )) # (* 10 + 5) / 10 for proper rounding
- printf "%2u/%2u bits\t%s\n" "$abps" "$bps" "$1"
- }
- for f in "$@"; do
- case "$f" in
- *.flac) checkbits "$f" ;;
- *) continue ;;
- esac
- done
- rm -f "$tf"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement