diff --git a/to_opus.sh b/to_opus.sh index bc2f70f..78c0665 100644 --- a/to_opus.sh +++ b/to_opus.sh @@ -1,18 +1,28 @@ -#!/usr/bin/env bash +#!/bin/bash +# set shopt-options used by this shell-script +# Note, 0 (true) from shopt -q is "false" in a math context. shopt -q globstar; globstar_set=$? ((globstar_set)) && shopt -s globstar shopt -q extglob; extglob_set=$? ((extglob_set)) && shopt -s extglob -# Note, 0 (true) from shopt -q is "false" in a math context. -FORMATS=$@ +# return default shopt-options +function finish { + ((globstar_set)) && shopt -u globstar + ((extglob_set)) && shopt -u extglob +} +trap finish EXIT -for file in **/*.@(${FORMATS// /|}); do - ffmpeg -threads 4 -i "$file" -c:a libopus -b:a 128k "${file%.*}.opus" && rm "$file" +# setting default extension to all +if [ $# -eq 0 ]; then + extension="*" +else + extension=$@ +fi + +for file in **/*.@(${extension// /|}); do + ffmpeg -threads 4 -i $file -c:a libopus -b:a 128k "${file%.*}.opus" && rm "$file" done -((globstar_set)) && shopt -u globstar -((extglob_set)) && shopt -u extglob - exit 0