-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusic.sh
More file actions
executable file
·184 lines (161 loc) · 3.03 KB
/
Copy pathmusic.sh
File metadata and controls
executable file
·184 lines (161 loc) · 3.03 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
LAME_FLAGS="-b 320"
usage() {
cat << EOF
usage: music <command> <dirs>
commands:
filename
music filename <dir>
Check for illegal file/path characters for Windows
mount
music mount <dir>
Mounts a directory to ~/Music/
mpv0
music mpv0 <filename> [<filenames>]
Converts the files to vbr0 mp3
mp320
music mp320 <filename> [<filenames>]
Converts the files to cbr320 mp3
prune
music prune <dir1> [<dirs>]
Remove non-mp3 and empty files and directories
sync
music sync <src1> [<srcs>] <dst>
'rsync -hmrtW --delete-delay --progress'
unicode
music unicode <dir1> [<dirs>]
Find filenames with unicode characters
EOF
}
filename() {
for file in "$@"; do
find "$file" | grep -E --color "\"|<|>|:|\\|\||\?|\*"
done
}
mount() {
local MUSIC=/home/johnhe00/Music
if [ -L "$MUSIC" ]; then
read -p "Link already exists. Replace? [yes/N] " response
case $response in
yes)
rm -i "$MUSIC"
;;
*)
;;
esac
fi
if [ ! -e "$MUSIC" ]; then
if [ -d "$@" ]; then
ln -s "$@" "$MUSIC"
else
printf "$@ doesn't exist\n"
fi
fi
}
mpv0() {
LAME_FLAGS="-V 0"
mp3 "$@"
}
mp3() {
for file in "$@"; do
if [[ -d "$file" ]]; then
printf "$file is a directory\n"
continue
fi
newfile="${file%.*}.mp3"
if [[ -e $newfile ]]; then
printf "$newfile already exists\n"
continue
fi
mime=$(file --mime-type -b "$file")
case $mime in
audio/x-flac)
flac -cds "$file" | lame $LAME_FLAGS - "$newfile"
;;
audio/x-wav)
lame $LAME_FLAGS "$file" "$newfile"
;;
*)
printf "$file has an incompatible mime: $mime\n"
;;
esac
done
}
mp320() {
LAME_FLAGS="-b 320"
mp3 "$@"
}
prune() {
for file in "$@"; do
find "$file" -type f -not -iname "*.mp3"
done
read -p "Delete? [yes/N] " response
case $response in
yes)
for file in "$@"; do
find "$file" -type f -not -iname "*.mp3" -exec rm {} \;
done
for file in "$@"; do
find "$file" -empty -exec rmdir {} \;
done
;;
*)
printf "Aborting ...\n"
;;
esac
}
sync() {
local DRY="rsync -himnrt"
local WET="rsync -hmrtW --delete-delay --progress"
$DRY "$@"
read -p "Execute? [yes/N] " response
case $response in
yes)
$WET "$@"
;;
*)
printf "Aborting ...\n"
;;
esac
}
unicode() {
for file in "$@"; do
find "$file" | grep --color -P "[^[:ascii:]]"
done
}
main() {
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
local COMMAND=$1
shift
case $COMMAND in
filename)
filename "$@"
;;
mount)
mount "$@"
;;
mpv0)
mpv0 "$@"
;;
mp320)
mp320 "$@"
;;
prune)
prune "$@"
;;
sync)
sync "$@"
;;
unicode)
unicode "$@"
;;
*)
printf "unrecognized command: $COMMAND\n"
usage
;;
esac
}
main "$@"