How many unique tracks have been played on A State of Trance over the years? What's been played the most?
In this post, we'll examine track plays over time.
First, some baseline analysis. Let's first figure out how many tracks played on A State of Trance are available on Spotify:
tracks_counted = 0
for episode in episodes:
try:
for track in sp.album_tracks(episode['uri'])['items']:
if "a state of trance" in track['name'].lower() or "- interview" in track['name'].lower():
continue
else:
tracks_counted += 1
except:
pass
print(tracks_counted)
Wow - 17,000+ total tracks have been played! Remember, as we learned in the "Methodology" post some episodes - especially early ones - are incomplete.
How many unique tracks? Get your regular expressions ready ..
import re
unique_tracks = set()
for episode in episodes:
try:
for track in sp.album_tracks(episode['uri'])['items']:
if "a state of trance" in track['name'].lower() or "- interview" in track['name'].lower():
continue
else:
unique_tracks.add(re.sub("[\(\[].*?[\)\]]", "", track['name'])) # Remove episode numbers from track names (ex. 'Eternity [ASOT 005]')
except:
pass
print(len(unique_tracks))
As always, this is a "best guess" - an approximation.
Let's crunch some numbers.
Which tracks have the most plays?
from collections import defaultdict
tracks_counter = defaultdict(int)
for episode in episodes:
try:
for track in sp.album_tracks(episode['uri'])['items']:
if "a state of trance" in track['name'].lower() or "- interview" in track['name'].lower():
continue
else:
track_artist = track['artists'][0]['name']
if len(track['artists']) > 1:
for artist in track['artists'][1:]:
track_artist += " & " + artist['name']
tracks_counter[track_artist + ' - ' + re.sub("[\(\[].*?[\)\]]", "", track['name'])] += 1
except:
pass
top_tracks = sorted(tracks_counter.items(), key=lambda k_v: k_v[1], reverse=True)
Let's see what we've got!
for track in top_tracks[:25]:
print(track)
In a crude graph:
source = pd.DataFrame.from_dict(top_tracks[:25])
bars = alt.Chart(source).mark_bar().encode(
x=alt.X('1:Q', title='Plays'),
y=alt.Y('0:N', sort='-x', title='Track', axis=alt.Axis(labels=False)),
).properties(
title="A State of Trance - Most-played tracks",
width=500
)
text = alt.Chart(source).mark_text(dx=-350, color='white', align='left').encode(
x=alt.X('1:Q', title='Plays'),
y=alt.Y('0:N', sort='-x'),
text=alt.Text('0:N')
)
bars + text