Advertisement
fant0men

gettags.sh

Apr 20th, 2022 (edited)
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This is just a test script to show off the 'gettags' function, which
  4. # reads the tags of FLAC files.
  5.  
  6. if=$(readlink -f "$1")
  7.  
  8. declare -A alltags
  9.  
  10. gettags () {
  11.     for field in "${!alltags[@]}"; do
  12.         unset -v alltags[${field}]
  13.     done
  14.  
  15.     mapfile -t lines < <(metaflac --no-utf8-convert --export-tags-to=- "$if")
  16.  
  17.     for (( z=0; z<${#lines[@]}; z++ )); do
  18.         line="${lines[${z}]}"
  19.  
  20.         unset -v mflac
  21.  
  22.         mflac[0]="${line%%=*}"
  23.         mflac[1]="${line#*=}"
  24.  
  25.         if [[ -z ${mflac[1]} ]]; then
  26.             continue
  27.         fi
  28.  
  29.         field="${mflac[0],,}"
  30.  
  31.         if [[ -n ${alltags[${field}]} ]]; then
  32.             continue
  33.         fi
  34.  
  35.         alltags["${field}"]="${mflac[1]}"
  36.     done
  37. }
  38.  
  39. gettags
  40.  
  41. for field in "${!alltags[@]}"; do
  42.     printf '%s\n' "${field}: ${alltags[${field}]}"
  43. done | sort
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement