-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpdignore.sh
executable file
·42 lines (30 loc) · 1.46 KB
/
mpdignore.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
#!/bin/bash
scriptname=$(realpath "$0")
. /usr/local/bin/editscript
. mpdignore.functions
[[ ! "$musicdir" ]] && getmpdmusicdir
[[ ! "$mpdpldir" ]] && getmpdpldir
[[ ! "$mpdlog" ]] && getmpdlog
watchpath="$mpdpldir/$watchfile" # sets full path of watchfile
ignoredpath="$mpdpldir/$ignoredm3u" # sets full path of ignoredm3u
while read -r line; do
song="${line##*/}"
songdir="${line%/*}"
ignoredir="$musicdir/$songdir"
if [[ -f "$ignoredir"/.mpdignore ]]; then
cp "$ignoredir"/.mpdignore "$ignoredir"/.mpdignore~
fi
if [[ "$song" =~ \[ ]] || [[ "$song" =~ \] ]] || [[ "$song" =~ \\ ]]; then
song=$(echo "$song" | -e 's/\\\([^\\]\)/\\\\\1/g' sed -e 's/\[/\\[/g' -e 's/\]/\\]/g')
fi
printf "%s\n# added on %s\n" "$song" "$(date)" >> "$ignoredir"/.mpdignore
printf '%s has been added to .mpdignore in %s\n' "$song" "$ignoredir"
printf '%s\n' "$line" >> "$ignoredpath"
printf '%s\n' "$(date '+%b %d %H:%M : player: ignored ')\"$line\"" | cat >> "$mpdlog"
done < "$watchpath"
printf '#last run %s\n' "$(date)" >> "$ignoredpath"
#: > "$watchpath" # clears the watchfile after run
#
#chmod g+w "$ignoredir"/.mpdignore "$ignoredpath" "$watchpath" # grants group access to the watchfile, ignoredm3u, and the created/updated .mpdignore file
#chown "$mpduser":"$mpdgroup" "$ignoredir"/.mpdignore "$ignoredpath" "$watchpath" # changes ownership of the above files to mpd and its goup (e.g., so the ignored playlist is readable by mpd)
rm "$watchpath"