Export playlist without a Spotify account? #102
Replies: 1 comment
-
|
I tested the notebook with the data I obtained from the chosic.com Spotify playlist exporter. Not surprisingly, I had to rename some columns. I also needed to convert track timestamps to milliseconds and convert key and mode pairs to separate columns. The change was fairly simple, though. I could open this as a PR, but I wasn't sure whether anybody would be interested in it. In my limited experience with Python notebooks in GitHub, it can be annoying dealing with the notebook metadata when only changing code. I thought I'd hold off on that until somebody expresses interest. Until then, I'll share my two cells (one text cell and one code) here… '''
## Clean up the data
I used Spotify playlist data obtained via https://www.chosic.com/spotify-playlist-exporter/, because I do not have an account with which to access the Spotify API. Some columns in the CSV data I received are different than what the original author's data contained.
'''
from datetime import datetime
print('Shape of data before:', data.shape)
rowsBefore = data.shape[0]
# Drop the '#' column
data = data.drop('#', axis=1, errors='ignore')
# Remove duplicate rows based on all remaining columns
data = data.drop_duplicates(keep='first').reset_index(drop=True)
print('Shape of data after dropping "#" column and duplicate rows:', data.shape)
print('Rows dropped:', rowsBefore - data.shape[0])
def time_to_milliseconds(time_str):
"""Convert a 'MM:SS' string to milliseconds using datetime."""
if isinstance(time_str, str):
try:
# Parse the time string as MM:SS
time_obj = datetime.strptime(time_str, '%M:%S')
# Calculate total seconds and convert to milliseconds
return (time_obj.minute * 60 + time_obj.second) * 1000
except ValueError:
# Handle potential errors if the format is not strictly MM:SS
return None
return None
data['Duration (ms)'] = data['Time'].apply(time_to_milliseconds)
# Change 'Key' from 'C♯/D♭ Major' to 'C#' and 'Mode' of 'major'
if 'Mode' not in data.columns:
data['Mode'] = data['Key'].apply(lambda x: x.split()[1].lower() if ' ' in x else None)
data['Key'] = data['Key'].apply(lambda x: x.replace('♯', '#').split()[0].split('/')[0])
# Rename columns
data = data.rename(columns={
'Song': 'Track Name',
'Artist': 'Artist Name(s)',
'Album': 'Album Name',
'Album Date': 'Release Date',
'BPM': 'Tempo',
'Loud (Db)': 'Loudness',
# the following columns may need to be converted from
# 0–100 range to 0.0–1.0 range…
'Dance': 'Danceability',
'Acoustic': 'Acousticness',
'Instrumental': 'Instrumentalness',
'Happy': 'Valence',
'Speech': 'Speechiness',
'Live': 'Liveness',
}) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The taste analysis notebook is very intriguing. I was searching for a way to help a low-tech friend export a Spotify playlist so it could be imported elsewhere, like maybe YouTube. I liked the idea of exportify.net, but I don't have a Spotify account. (I also didn't want to put my friend at risk by sharing their account password.) So I wanted a way to get the playlist without signing in. I had two ideas…
So far, I found one other, (https://www.chosic.com/spotify-playlist-exporter/). It exports as CSV or text. I've not tested the CSV with your notebook yet, but it's a start. Maybe there are other websites that do this, too.
I see your
exportify.jsuses Spotify Web API. I guess that's why the user must log in for it to work. That's great for most people, but wouldn't work for me.Without logging into Spotify, I can use their web UI to see my friend's playlist in a browser. I poked around using developers' tools and found that there were many requests back to their own API. For example, some with the URL
https://api-partner.spotify.com/pathfinder/v2/query. By copying those as cURL, I could run them in a shell and get the results as JSON. That's pretty good. I wonder whether there's a way to script that using Userscript.These are only some ideas I had. I will explore your notebook more and see whether it can use the CSV or JSON formats I found.
Beta Was this translation helpful? Give feedback.
All reactions