From 363553a5a4f7687cb507010e8d00de2b2b68ace1 Mon Sep 17 00:00:00 2001 From: Leaced Date: Fri, 24 Mar 2023 15:14:15 +0100 Subject: [PATCH] Add files via upload better shopt management and * as default setting for file-extensions --- to_opus.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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