Commit: 877ded3fa462aab528d88fc993333522fe627650
Parent: de0bef4b0bd99901f912bc208b503c1bd3dd4cc3
Author: Randy Palamar
Date: Wed, 2 Jun 2021 18:30:59 -0600
extract-audio: stip {pre,suf}fix '_', add file numbering option
file numbering is not enabled by default because its only useful for
extremely janky filenames (i.e. using '.' instead of space or '_' like
a sane person)
Diffstat:
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/bin/extract-audio b/bin/extract-audio
@@ -4,14 +4,15 @@
# useful for passive immersion
usage() {
- echo "usage: $0 [-d outdir] [-l lang] file ..."
+ echo "usage: $0 [-n] [-d outdir] [-l lang] file ..."
exit 1
}
-while getopts "d:l" arg; do
+while getopts "d:l:n" arg; do
case "${arg}" in
d) outdir="${OPTARG}" ;;
l) lang="${OPTARG}" ;;
+ n) COUNT=0 ;;
*) usage ;;
esac
done
@@ -30,9 +31,15 @@ for f in $*; do
# construct track title and new filename
t=$(echo $f | cut -d . -f 1 | \
sed -e 's:\[.*\]::g; s:(.*)::g' \
- -e 's:^ *::; s: *$::')
+ -e 's:^ *::; s: *$::' \
+ -e 's:^_*::; s:_*$::')
newf=$out/$t.opus
+ if [ $COUNT ]; then
+ COUNT=$((COUNT + 1))
+ newf=$(printf "%s/%02d %s.opus" $out $COUNT $t)
+ fi
+
# find a stream index for desired audio track
idx=$(ffprobe -of compact=nk=1:s=. -v error \
-show_entries stream=index,codec_type:stream_tags=language \