Skip to content

Instantly share code, notes, and snippets.

@tinbotu
Created April 22, 2024 04:45
Show Gist options
  • Select an option

  • Save tinbotu/2a5e8f1a1a910fd450dbc2be382e671e to your computer and use it in GitHub Desktop.

Select an option

Save tinbotu/2a5e8f1a1a910fd450dbc2be382e671e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------\n",
"Lizzo - About Damn Time\n",
"Preview: https://p.scdn.co/mp3-preview/bbf8a26d38f7d8c7191dd64bd7c21a4cec8b61a0?cid=10e40b52051b4668b3d9ebbc8968a2ec\n",
"[\n",
" {\n",
" \"time_signature\": 4,\n",
" \"id\": \"1PckUlxKqWQs3RlWXVBLw3\",\n",
" \"acousticness\": 0.0995,\n",
" \"danceability\": 0.836,\n",
" \"loudness\": -6.305,\n",
" \"valence\": 0.722,\n",
" \"duration_ms\": 191822,\n",
" \"analysis_url\": \"https://api.spotify.com/v1/audio-analysis/1PckUlxKqWQs3RlWXVBLw3\",\n",
" \"type\": \"audio_features\",\n",
" \"key\": 10,\n",
" \"mode\": 0,\n",
" \"uri\": \"spotify:track:1PckUlxKqWQs3RlWXVBLw3\",\n",
" \"speechiness\": 0.0656,\n",
" \"tempo\": 108.966,\n",
" \"energy\": 0.743,\n",
" \"instrumentalness\": 0,\n",
" \"liveness\": 0.335,\n",
" \"track_href\": \"https://api.spotify.com/v1/tracks/1PckUlxKqWQs3RlWXVBLw3\"\n",
" }\n",
"]\n",
"-------------------\n",
"Tipographica - フレンズ (Friends)\n",
"Preview: https://p.scdn.co/mp3-preview/e5b9dfbe0bafdc8123a402a78d8de66e0d3e6135?cid=10e40b52051b4668b3d9ebbc8968a2ec\n",
"[\n",
" {\n",
" \"time_signature\": 4,\n",
" \"id\": \"46GDbPYiYSc1Ag4og8DTUr\",\n",
" \"acousticness\": 0.00123,\n",
" \"danceability\": 0.487,\n",
" \"loudness\": -11.342,\n",
" \"valence\": 0.696,\n",
" \"duration_ms\": 534000,\n",
" \"analysis_url\": \"https://api.spotify.com/v1/audio-analysis/46GDbPYiYSc1Ag4og8DTUr\",\n",
" \"type\": \"audio_features\",\n",
" \"key\": 9,\n",
" \"mode\": 1,\n",
" \"uri\": \"spotify:track:46GDbPYiYSc1Ag4og8DTUr\",\n",
" \"speechiness\": 0.0883,\n",
" \"tempo\": 97.309,\n",
" \"energy\": 0.543,\n",
" \"instrumentalness\": 0.627,\n",
" \"liveness\": 0.096,\n",
" \"track_href\": \"https://api.spotify.com/v1/tracks/46GDbPYiYSc1Ag4og8DTUr\"\n",
" }\n",
"]\n",
"-------------------\n",
"Dorian Concept - Promises\n",
"Preview: https://p.scdn.co/mp3-preview/50282c05925c881ead8e3e763f8f1a613db4f493?cid=10e40b52051b4668b3d9ebbc8968a2ec\n",
"[\n",
" {\n",
" \"time_signature\": 1,\n",
" \"id\": \"7AOE6W4OwFEjbeD0hExnvq\",\n",
" \"acousticness\": 0.385,\n",
" \"danceability\": 0.621,\n",
" \"loudness\": -9.347,\n",
" \"valence\": 0.323,\n",
" \"duration_ms\": 237064,\n",
" \"analysis_url\": \"https://api.spotify.com/v1/audio-analysis/7AOE6W4OwFEjbeD0hExnvq\",\n",
" \"type\": \"audio_features\",\n",
" \"key\": 10,\n",
" \"mode\": 0,\n",
" \"uri\": \"spotify:track:7AOE6W4OwFEjbeD0hExnvq\",\n",
" \"speechiness\": 0.0685,\n",
" \"tempo\": 124.056,\n",
" \"energy\": 0.675,\n",
" \"instrumentalness\": 0.0337,\n",
" \"liveness\": 0.347,\n",
" \"track_href\": \"https://api.spotify.com/v1/tracks/7AOE6W4OwFEjbeD0hExnvq\"\n",
" }\n",
"]\n",
"-------------------\n",
"Chick Corea Akoustic Band - Morning Sprite - Live\n",
"Preview: None\n",
"[\n",
" {\n",
" \"time_signature\": 4,\n",
" \"id\": \"0Rlo0wutXR42FL3RVvO9MC\",\n",
" \"acousticness\": 0.274,\n",
" \"danceability\": 0.393,\n",
" \"loudness\": -21.322,\n",
" \"valence\": 0.652,\n",
" \"duration_ms\": 614960,\n",
" \"analysis_url\": \"https://api.spotify.com/v1/audio-analysis/0Rlo0wutXR42FL3RVvO9MC\",\n",
" \"type\": \"audio_features\",\n",
" \"key\": 1,\n",
" \"mode\": 0,\n",
" \"uri\": \"spotify:track:0Rlo0wutXR42FL3RVvO9MC\",\n",
" \"speechiness\": 0.0385,\n",
" \"tempo\": 139.434,\n",
" \"energy\": 0.462,\n",
" \"instrumentalness\": 0.579,\n",
" \"liveness\": 0.704,\n",
" \"track_href\": \"https://api.spotify.com/v1/tracks/0Rlo0wutXR42FL3RVvO9MC\"\n",
" }\n",
"]\n"
]
}
],
"source": [
"import json\n",
"import spotipy\n",
"from spotipy.oauth2 import SpotifyClientCredentials\n",
"\n",
"spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret))\n",
"spotify_uris = ['spotify:track:1PckUlxKqWQs3RlWXVBLw3', 'spotify:track:46GDbPYiYSc1Ag4og8DTUr', 'spotify:track:7AOE6W4OwFEjbeD0hExnvq', 'spotify:track:0Rlo0wutXR42FL3RVvO9MC', ]\n",
"\n",
"for uri in spotify_uris:\n",
" track = spotify.track(uri)\n",
" features = spotify.audio_features(uri)\n",
" print(\"-------------------\\n%s - %s\" % (track[\"artists\"][0][\"name\"], track[\"name\"]))\n",
" print(\"Preview: %s\" % track[\"preview_url\"])\n",
" print(json.dumps(features, indent=2))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment