-
Notifications
You must be signed in to change notification settings - Fork 0
/
reviewdir.sh
91 lines (82 loc) · 2.72 KB
/
reviewdir.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
#!/bin/bash
cpdir=
if [ $# -lt 1 ]; then
echo "Please specify directory to load music from"
exit 1
elif [ ! -d "$(realpath "$1")" ]; then
echo "Invalid location $1: not a directory."
exit 1
elif [ $# -gt 1 ]; then
if [ -d "$(realpath "$2")" ]; then
cpdir="$(realpath "$2")"
echo "Backup directory set to: $cpdir"
else
echo "Backup dir $2 invalid."
fi
fi
dir="$(realpath "$1")"
cmus-remote -C "clear"
cmus-remote -C "add $dir"
cmus-remote -p
tmpfile=$(mktemp)
#note: because it returns track currently under cursor,
# $(cmus-remote -C win-sel-cur 'echo {}') is not as reliable as 'file' field in cmus-remote -Q output
_filename () {
cmus-remote -Q > $tmpfile # dump current song info query outputn
field=$(grep "^file " "$tmpfile") # retrieve file name of current track
echo ${field#file }
}
echoboxed () {
echo -en "│ $1"
[ $# -lt 2 ] && echo && return
# sequence goes to <last parameter> - <length of first parameter> + 1
for j in $(seq $(( ${!#} - ${#1} + 1 ))); do echo -n ' '; done
echo │
}
latest=
while true; do
cmus-remote -C "view sorted"
[ "$latest" = "$(_filename)" ] && cmus-remote -n
curfile=$(_filename)
ta=$(sed -n 's/^tag artist \(.*\)$/\1/pg' $tmpfile)
tt=$(sed -n 's/^tag title \(.*\)$/\1/pg' $tmpfile)
# do some fun to look at output stuff
twid=$(( $(tput cols)-4 )) # terminal width
mp3info="$ta - $tt" # echo some ID3 tags from current MP3
fileinfo="$(basename "$curfile")"
flocinfo="${curfile%${fileinfo}}"
flocinfo="${flocinfo#${dir}}"
# determine width of output bounding box:
hdw=$(echo -en "70\n${#mp3info}\n${#fileinfo}\n${#flocinfo}" | sort -n | tail -1) # compute minimal width
hdw=$(echo $(( $twid < $hdw ? $twid : $hdw ))) # compute max width (terminal width)
# begin bounding box
echo -n ┌ ;for j in $(seq $hdw); do echo -n "─"; done && echo ──┐
echoboxed "$mp3info" $hdw
echoboxed "$fileinfo" $hdw
echoboxed "$flocinfo" $hdw
echo -n ├ && for j in $(seq $hdw); do echo -n "─"; done && echo ──┤
prompt="> What to do? [K]eep/[d]elete/[m]odify$([ -n "$cpdir" ]&&echo /[c]opy) > "
echoboxed "$prompt" $hdw
# move cursor to right position
tput cuu1; tput cuf $(( ${#prompt} + 2))
read i
if [ "$i" = "d" ]; then
echoboxed "> removing $(basename "$curfile")" $hdw
rm "$curfile"
elif [ "$i" = "q" ]; then
exit 0
elif [ "$i" = "m" ]; then
echo -n "> Input ID3 tags like this: <Artist> - <Title>: "
read tags
ta=$(echo $tags | cut -d- -f 1)
tt=$(echo $tags | cut -d- -f 2-)
eyeD3 -l LEVEL:error -a "$ta" -t "$tt" "$curfile"
elif [ "$i" = "c" ]; then
if [ -n "$cpdir" ]; then
echoboxed "> Copying $(basename "$curfile")..." $hdw
cp "$curfile" "$cpdir"
fi
fi
echo -n └; for j in $(seq $hdw); do echo -n "─"; done && echo ──┘
latest=$curfile
done