projects
/
BK-2020-03.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat(unitproc/bkt-randFloat):Update to use printf
[BK-2020-03.git]
/
user
/
bk-copy-rand-music.sh
diff --git
a/user/bk-copy-rand-music.sh
b/user/bk-copy-rand-music.sh
index c326e419e35cfd9cfa338f07bac4d758348f14f5..ea384fe722371fa1d27ca488313e51801fb4fcc4 100755
(executable)
--- a/
user/bk-copy-rand-music.sh
+++ b/
user/bk-copy-rand-music.sh
@@
-1,6
+1,7
@@
#!/usr/bin/env bash
#!/usr/bin/env bash
-# Desc: Copies random
music
+# Desc: Copies random
audio files
# Usage: bk-copy-rand-music.sh [dir SOURCE] [dir DEST] [int DURATION]
# Usage: bk-copy-rand-music.sh [dir SOURCE] [dir DEST] [int DURATION]
+# Version: 0.0.3
declare -Ag appRollCall # Associative array for storing app status
declare -Ag fileRollCall # Associative array for storing file status
declare -Ag appRollCall # Associative array for storing app status
declare -Ag fileRollCall # Associative array for storing file status
@@
-9,7
+10,9
@@
declare -a music_codecs # Array for storing valid codec names (e.g. "aac" "mp3")
# Adjustable parameters
music_codecs=("vorbis" "aac" "mp3" "flac" "opus"); # whitelist of valid codec_names ffprobe might return
# Adjustable parameters
music_codecs=("vorbis" "aac" "mp3" "flac" "opus"); # whitelist of valid codec_names ffprobe might return
-max_loops=1000000; # max number of files to test whether are audio or not
+max_loops="1000000"; # max number of files to test whether are audio or not
+max_filename_length="255"; # max output filename length
+min_file_duration="10"; # minimum duration per music file
yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
@@
-178,8
+181,8
@@
showUsage() {
cat <<'EOF'
DESCRIPTION:
cat <<'EOF'
DESCRIPTION:
- This script may be used to copy a random selection of files
from
- SOURCE to DEST.
+ This script may be used to copy a random selection of files
containing
+
audio tracks from
SOURCE to DEST.
USAGE:
bk-copy-rand-music [dir SOURCE] [dir DEST] [int DURATION]
USAGE:
bk-copy-rand-music [dir SOURCE] [dir DEST] [int DURATION]
@@
-431,6
+434,7
@@
main() {
dur_cand="$(get_media_length "$path_candfile")";
dur_cand="${dur_cand%%.*}"; # convert float to int
if ! checkInt "$dur_cand"; then continue; fi; # reject
dur_cand="$(get_media_length "$path_candfile")";
dur_cand="${dur_cand%%.*}"; # convert float to int
if ! checkInt "$dur_cand"; then continue; fi; # reject
+ if [[ "$dur_cand" -lt "$min_file_duration" ]]; then continue; fi; # reject
### Add/update candfile to list_copy assoc. array (key=path; value=duration)
#yell "DEBUG:Adding $path_candfile";
### Add/update candfile to list_copy assoc. array (key=path; value=duration)
#yell "DEBUG:Adding $path_candfile";
@@
-448,6
+452,7
@@
main() {
if [[ $n -gt $max_loops ]]; then die "ERROR:Too many loops:$n"; fi;
done;
if [[ $n -gt $max_loops ]]; then die "ERROR:Too many loops:$n"; fi;
done;
+ n=0; # Initialize loop counter
# Copy files in list_copy to dir_dest;
for key in "${!list_copy[@]}"; do
value="${list_copy[$key]}";
# Copy files in list_copy to dir_dest;
for key in "${!list_copy[@]}"; do
value="${list_copy[$key]}";
@@
-457,13
+462,26
@@
main() {
## Get 16-character b2sum fingerprint (for different files that share basename)
fingerprint="$(b2sum -l64 "$key" | cut -d' ' -f1)";
## Get 16-character b2sum fingerprint (for different files that share basename)
fingerprint="$(b2sum -l64 "$key" | cut -d' ' -f1)";
+ ## Form output filename
+ file_name="$fingerprint".."$file_basename";
+ file_name="${file_name:0:$max_filename_length}"; # Limit filename length (e.g. Windows has max of 255 characters)
+
## Form output path
## Form output path
- path_output="$dir_dest"/"$fi
ngerprint".."$file_base
name";
+ path_output="$dir_dest"/"$fi
le_
name";
## Copy
try cp "$key" "$path_output" && yell "NOTICE:Copied ($value seconds): $key ";
#yell "DEBUG:Copied $file_basename to $dur_dest.";
## Copy
try cp "$key" "$path_output" && yell "NOTICE:Copied ($value seconds): $key ";
#yell "DEBUG:Copied $file_basename to $dur_dest.";
+ ## Append log
+ path_log_output="$dir_dest"/COPY.log;
+ if [[ $n -le 0 ]]; then
+ echo "fingerprint","duration","original_path" >> "$path_log_output";
+ else
+ echo "$fingerprint","$value","$key" >> "$path_log_output";
+ fi;
+
+ ((n++));
unset file_basename path_output
done;
unset file_basename path_output
done;