zohann's picture
Upload Audio_Effects_SDK/samples/effects_demo/list.sh with huggingface_hub
15487d0 verified
raw
history blame
1.32 kB
#!/bin/bash
set -eo pipefail
if [ "$#" -lt 2 ]; then
echo "Format: $0 <input_folder> <size> [reset_indices]"
exit 1
fi
unset reset_list reset_files_list reset_files_num
declare -a reset_list
declare -a reset_files_list
reset_files_num=0
if [ "$#" -eq 3 ]; then
IFS="," read -r -a reset_list <<< $3
while IFS= read -d $'\0' -r f; do
reset_files_list[reset_files_num++]="$f"
done < <(find $1 -type f -iname "*short*.wav" -print0 | sort -V -z)
if [ $reset_files_num -eq 0 ]; then
echo "No reset files found in directory $1"
exit 1
fi
fi
if [ ! -d "$1" ]; then
echo "First argument should be a directory (got $1)"
exit 1
fi
unset list i
i=0
declare -a list
while IFS= read -d $'\0' -r f; do
list[i++]="$f"
done < <(find $1 -type f -iname "*.wav" ! -iname "*short*" -print0 | sort -V -z)
if [ $i -le 0 ]; then
echo "No files found in directory $1"
exit 1
fi
LIMIT=$2
case $LIMIT in
*[!0-9]*) echo "Second argument should be a positive number (was $2)"; exit 1;
esac
LIMIT=$((LIMIT-1))
OUT=""
for index in $(seq 0 $LIMIT)
do
val=$((index%i))
if [[ " ${reset_list[@]} " =~ " $index " ]]; then
rval=$((index%reset_files_num))
OUT="$OUT ${reset_files_list[$rval]};${list[$val]}"
else
OUT="$OUT ${list[$val]}"
fi
done
echo $OUT