- new_accumulated_duration=$(echo "$accumulated_duration + $duration" | bc)
- if (( $(echo "$random_point < $new_accumulated_duration" | bc -l) )); then
- offset=$(echo "$random_point - $accumulated_duration" | bc)
+ declare -p idx file duration accumulated_duration 1>&2 # Debugging statement
+
+ # Validate the duration
+ if [[ -n "$duration" && "$duration" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
+ new_accumulated_duration=$(echo "$accumulated_duration + $duration" | bc)
+ # Convert accumulated durations to integers for comparison
+ accumulated_duration_int=$(printf "%.0f" "$accumulated_duration")
+ new_accumulated_duration_int=$(printf "%.0f" "$new_accumulated_duration")
+ else
+ yell "WARNING: Invalid duration '$duration' for file '$file', skipping." 1>&2
+ continue
+ fi
+
+ if (( random_point < new_accumulated_duration_int )); then
+ offset=$(echo "$random_point - $accumulated_duration_int" | bc)