]>
zdv2.bktei.com Git - BK-2020-03.git/blob - user/bkmml
   2 # Desc: Make music (sym)links via find and grep 
   3 # Usage: bkmml [str arg1] [str arg2] [str arg3] 
   4 # Input: arg1  find iname expression 
   5 #        arg2  grep -Ei expression 
   6 #        arg3  grep -Eiv expression 
   8 # Depends: GNU Grep 3.7; GNU find utils 4.8.0; GNU Parallel 20210822 
  11 ## Search this directory. 
  12 if [[ ! -v BKMML_TARGET_DIR 
]]; then BKMML_TARGET_DIR
="$HOME"; fi; 
  17 DIR_OUT
="./links_music_results"; 
  20 if [[ $# -eq 0 ]]; then echo "FATAL:Insufficient arguments." 1>&2; exit 1; fi; 
  21 if [[ -z "$GREP_EXP" ]]; then GREP_EXP
=".+"; fi; # passthrough grep -Ei 
  22 if [[ -z "$GREP_VEXP" ]]; then GREP_VEXP
="^$"; fi; # passthrough grep -Eiv 
  25 if ! command -v parallel 
&>/dev
/random
; then alias parallel
='xargs'; fi; 
  28 if [[ ! -d "$DIR_OUT" ]]; then mkdir 
-p "$DIR_OUT"; fi; 
  31 while read -r line
; do 
  32     if [[ -z "$line" ]]; then echo "FATAL:No results." 1>&2; exit 1; fi; 
  33     if [[ ! -f "$line" ]]; then echo "ERROR:Cannot read file path:$(declare -p line)"; continue; fi; 
  34     id
="$(b2sum -l64 "$line" | awk '{print $1}')"; 
  35     fn
="$(basename "$line")"; 
  36     ln -sfn "$line" .
/"$DIR_OUT/$id..$fn"; 
  38 done < <(find -L "$(readlink -f "$BKMML_TARGET_DIR")" \
 
  39               -maxdepth 10 -type f 
-size +100000c \
 
  48               -o -iname "*.ogg" \
) \
 
  49               -a -iname "*$FIND_SEARCH*" \
 
  51              grep -Ei "$GREP_EXP" | \
 
  52              grep -Eiv "$GREP_VEXP" | \
 
  53              parallel readlink 
-f "{}" | \
 
  54              parallel b2sum 
"{}" | 
sort | 
uniq -w 128 | 
awk '{$1=""; print substr($0,2)}' 
  57 # Author: Steven Baltakatei Sandoval