-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyrics_editor
60 lines (50 loc) · 1.18 KB
/
lyrics_editor
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
#!/bin/zsh
# Copyright 2017-2018 Han Boetes <han@boetes.org>
# For license info see http://unlicense.org/
# Check for dependencies.
for i in exiftool metaflac glyrc; do
if ! command -v $i >& /dev/null; then
faileddep=true
echo "I need $i, please install it."
fi
done
if [[ $faileddep == true ]]; then
exit 1
fi
searchstring="$1"
readtag ()
{
exiftool -q -q -p '$LYRICS' $1 > "${1}.txt"
}
write_flac_lyrics()
{
metaflac --remove-tag=lyrics "$1"
metaflac --set-tag-from-file="lyrics=${1}.txt" "$1"
}
write_mp3_lyrics()
{
eyeD3 --remove-all-lyrics "$1"
eyeD3 --add-lyrics "${1}.txt" "$1"
}
for i in *.(mp3|flac); do
readtag "$i"
if [[ -z $searchstring ]]; then
$EDITOR "${i}.txt"
else
sed -i -n "/$searchstring/q;p" "${i}.txt"
fi
# Strip trailing whitespace.
sed -i 's|[[:space:]]*$||' "${i}.txt"
dos2unix "${i}.txt"
# remove leading and trailing empty lines.
sed -i -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' "${i}.txt"
case $i in
*.flac)
write_flac_lyrics "$i"
;;
*.mp3)
write_mp3_lyrics "$i"
;;
esac
rm -f -- "${i}.txt"
done