L=5; while true; do; readarray -t paths < <(find . -type f -print | shuf -n 1); for i in "${!paths[@]}"; do; path=${paths[i]}; if ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0" > /dev/null; then; N=$(ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0"); D=${N%.*}; P=$((D / 100 * 25)); R=$((1 + RANDOM % D - P * 2)); S=$((P + RANDOM % R)); W=$((R / 4)); LEN=$((1 + RANDOM % L)); mpv "$path" --start="$S" --length="$LEN" --fs &> /dev/null; W=$(bc <<< "$LEN - 0.5"); sleep "$W"; unset 'paths[i]'; fi; done; done
The command expanded to multiple lines as if written in a script:
L=5
while true; do
readarray -t paths < <(find . -type f -print | shuf -n 1)
for i in "${!paths[@]}"; do
path=${paths[i]}
if ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0" > /dev/null; then
N=$(ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0")
D=${N%.*}
P=$((D / 100 * 25))
R=$((1 + RANDOM % D - P * 2))
S=$((P + RANDOM % R))
W=$((R / 4))
LEN=$((1 + RANDOM % L))
mpv "$path" --start="$S" --length="$LEN" --fs &> /dev/null
W=$(bc <<< "$LEN - 0.5")
sleep "$W"
unset 'paths[i]'
fi
done
done
Usage:
The script assumes several non-standard utilities are installed in the system: