Created
November 20, 2023 02:52
-
-
Save rivermont/3f3a11320930626af7b7e76343b2065c to your computer and use it in GitHub Desktop.
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 | |
""" | |
Print the tracks missing from one Spotify playlist to another. | |
Requires Playlist1.json from Spoify user data download. | |
Will Bennett (rivermont) 2023 | |
""" | |
import json | |
def playlist_diff(list1, list2, data): | |
for playlist in data['playlists']: | |
if playlist['name'] == list1: | |
list1_tracks = playlist['items'] | |
elif playlist['name'] == list2: | |
list2_tracks = playlist['items'] | |
list1_tracks = set([i['track']['trackName']+i['track']['artistName'] for i in list1_tracks]) | |
list2_tracks = set([i['track']['trackName']+i['track']['artistName'] for i in list2_tracks]) | |
return list(list1_tracks - list2_tracks) | |
if __name__ == '__main__': | |
playlist1 = 'Playlist title 1' | |
playlist2 = 'Playlist title 2' | |
target = 'Playlist1.json' | |
with open(target, 'r') as file_: | |
diff = playlist_diff(playlist1, playlist2, json.load(file_)) | |
print(json.dumps(diff, indent=4, sort_keys=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment