Last active
May 23, 2024 10:52
-
-
Save Luuk3333/2dfae8ad0960569afa993f8382e7244d to your computer and use it in GitHub Desktop.
Calculates your most skipped Spotify songs
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
import json | |
import os | |
# | |
# Place this script in spotify data request > MyData directory. | |
# | |
THRESHOLD = 3000 # time in milliseconds to determine a 'skip' | |
AMOUNT = 100 # amount of skipped tracks to display | |
total_count = 0 | |
data = {} | |
part = 0 | |
while True: | |
filename = 'StreamingHistory{}.json'.format(part) | |
if not os.path.isfile(filename): | |
print('Read {} history json files.'.format(part+1)) | |
break | |
part = part + 1 | |
with open(filename, 'r', encoding='utf-8') as myfile: | |
jsondata=myfile.read() | |
items = json.loads(jsondata) | |
for item in items: | |
if item['msPlayed'] < THRESHOLD: | |
slug = item['artistName'] + item['trackName'] | |
if slug in data: | |
data[slug]['count'] = data[slug]['count'] + 1 | |
else: | |
data[slug] = { | |
'artist': item['artistName'], | |
'track': item['trackName'], | |
'count': 1 | |
} | |
total_count = total_count + 1 | |
print('\nTracks listened:', total_count) | |
print('Unique tracks: ', len(data)) | |
print('\nSkipped tracks:') | |
# Convert to list | |
l = [] | |
for k, v in data.items(): | |
l.append(v) | |
# Sort by count | |
sort = sorted(l, key=lambda k: k['count'], reverse=True) | |
for index, item in enumerate(sort[:AMOUNT]): | |
print('#{} {} - {} ({}x)'.format(index+1, item['artist'], item['track'], item['count'])) | |
# print('{} - {}'.format(item['artist'], item['track'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made a new revision of your script to have more control over te result and a little more documentation. Not really good in python, but this seems to work as intended: