- Note: Using `tr -dc '[:graph:][:space:]'` as character filter.
#!/usr/bin/env bash
# Desc: Copies random audio files
# Usage: bk-copy-rand-music [dir SOURCE] [dir DEST] [int DURATION] ([int BYTES])
#!/usr/bin/env bash
# Desc: Copies random audio files
# Usage: bk-copy-rand-music [dir SOURCE] [dir DEST] [int DURATION] ([int BYTES])
# Depends: BK-2020-03: bkshuf v0.1.0
declare -Ag appRollCall # Associative array for storing app status
# Depends: BK-2020-03: bkshuf v0.1.0
declare -Ag appRollCall # Associative array for storing app status
fpath="$(printf "%s" "$line" | cut -d',' -f3-)";
## Get basename of path
file_basename="$(basename "$fpath")";
fpath="$(printf "%s" "$line" | cut -d',' -f3-)";
## Get basename of path
file_basename="$(basename "$fpath")";
+ ### Get basename without unprintable non-ASCII characters
+ file_basename_compat="$(printf "%s" "$file_basename" | tr -dc '[:graph:][:space:]' )";
## Get 16-character b2sum fingerprint (for different files that share basename)
fingerprint="$(b2sum -l32 "$fpath" | awk '{print $1}' )";
## Form output filename
num="$(printf "$num_fmt" "$n")";
## Get 16-character b2sum fingerprint (for different files that share basename)
fingerprint="$(b2sum -l32 "$fpath" | awk '{print $1}' )";
## Form output filename
num="$(printf "$num_fmt" "$n")";
- file_name="$num"_"$fingerprint".."$file_basename";
+ file_name="$num"_"$fingerprint".."$file_basename_compat";
file_name="${file_name:0:$max_filename_length}"; # Limit filename length (e.g. Windows has max of 255 characters)
## Form output path
file_name="${file_name:0:$max_filename_length}"; # Limit filename length (e.g. Windows has max of 255 characters)
## Form output path
printf "$log_fmt" "$num" "$fingerprint" "$fdur" "$fsize" "$fpath_can" >> "$path_log_output";
((n++));
printf "$log_fmt" "$num" "$fingerprint" "$fdur" "$fsize" "$fpath_can" >> "$path_log_output";
((n++));
- unset file_basename path_output
+ unset file_basename file_basename_compat path_output;
done < <(printf "%s\n" "${list_copy[@]}");
# Report total duration and size
done < <(printf "%s\n" "${list_copy[@]}");
# Report total duration and size