From a8f5fbff1444ea841e716a42dfaa43a24c421784 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 6 Jan 2017 01:30:30 -0500 Subject: [PATCH] shell/mpd/bin/cleanup-music.sh: remove duplicates in playlists --- shell/mpd/bin/cleanup-music.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shell/mpd/bin/cleanup-music.sh b/shell/mpd/bin/cleanup-music.sh index 66f3c985..48957c9b 100755 --- a/shell/mpd/bin/cleanup-music.sh +++ b/shell/mpd/bin/cleanup-music.sh @@ -22,5 +22,14 @@ for song in ${songs[@]}; do done :>"$playlistfile" +# 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 + # Remove empty directories find "$HOME/music" -type d -empty -delete