Skip to content

Instantly share code, notes, and snippets.

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 Birch-san/361cfda8ec75dabd7be1 to your computer and use it in GitHub Desktop.
Save Birch-san/361cfda8ec75dabd7be1 to your computer and use it in GitHub Desktop.
Delete duplicate entries from Google Play Music user playlist
from gmusicapi import Mobileclient
# Get gmusicapi: https://github.com/simon-weber/Unofficial-Google-Music-API
# This script iterates through all your playlists, and deletes any playlist entries that
# have a duplicate later on in the same playlist.
api = Mobileclient()
logged_in = api.login('email@sharklasers.com', 'nice try :P')
playlists = api.get_all_user_playlist_contents()
leading_dupes = []
for playlist in playlists:
entries = playlist['tracks']
def have_i_dupe_ahead(entry, entries, idx):
for t in entries[(idx+1):]:
if entry['trackId'] == t['trackId']:
return True
return False
for idx, entry in enumerate(entries):
isdupe = have_i_dupe_ahead(entry, entries, idx)
if isdupe:
leading_dupes.append(entry)
entry_ids = [entry['id'] for entry in leading_dupes]
api.remove_entries_from_playlist(entry_ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment