Skip to content

Instantly share code, notes, and snippets.

@hfs
Created December 19, 2017 20:06
Show Gist options
  • Save hfs/1b7c120c07ce63cd9105ed59788a6915 to your computer and use it in GitHub Desktop.
Save hfs/1b7c120c07ce63cd9105ed59788a6915 to your computer and use it in GitHub Desktop.
Remove duplicates (by file path) from the MPD playlist
#!/bin/sh
# Remove duplicates from MPD playlist.
# Export MPD_HOST and MPD_PORT if you want to connect to a different host.
mpc playlist -f '%position%\t%file%' | sort -k 2 | perl -ne 'm/(.*)\t(.*)/; print "$1\n" if $2 eq $prev; $prev=$2' | mpc del
@neeasade
Copy link

an alternative:

  duplicates=$(mpc playlist -f '%position% %file%' | sort -k2 | uniq -f1 -d)
  while [ ! -z "$duplicates" ]; do
    echo "$duplicates" | sed 's/ .*//' | mpc del
    duplicates=$(mpc playlist -f '%position% %file%' | sort -k2 | uniq -f1 -d)
  done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment