Skip to content

Instantly share code, notes, and snippets.

@vool
Last active November 15, 2019 12:03
Show Gist options
  • Save vool/c8955de42191d168b7f40414e855a83d to your computer and use it in GitHub Desktop.
Save vool/c8955de42191d168b7f40414e855a83d to your computer and use it in GitHub Desktop.
This script exports a spotify playlist as list
Artist Track Album
Ezra Collective Space is the Place You Can't Steal My Joy
Kamaal Williams, Henry Wu Medina The Return
Ezra Collective The Philosopher Juan Pablo: The Philosopher
Ezra Collective, Loyle Carner What Am I to Do? You Can't Steal My Joy
Yussef Kamaal Joint 17 Black Focus
Kamaal Williams, Henry Wu High Roller The Return
Yussef Kamaal Black Focus Black Focus
Tenderlonious, The 22archestra Yussef's Groove The Shakedown
Joe Armon-Jones Almost Went Too Far Starting Today
Ruby Rushton Triceratops / The Caller Ironside
Nubya Garcia Lost Kingdoms Nubya's 5ive
Yussef Dayes, Alfa Mist, Mansur Brown Love Is the Message Love Is the Message
Ruby Rushton Moonlight Woman Trudi's Songbook, Vol. 1
Moses Boyd Rye Lane Shuffle Displaced Diaspora
Yazmin Lacey 90 Degrees 90 Degrees
Mansur Brown Mashita Shiroi
Nérija, Nubya Garcia, Shirley Tetteh, Cassie Kinoshi, Sheila Maurice-Grey, Rosie Turton The Fisherman NÉRIJA EP
Shabaka and the Ancestors, Shabaka Hutchings Joyous Wisdom of Elders
Kamaal Williams, Darkhouse Family New Heights (Visions of Aisha Malik) New Heights / Snitches Brew
Alfa Mist, Kaya Thomas-Dyke Breathe Antiphon
Shabaka Hutchings Black Skin, Black Masks We out Here
Yazmin Lacey Black Moon Black Moon
Tenderlonious, The 22archestra Expansions The Shakedown
Robohands Green Green
Kaidi Tatham Bien It's a World Before You
Kamaal Williams, Henry Wu Salaam The Return
KOKOROKO Abusey Junction KOKOROKO
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import sys\n",
"import spotipy\n",
"import spotipy.util as util\n",
"from tabulate import tabulate\n",
"from IPython.core.display import display, HTML"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#set playlist\n",
"playlist_id = '5ISdEZ20dPsajdxW8MPzcO'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#set user\n",
"username ='xxxxxxx'\n",
"\n",
"#set key & secret\n",
"c_id = 'xxxxxxx'\n",
"c_secret= 'xxxxxxx'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#set scope\n",
"scope = 'playlist-read-collaborative'\n",
"\n",
"#get token\n",
"token = util.prompt_for_user_token(username,scope,client_id=c_id,client_secret=c_secret,redirect_uri='http://localhost') \n",
"\n",
"if token:\n",
" sp = spotipy.Spotify(auth=token)\n",
"else:\n",
" print(\"Can't get token for\", username)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Title -> UK Jazz\n",
"Owner -> c_doubleyou\n",
"29 tracks in playlist\n"
]
}
],
"source": [
"#read playlist\n",
"tracks = []\n",
"\n",
"res = sp.user_playlist(None, playlist_id , 'fields=tracks.items(track(name,href,album(name,href)))')\n",
"\n",
"print('Title -> '+res['name'])\n",
"\n",
"print('Owner -> '+res['owner']['display_name'])\n",
"\n",
"print(\"%d tracks in playlist\" %(len(res['tracks']['items'])))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"#get tracks\n",
"for item in res['tracks']['items']:\n",
" \n",
" artists = []\n",
" \n",
" for artist in item['track']['artists']:\n",
" artists.append(artist['name'])\n",
" \n",
" artist = \", \".join(artists)\n",
" name = item['track']['name']\n",
" album = item['track']['album']['name']\n",
"\n",
" tracks.append((artist, name, album))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<thead>\n",
"<tr><th>Artist </th><th>Track </th><th>Album </th></tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr><td>Ezra Collective </td><td>Space is the Place </td><td>You Can't Steal My Joy </td></tr>\n",
"<tr><td>Kamaal Williams, Henry Wu </td><td>Medina </td><td>The Return </td></tr>\n",
"<tr><td>Ezra Collective </td><td>The Philosopher </td><td>Juan Pablo: The Philosopher</td></tr>\n",
"<tr><td>Ezra Collective, Loyle Carner </td><td>What Am I to Do? </td><td>You Can't Steal My Joy </td></tr>\n",
"<tr><td>Yussef Kamaal </td><td>Joint 17 </td><td>Black Focus </td></tr>\n",
"<tr><td>Kamaal Williams, Henry Wu </td><td>High Roller </td><td>The Return </td></tr>\n",
"<tr><td>Yussef Kamaal </td><td>Black Focus </td><td>Black Focus </td></tr>\n",
"<tr><td>Tenderlonious, The 22archestra </td><td>Yussef's Groove </td><td>The Shakedown </td></tr>\n",
"<tr><td>Joe Armon-Jones </td><td>Almost Went Too Far </td><td>Starting Today </td></tr>\n",
"<tr><td>Ruby Rushton </td><td>Triceratops / The Caller </td><td>Ironside </td></tr>\n",
"<tr><td>Nubya Garcia </td><td>Lost Kingdoms </td><td>Nubya's 5ive </td></tr>\n",
"<tr><td>Yussef Dayes, Alfa Mist, Mansur Brown </td><td>Love Is the Message </td><td>Love Is the Message </td></tr>\n",
"<tr><td>Ruby Rushton </td><td>Moonlight Woman </td><td>Trudi's Songbook, Vol. 1 </td></tr>\n",
"<tr><td>Moses Boyd </td><td>Rye Lane Shuffle </td><td>Displaced Diaspora </td></tr>\n",
"<tr><td>Yazmin Lacey </td><td>90 Degrees </td><td>90 Degrees </td></tr>\n",
"<tr><td>Vels Trio </td><td>Godzilla </td><td>Yellow Ochre EP </td></tr>\n",
"<tr><td>Mansur Brown </td><td>Mashita </td><td>Shiroi </td></tr>\n",
"<tr><td>Nérija, Nubya Garcia, Shirley Tetteh, Cassie Kinoshi, Sheila Maurice-Grey, Rosie Turton</td><td>The Fisherman </td><td>NÉRIJA EP </td></tr>\n",
"<tr><td>Shabaka and the Ancestors, Shabaka Hutchings </td><td>Joyous </td><td>Wisdom of Elders </td></tr>\n",
"<tr><td>Kamaal Williams, Darkhouse Family </td><td>New Heights (Visions of Aisha Malik)</td><td>New Heights / Snitches Brew</td></tr>\n",
"<tr><td>Alfa Mist, Kaya Thomas-Dyke </td><td>Breathe </td><td>Antiphon </td></tr>\n",
"<tr><td>Shabaka Hutchings </td><td>Black Skin, Black Masks </td><td>We out Here </td></tr>\n",
"<tr><td>Mammal Hands </td><td>Kandaiki </td><td>Animalia </td></tr>\n",
"<tr><td>Yazmin Lacey </td><td>Black Moon </td><td>Black Moon </td></tr>\n",
"<tr><td>Tenderlonious, The 22archestra </td><td>Expansions </td><td>The Shakedown </td></tr>\n",
"<tr><td>Robohands </td><td>Green </td><td>Green </td></tr>\n",
"<tr><td>Kaidi Tatham </td><td>Bien </td><td>It's a World Before You </td></tr>\n",
"<tr><td>Kamaal Williams, Henry Wu </td><td>Salaam </td><td>The Return </td></tr>\n",
"<tr><td>KOKOROKO </td><td>Abusey Junction </td><td>KOKOROKO </td></tr>\n",
"</tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#output track table\n",
"headers = ('Artist', 'Track', 'Album')\n",
"\n",
"display(HTML(tabulate(tracks, headers, tablefmt='html')))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment