Reputation: 1618
I'm doing a university project on Data Analysis, in particular, I'm trying to analyze the behavior of listeners on Spotify before and during the pandemic.
So far I downloaded the top 200 weekly and grouped it by states with a simple script, you can finde the data here: https://spotifycharts.com/regional
I also managed to use those top 200 to retrieve each song and extract features, release date ecc... using the Spotify API.
I read this article: Spotify genre trends during pandemic which is pretty interesting. I would like to emulate what they're doing in the article. For example, they're able to retrieve the top 100 artist by genre.
I've been looking around the Spotify API and Spotify available datasets, but I can't find a solution to achieve my goal.
Is there a way to retrieve the top 100 artist by genre in a given period?
This is the code I used to download the top 200 weekly, but it's no use for my goal:
import requests
import os
import time
path = os.getcwd()
states = ['br','it','gb','de','us','fr','es']
for state in states:
dir_path = os.path.join(path, state)
os.mkdir(dir_path)
for week in weeks:
csv_url = 'https://spotifycharts.com/regional/'+state+'/weekly/'+week+'/download'
req = requests.get(csv_url)
#print(req.status_code)
time.sleep(0.5)
if req.status_code == 200:
url_content = req.content
csv = ''+state+'_'+week+'.csv'
csv_path = os.path.join(dir_path, csv)
csv_file = open(csv_path, 'wb')
csv_file.write(url_content)
csv_file.close()
else:
print('error with the following file:'+str(csv_url))
Where weeks
is a list of strings containing the filename of the file to be downloaded in the request (previously generated with another code, omitting it for sake of clarity), for example:
2016-12-23--2016-12-30
2016-12-30--2017-01-06
2017-01-06--2017-01-13
2017-01-13--2017-01-20
2017-01-20--2017-01-27
2017-01-27--2017-02-03
2017-02-03--2017-02-10
2017-02-10--2017-02-17
Upvotes: 2
Views: 5586
Reputation: 543
The blog states
we collected MLs data for the Top 100 artists of each genre, ranked by Spotify Follower count.
Getting charts directly from the official Spotify Web API is not possible. Chartmetric, the company that wrote the blog has probably a scraping algorithm that they will not disclose as it is their business model to sell these stats.
The Spotify Web API Artists endpoint gives you the genres
of an artist (and their number of followers) so if you get Artists charts from another source (with their Spotify ID), you could potentially extract each artist genres and re-rank the Artists within each genre. These genres would probably need to be re-classified according to your needs.
This repo uses the Search endpoint with just a data range as the main query parameter (here: year:2000-2014
) and creates a database of Most followed artists with their corresponding Spotify ID. This hack doesn't seem to be working anymore as I don't necessarily get ranked result when I try with my own auth Token.
Then to get the Monthly Listeners (ML), the blog mentions the Spotify for Artist page. Which states:
Monthly listeners are unique listeners who play your music during a 28-day period. This stat updates every day, and appears on both your artist profile on Spotify
Again, this figure is not available from the Spotify API so you would either need to create an Artist page and use the comparison option to get it for other artists or scrape this figure on a daily basis on the regular Spotify platform.
Upvotes: 4