Created
February 15, 2015 19:32
-
-
Save Birch-san/361cfda8ec75dabd7be1 to your computer and use it in GitHub Desktop.
Delete duplicate entries from Google Play Music user playlist
This file contains 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
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 protected]', '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