Last active
August 18, 2020 20:54
-
-
Save duganchen/95a679320ab53c030996e5f96bdd0c69 to your computer and use it in GitHub Desktop.
Clean duplicate songs from MPD's queue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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