-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpdignore.nfo
80 lines (63 loc) · 3.42 KB
/
mpdignore.nfo
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
##Mon Mar 25 02:56:55 PM EDT 2024 NB: I have no idea when this was written or how accurate it still is. A lot of this is generally still applicable as an outline for how this was designed.
#beyond that, I'm not sure how much of this is relevant.
First, place mpdignore.sh in /usr/local/sbin
mpdignore.sh:
#!/bin/bash
pldir="/var/lib/mpd/playlists" # defines playlist directory; default = /var/lib/mpd/playlists
watchfile=".mpdignore.m3u" # defines the watched playlist; default = .mpdignore.m3u
mpdconf="/etc/mpd.conf" # defines mpd.conf location; default = /etc/mpd.conf
mpduser="mpd" # defines the user mpd service runs as; default = mpd
mpdgroup="media" # defines the group mpd service runs as; default = media
ignoredm3u="mpdignored.m3u" # defines the playlist of songs ignored by mpdignore; default = mpdignored.m3u
watchfile="$pldir/$watchfile" # sets full path of watchfile
ignoredm3u="$pldir/$ignoredm3u" # sets full path of ignoredm3u
if [[ -f "$mpdconf" ]] # defines the location of your mpd music directory; this is defined in the mpd.conf file found at /etc/mpd.conf by default
then
musicdir="$(grep -v "^#" "$mpdconf" | grep -v "^$" | grep music_directory)"
musicdir="${musicdir%*\"}"
musicdir="${musicdir#*\"}"
musicdir="${musicdir%/}"
else
musicdir="/library/music" # manually code the location if /etc/mpd.conf doesn't exist.
fi
while read -r line
do
song="${line##*/}"
songdir="${line%/*}"
ignoredir="$musicdir/$songdir"
if [[ -f "$ignoredir"/.mpdignore ]]
then
cp "$ignoredir"/.mpdignore "$ignoredir"/.mpdignore~
fi
printf '%s\n' "$song" "# added on `date`" >> "$ignoredir"/.mpdignore
printf '%s has been added to .mpdignore in %s\n' "$song" "$ignoredir"
printf '%s\n' "$line" >> "$ignoredm3u"
done < "$watchfile"
echo "#lastrun/`date`" >> "$ignoredm3u"
> "$watchfile" # clears the watchfile after run
chmod g+w "$ignoredir"/.mpdignore "$ignoredm3u" "$watchfile" # grants group access to the watchfile, ignoredm3u, and the created/updated .mpdignore file
chown "$mpduser":"$mpdgroup" "$ignoredir"/.mpdignore "$ignoredm3u" "$watchfile" # changes ownership of the above files to mpd and its goup (e.g., so the ignored playlist is readable by mpd)
#####################################################################################################################
Next, create /etc/systemd/system/mpdignore.service:
#mpdignore.service
[Unit]
Description=Creates and updates .mpdignore files in music directories when songs are added to /var/lib/mpd/playlists/.mpdignore.mp3 via mpd client.
Requires=
[Service]
Type=oneshot
# Set ExecStart to location of mpdigore.sh script, e.g., /usr/local/sbin/mpdignore.sh
ExecStart=/usr/local/sbin/mpdignore.sh
[Install]
Also=mpdignore.path
#####################################################################################################################
Next, create /etc/systemd/system/mpdignore.path:
#mpdignore.path
[Install]
WantedBy=paths.target
[Path]
PathChanged=/var/lib/mpd/playlists/.mpdignore.m3u
#####################################################################################################################
Set file ownership:
sudo chown root:root /usr/local/sbin/mpdignore.sh /etc/systemd/system/mpdignore.path /etc/systemd/system/mpdignore.service && sudo chmod u+x /usr/local/sbin/mpdignore.sh
Finally
sudo systemctl enable mpdignore.path && sudo systemctl start mpdignore.path && sudo systemctl status mpdignore.path