Skip to content

Instantly share code, notes, and snippets.

@duganchen
Last active August 18, 2020 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duganchen/95a679320ab53c030996e5f96bdd0c69 to your computer and use it in GitHub Desktop.
Save duganchen/95a679320ab53c030996e5f96bdd0c69 to your computer and use it in GitHub Desktop.
Clean duplicate songs from MPD's queue.
#!/usr/bin/env python3
# Dependencies:
# pip install python-musicpd
import musicpd
import collections
def main():
client = musicpd.MPDClient()
client.connect()
dupes = collections.defaultdict(list)
for song in client.playlistinfo():
dupes[song["file"]].append(song["id"])
if all(len(duped) == 1 for duped in dupes.values()):
return
client.command_list_ok_begin()
for duped in dupes.values():
for songid in duped[1:]:
client.deleteid(songid)
client.command_list_end()
client.disconnect()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment