forked from linux4ever07/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flac_tags.sh
executable file
·109 lines (74 loc) · 1.52 KB
/
flac_tags.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# This script will list tags of a FLAC album. It allows the user to
# select individual tracks from a simple menu, and display the tags.
usage () {
printf '\n%s\n\n' "Usage: $(basename "$0") [dir]"
exit
}
if [[ ! -d $1 ]]; then
usage
fi
dn=$(readlink -f "$1")
mapfile -t files < <(find "$dn" -maxdepth 1 -type f -iname "*.flac" 2>&- | sort -n)
if [[ ${#files[@]} -eq 0 ]]; then
usage
fi
declare track
regex_num='^[0-9]+$'
gettags () {
if="$1"
declare -A alltags
mapfile -t lines < <(metaflac --no-utf8-convert --export-tags-to=- "$if" 2>&-)
for (( z = 0; z < ${#lines[@]}; z++ )); do
line="${lines[${z}]}"
unset -v mflac
mflac[0]="${line%%=*}"
mflac[1]="${line#*=}"
if [[ -z ${mflac[1]} ]]; then
continue
fi
field="${mflac[0],,}"
if [[ -n ${alltags[${field}]} ]]; then
continue
fi
alltags["${field}"]="${mflac[1]}"
done
for field in "${!alltags[@]}"; do
printf '%s\n' "${field}: ${alltags[${field}]}"
done | sort
}
options () {
unset -v track
printf '\n%s\n%s\n\n' '*** BACK (b)' '*** QUIT (q)'
read -p '>'
clear
case "$REPLY" in
'b')
return
;;
'q')
exit
;;
esac
if [[ ! $REPLY =~ $regex_num ]]; then
return
fi
ref="files[${REPLY}]"
if [[ -z ${!ref} ]]; then
return
fi
track="${!ref}"
}
clear
while true; do
printf '\n%s\n\n' '*** CHOOSE TRACK ***'
for (( i = 0; i < ${#files[@]}; i++ )); do
printf '%s) %s\n' "$i" "$(basename "${files[${i}]}")"
done
options
if [[ -z $track ]]; then
continue
fi
gettags "$track"
options
done