2016-12-23 00:10:40 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Delete all songs that are in the delete-pls playlist, and cleans up any empty folders
|
|
|
|
# it leaves behind.
|
|
|
|
|
2016-12-28 23:39:21 -08:00
|
|
|
set -e
|
|
|
|
|
2017-01-05 22:30:22 -08:00
|
|
|
playlistdir="$(grep playlist_directory $HOME/.config/mpd/mpd.conf | awk '{ print $2; }')"
|
|
|
|
playlistdir="${playlistdir//\"/}"
|
|
|
|
playlistfile="$playlistdir/1-star.m3u"
|
2016-12-23 00:10:40 -08:00
|
|
|
songs=$(<"$playlistfile")
|
|
|
|
|
|
|
|
# Delete designated songs
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
for song in ${songs[@]}; do
|
|
|
|
fpath="$HOME/music/$song"
|
|
|
|
if [[ -f $fpath ]]; then
|
|
|
|
echo "Deleting: $song"
|
|
|
|
rm -f "$fpath"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
:>"$playlistfile"
|
|
|
|
|
2017-01-05 22:30:30 -08:00
|
|
|
# Remove duplicates in playlists
|
|
|
|
for playlist in "$playlistdir"/*.m3u; do
|
|
|
|
awk '!seen[$0]++' "$playlist" > "${playlist}.tmp"
|
|
|
|
if [[ -f "${playlist}.tmp" ]]; then
|
|
|
|
rm -f "$playlist"
|
|
|
|
mv "${playlist}.tmp" "$playlist"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-12-28 23:39:21 -08:00
|
|
|
# Remove empty directories
|
|
|
|
find "$HOME/music" -type d -empty -delete
|