From 5b7e85267f7941830759d59e10bf1c48d4db13d8 Mon Sep 17 00:00:00 2001 From: Alton Liew Date: Fri, 8 Dec 2023 04:39:27 +0100 Subject: [PATCH] feat(Spotify): Get artist's top 10 tracks Get artist's top 10 tracks just like you would when you visit an artist's page on Spotify. --- Spotify/Spotify_Get_Artists_Top_Tracks.ipynb | 1048 ++++++++++++++++++ 1 file changed, 1048 insertions(+) create mode 100644 Spotify/Spotify_Get_Artists_Top_Tracks.ipynb diff --git a/Spotify/Spotify_Get_Artists_Top_Tracks.ipynb b/Spotify/Spotify_Get_Artists_Top_Tracks.ipynb new file mode 100644 index 0000000000..b55ffcb1f2 --- /dev/null +++ b/Spotify/Spotify_Get_Artists_Top_Tracks.ipynb @@ -0,0 +1,1048 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8e2291f3-d36d-44c3-87bf-897ff94c9eb3", + "metadata": {}, + "source": [ + "\"Spotify.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "ba7d436a-2809-451b-83ad-d6c270f38b99", + "metadata": {}, + "source": [ + "# Spotify - Get Artist\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "bb85832d-fe5a-42c0-b6a8-55d7ddcabb6f", + "metadata": {}, + "source": [ + "**Tags:** #spotify #api #getartisttoptracks #webapi #reference #uniqueid #snippet" + ] + }, + { + "cell_type": "markdown", + "id": "f64cab10-78cc-4bda-a72c-7849da2d6780", + "metadata": {}, + "source": [ + "**Author:** [Alton Liew](https://www.linkedin.com/in/alton-liew-749944182/)" + ] + }, + { + "cell_type": "markdown", + "id": "e6f238a0-54d8-4851-afce-89b688f7e64b", + "metadata": {}, + "source": [ + "**Last update:** 2023-12-08 (Created: 2023-12-08)" + ] + }, + { + "cell_type": "markdown", + "id": "9506cddd-bb56-421b-b51a-2c8b6b49bc7b", + "metadata": {}, + "source": [ + "**Description:** This notebook retrieves the top ten tracks of an artist on Spotify." + ] + }, + { + "cell_type": "markdown", + "id": "92939377-87b8-4ac5-baa7-ad9c2c673f53", + "metadata": {}, + "source": [ + "**References:**\n", + "- [Spotify Web API Reference - Get Artist's Top Tracks](https://developer.spotify.com/documentation/web-api/reference/get-an-artists-top-tracks)\n", + "- [Spotify Developer Documentation](https://developer.spotify.com/documentation/)" + ] + }, + { + "cell_type": "markdown", + "id": "f4c249c1-ae37-44ad-988c-5ac39d340e90", + "metadata": {}, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "09a26cbb-770f-4cbb-b735-aeb805d5d1cb", + "metadata": {}, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d4e02b0d-1892-49c6-9c8e-54ba30965d44", + "metadata": { + "execution": { + "iopub.execute_input": "2023-12-08T03:34:02.094606Z", + "iopub.status.busy": "2023-12-08T03:34:02.094345Z", + "iopub.status.idle": "2023-12-08T03:34:06.545881Z", + "shell.execute_reply": "2023-12-08T03:34:06.545102Z", + "shell.execute_reply.started": "2023-12-08T03:34:02.094523Z" + } + }, + "outputs": [], + "source": [ + "try:\n", + " import spotipy\n", + "except:\n", + " !pip install spotipy --user\n", + " import spotipy\n", + "from spotipy.oauth2 import SpotifyClientCredentials\n", + "import naas\n", + "from IPython.display import Image, display" + ] + }, + { + "cell_type": "markdown", + "id": "07ffca4a-50d7-47f9-aa07-89b4d0d5c427", + "metadata": { + "execution": { + "iopub.execute_input": "2023-12-08T03:15:00.202207Z", + "iopub.status.busy": "2023-12-08T03:15:00.201855Z", + "iopub.status.idle": "2023-12-08T03:15:00.213808Z", + "shell.execute_reply": "2023-12-08T03:15:00.213100Z", + "shell.execute_reply.started": "2023-12-08T03:15:00.202117Z" + } + }, + "source": [ + "### Setup variables\n", + "- `client_id`: Your Spotify API client ID. [Get your client ID](https://developer.spotify.com/documentation/general/guides/app-settings/#register-your-app)\n", + "- `client_secret`: Your Spotify API client secret. [Get your client secret](https://developer.spotify.com/documentation/general/guides/app-settings/#register-your-app)\n", + "- `artist_id`: The unique Spotify ID for the artist. [Find the artist ID](https://developer.spotify.com/console/get-artist/)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "34f09e6d-d057-4996-b268-7d101cb73c6f", + "metadata": { + "execution": { + "iopub.execute_input": "2023-12-08T03:34:06.555401Z", + "iopub.status.busy": "2023-12-08T03:34:06.552855Z", + "iopub.status.idle": "2023-12-08T03:34:06.560617Z", + "shell.execute_reply": "2023-12-08T03:34:06.560045Z", + "shell.execute_reply.started": "2023-12-08T03:34:06.555359Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "client_id = \"c112067061f74b66ba1bbf813eacbc08\"\n", + "client_secret = \"cceba0c36915445aa819e454879d115d\"\n", + "artist_id = \"20wkVLutqVOYrc0kxFs7rA\" #beyonce" + ] + }, + { + "cell_type": "markdown", + "id": "8c98aef3-e91c-4698-ae4d-34d17e211e0e", + "metadata": {}, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "d0ee441d-be4d-4125-bc23-00e0d3fd24e5", + "metadata": {}, + "source": [ + "### Get Top 10 Tracks" + ] + }, + { + "cell_type": "markdown", + "id": "bd22786c-fbe1-4005-951e-98abf11eddfc", + "metadata": {}, + "source": [ + "* Retrieve the top 10 tracks of an artist through their Spotify ID.\n", + "* Sets up client with client id and client secret using spotipy library and fetches information." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "9052e5bc-2c74-466d-808e-74eee79eee88", + "metadata": { + "execution": { + "iopub.execute_input": "2023-12-08T03:34:06.565308Z", + "iopub.status.busy": "2023-12-08T03:34:06.564890Z", + "iopub.status.idle": "2023-12-08T03:34:06.871031Z", + "shell.execute_reply": "2023-12-08T03:34:06.870282Z", + "shell.execute_reply.started": "2023-12-08T03:34:06.565276Z" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'tracks': [{'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/3xybjP7r2VsWzwvDQipdM0'},\n", + " 'href': 'https://api.spotify.com/v1/albums/3xybjP7r2VsWzwvDQipdM0',\n", + " 'id': '3xybjP7r2VsWzwvDQipdM0',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2733138f891f3075c9c5d944037',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e023138f891f3075c9c5d944037',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048513138f891f3075c9c5d944037',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Freudian',\n", + " 'release_date': '2017-08-25',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 10,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:3xybjP7r2VsWzwvDQipdM0'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3Y7RZ31TRPVadSFVy1o8os'},\n", + " 'href': 'https://api.spotify.com/v1/artists/3Y7RZ31TRPVadSFVy1o8os',\n", + " 'id': '3Y7RZ31TRPVadSFVy1o8os',\n", + " 'name': 'H.E.R.',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3Y7RZ31TRPVadSFVy1o8os'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 209831,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'CADDS1700022'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/1RMJOxR6GRPsBHL8qeC2ux'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/1RMJOxR6GRPsBHL8qeC2ux',\n", + " 'id': '1RMJOxR6GRPsBHL8qeC2ux',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Best Part (feat. H.E.R.)',\n", + " 'popularity': 86,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/c3c8ed8ba1546630a13ffb139b405800c121e10d?cid=c112067061f74b66ba1bbf813eacbc08',\n", + " 'track_number': 2,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:1RMJOxR6GRPsBHL8qeC2ux'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/3xybjP7r2VsWzwvDQipdM0'},\n", + " 'href': 'https://api.spotify.com/v1/albums/3xybjP7r2VsWzwvDQipdM0',\n", + " 'id': '3xybjP7r2VsWzwvDQipdM0',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2733138f891f3075c9c5d944037',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e023138f891f3075c9c5d944037',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048513138f891f3075c9c5d944037',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Freudian',\n", + " 'release_date': '2017-08-25',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 10,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:3xybjP7r2VsWzwvDQipdM0'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1U1el3k54VvEUzo3ybLPlM'},\n", + " 'href': 'https://api.spotify.com/v1/artists/1U1el3k54VvEUzo3ybLPlM',\n", + " 'id': '1U1el3k54VvEUzo3ybLPlM',\n", + " 'name': 'Kali Uchis',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1U1el3k54VvEUzo3ybLPlM'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 278179,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'TCACR1690004'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/7zFXmv6vqI4qOt4yGf3jYZ'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/7zFXmv6vqI4qOt4yGf3jYZ',\n", + " 'id': '7zFXmv6vqI4qOt4yGf3jYZ',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Get You (feat. Kali Uchis)',\n", + " 'popularity': 85,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/50f8ebebe7de796d2519b203077d119e66a90ea3?cid=c112067061f74b66ba1bbf813eacbc08',\n", + " 'track_number': 1,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:7zFXmv6vqI4qOt4yGf3jYZ'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/7ivbFszr1TbVadj89BIy1y'},\n", + " 'href': 'https://api.spotify.com/v1/albums/7ivbFszr1TbVadj89BIy1y',\n", + " 'id': '7ivbFszr1TbVadj89BIy1y',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2737c68face1dc58127f3a7b1cc',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e027c68face1dc58127f3a7b1cc',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048517c68face1dc58127f3a7b1cc',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'NEVER ENOUGH',\n", + " 'release_date': '2023-04-07',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 15,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:7ivbFszr1TbVadj89BIy1y'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 225312,\n", + " 'explicit': True,\n", + " 'external_ids': {'isrc': 'USUG12209355'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/2LlOeW5rVcvl3QcPNPcDus'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/2LlOeW5rVcvl3QcPNPcDus',\n", + " 'id': '2LlOeW5rVcvl3QcPNPcDus',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Always',\n", + " 'popularity': 84,\n", + " 'preview_url': None,\n", + " 'track_number': 6,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:2LlOeW5rVcvl3QcPNPcDus'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/1uNFoZAHBGtllmzznpCI3s'},\n", + " 'href': 'https://api.spotify.com/v1/artists/1uNFoZAHBGtllmzznpCI3s',\n", + " 'id': '1uNFoZAHBGtllmzznpCI3s',\n", + " 'name': 'Justin Bieber',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1uNFoZAHBGtllmzznpCI3s'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/5dGWwsZ9iB2Xc3UKR0gif2'},\n", + " 'href': 'https://api.spotify.com/v1/albums/5dGWwsZ9iB2Xc3UKR0gif2',\n", + " 'id': '5dGWwsZ9iB2Xc3UKR0gif2',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273e6f407c7f3a0ec98845e4431',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02e6f407c7f3a0ec98845e4431',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851e6f407c7f3a0ec98845e4431',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Justice',\n", + " 'release_date': '2021-03-19',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 16,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:5dGWwsZ9iB2Xc3UKR0gif2'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/1uNFoZAHBGtllmzznpCI3s'},\n", + " 'href': 'https://api.spotify.com/v1/artists/1uNFoZAHBGtllmzznpCI3s',\n", + " 'id': '1uNFoZAHBGtllmzznpCI3s',\n", + " 'name': 'Justin Bieber',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1uNFoZAHBGtllmzznpCI3s'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4fxd5Ee7UefO4CUXgwJ7IP'},\n", + " 'href': 'https://api.spotify.com/v1/artists/4fxd5Ee7UefO4CUXgwJ7IP',\n", + " 'id': '4fxd5Ee7UefO4CUXgwJ7IP',\n", + " 'name': 'Giveon',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4fxd5Ee7UefO4CUXgwJ7IP'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 198081,\n", + " 'explicit': True,\n", + " 'external_ids': {'isrc': 'USUM72102636'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/4iJyoBOLtHqaGxP12qzhQI'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/4iJyoBOLtHqaGxP12qzhQI',\n", + " 'id': '4iJyoBOLtHqaGxP12qzhQI',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Peaches (feat. Daniel Caesar & Giveon)',\n", + " 'popularity': 83,\n", + " 'preview_url': None,\n", + " 'track_number': 12,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:4iJyoBOLtHqaGxP12qzhQI'},\n", + " {'album': {'album_type': 'single',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/5qfhZ5YkZ4LhEUbYgjrWt6'},\n", + " 'href': 'https://api.spotify.com/v1/albums/5qfhZ5YkZ4LhEUbYgjrWt6',\n", + " 'id': '5qfhZ5YkZ4LhEUbYgjrWt6',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273617c314e94693fad9a26f798',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02617c314e94693fad9a26f798',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851617c314e94693fad9a26f798',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Get You - Single',\n", + " 'release_date': '2016-10-21',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 2,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:5qfhZ5YkZ4LhEUbYgjrWt6'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 270846,\n", + " 'explicit': True,\n", + " 'external_ids': {'isrc': 'TCACR1690007'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/1boXOL0ua7N2iCOUVI1p9F'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/1boXOL0ua7N2iCOUVI1p9F',\n", + " 'id': '1boXOL0ua7N2iCOUVI1p9F',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Japanese Denim',\n", + " 'popularity': 82,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/ee5340b8b4f71426681b2a59a5118fd14ea19b4f?cid=c112067061f74b66ba1bbf813eacbc08',\n", + " 'track_number': 2,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:1boXOL0ua7N2iCOUVI1p9F'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/7ivbFszr1TbVadj89BIy1y'},\n", + " 'href': 'https://api.spotify.com/v1/albums/7ivbFszr1TbVadj89BIy1y',\n", + " 'id': '7ivbFszr1TbVadj89BIy1y',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2737c68face1dc58127f3a7b1cc',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e027c68face1dc58127f3a7b1cc',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048517c68face1dc58127f3a7b1cc',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'NEVER ENOUGH',\n", + " 'release_date': '2023-04-07',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 15,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:7ivbFszr1TbVadj89BIy1y'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 174512,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USUG12209368'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/736PP5LTtREkDgktNmX3Gu'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/736PP5LTtREkDgktNmX3Gu',\n", + " 'id': '736PP5LTtREkDgktNmX3Gu',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Superpowers',\n", + " 'popularity': 76,\n", + " 'preview_url': None,\n", + " 'track_number': 14,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:736PP5LTtREkDgktNmX3Gu'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/3xybjP7r2VsWzwvDQipdM0'},\n", + " 'href': 'https://api.spotify.com/v1/albums/3xybjP7r2VsWzwvDQipdM0',\n", + " 'id': '3xybjP7r2VsWzwvDQipdM0',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2733138f891f3075c9c5d944037',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e023138f891f3075c9c5d944037',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048513138f891f3075c9c5d944037',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Freudian',\n", + " 'release_date': '2017-08-25',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 10,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:3xybjP7r2VsWzwvDQipdM0'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 185522,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'CADDS1700028'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/59acp1OhcvxwVBwQJBYKuX'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/59acp1OhcvxwVBwQJBYKuX',\n", + " 'id': '59acp1OhcvxwVBwQJBYKuX',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Loose',\n", + " 'popularity': 77,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/b08c29b19a6fbe2b320d72c97d83b9c74589a4d6?cid=c112067061f74b66ba1bbf813eacbc08',\n", + " 'track_number': 5,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:59acp1OhcvxwVBwQJBYKuX'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/4mvxoogQn8p84Wz17zTHnJ'},\n", + " 'href': 'https://api.spotify.com/v1/albums/4mvxoogQn8p84Wz17zTHnJ',\n", + " 'id': '4mvxoogQn8p84Wz17zTHnJ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2737607aa9ae7904e1b12907c93',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e027607aa9ae7904e1b12907c93',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048517607aa9ae7904e1b12907c93',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'CASE STUDY 01',\n", + " 'release_date': '2019-06-28',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 10,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:4mvxoogQn8p84Wz17zTHnJ'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 194959,\n", + " 'explicit': True,\n", + " 'external_ids': {'isrc': 'QM6N21983282'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/3uouaAVXpQR3X8RYkJyitQ'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/3uouaAVXpQR3X8RYkJyitQ',\n", + " 'id': '3uouaAVXpQR3X8RYkJyitQ',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'CYANIDE',\n", + " 'popularity': 75,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/5069a8ff35f6c416c290b9da7c2e094a9702b3b6?cid=c112067061f74b66ba1bbf813eacbc08',\n", + " 'track_number': 2,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:3uouaAVXpQR3X8RYkJyitQ'},\n", + " {'album': {'album_type': 'single',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/15M9pZ8gsdoN67yLjyQ039'},\n", + " 'href': 'https://api.spotify.com/v1/albums/15M9pZ8gsdoN67yLjyQ039',\n", + " 'id': '15M9pZ8gsdoN67yLjyQ039',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273c70176fa51326491ecc5f79e',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02c70176fa51326491ecc5f79e',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851c70176fa51326491ecc5f79e',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Who Hurt You?',\n", + " 'release_date': '2018-10-16',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 1,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:15M9pZ8gsdoN67yLjyQ039'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 231964,\n", + " 'explicit': True,\n", + " 'external_ids': {'isrc': 'TCADX1816901'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/23c9gmiiv7RCu7twft0Mym'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/23c9gmiiv7RCu7twft0Mym',\n", + " 'id': '23c9gmiiv7RCu7twft0Mym',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Who Hurt You?',\n", + " 'popularity': 75,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/f6a819d48858ea32cffcbb8815e0e4d55a2e45da?cid=c112067061f74b66ba1bbf813eacbc08',\n", + " 'track_number': 1,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:23c9gmiiv7RCu7twft0Mym'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/7ivbFszr1TbVadj89BIy1y'},\n", + " 'href': 'https://api.spotify.com/v1/albums/7ivbFszr1TbVadj89BIy1y',\n", + " 'id': '7ivbFszr1TbVadj89BIy1y',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2737c68face1dc58127f3a7b1cc',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e027c68face1dc58127f3a7b1cc',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048517c68face1dc58127f3a7b1cc',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'NEVER ENOUGH',\n", + " 'release_date': '2023-04-07',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 15,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:7ivbFszr1TbVadj89BIy1y'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/20wkVLutqVOYrc0kxFs7rA'},\n", + " 'href': 'https://api.spotify.com/v1/artists/20wkVLutqVOYrc0kxFs7rA',\n", + " 'id': '20wkVLutqVOYrc0kxFs7rA',\n", + " 'name': 'Daniel Caesar',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:20wkVLutqVOYrc0kxFs7rA'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 216524,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USUG12209350'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/3ym8ajVmKm6Fybgov3WBI5'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/3ym8ajVmKm6Fybgov3WBI5',\n", + " 'id': '3ym8ajVmKm6Fybgov3WBI5',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Let Me Go',\n", + " 'popularity': 71,\n", + " 'preview_url': None,\n", + " 'track_number': 4,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:3ym8ajVmKm6Fybgov3WBI5'}]}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_artist(client_id, client_secret, artist_id):\n", + " data = None\n", + " sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret))\n", + " try:\n", + " data = sp.artist_top_tracks(artist_id)\n", + " except spotipy.SpotifyException as e:\n", + " print(f\"Error retrieving artist information: {e}\")\n", + " return data\n", + " \n", + "data = get_artist(client_id, client_secret, artist_id)\n", + "data" + ] + }, + { + "cell_type": "markdown", + "id": "3dc5ac7c-f3a2-4993-ba16-3a3829078836", + "metadata": {}, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "831383ee-f7c3-447d-8eae-4174ec992dd0", + "metadata": {}, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "markdown", + "id": "286ca61d-3347-4f67-a92e-48757515b522", + "metadata": {}, + "source": [ + "* If data is available, this will print out the required information." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1bb7a28f-e368-4a24-b6bf-2023c3f778cc", + "metadata": { + "execution": { + "iopub.execute_input": "2023-12-08T03:34:06.872190Z", + "iopub.status.busy": "2023-12-08T03:34:06.871956Z", + "iopub.status.idle": "2023-12-08T03:34:06.945623Z", + "shell.execute_reply": "2023-12-08T03:34:06.944934Z", + "shell.execute_reply.started": "2023-12-08T03:34:06.872158Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Top 10 Tracks by Daniel Caesar:\n", + "\n", + "\n", + "Name: Best Part (feat. H.E.R.)\n", + "Album: Freudian\n", + "ID: 1RMJOxR6GRPsBHL8qeC2ux\n", + "External URLs: https://open.spotify.com/track/1RMJOxR6GRPsBHL8qeC2ux\n", + "Preview: https://p.scdn.co/mp3-preview/c3c8ed8ba1546630a13ffb139b405800c121e10d?cid=c112067061f74b66ba1bbf813eacbc08\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Get You (feat. Kali Uchis)\n", + "Album: Freudian\n", + "ID: 7zFXmv6vqI4qOt4yGf3jYZ\n", + "External URLs: https://open.spotify.com/track/7zFXmv6vqI4qOt4yGf3jYZ\n", + "Preview: https://p.scdn.co/mp3-preview/50f8ebebe7de796d2519b203077d119e66a90ea3?cid=c112067061f74b66ba1bbf813eacbc08\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Always\n", + "Album: NEVER ENOUGH\n", + "ID: 2LlOeW5rVcvl3QcPNPcDus\n", + "External URLs: https://open.spotify.com/track/2LlOeW5rVcvl3QcPNPcDus\n", + "Preview: None\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Peaches (feat. Daniel Caesar & Giveon)\n", + "Album: Justice\n", + "ID: 4iJyoBOLtHqaGxP12qzhQI\n", + "External URLs: https://open.spotify.com/track/4iJyoBOLtHqaGxP12qzhQI\n", + "Preview: None\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Japanese Denim\n", + "Album: Get You - Single\n", + "ID: 1boXOL0ua7N2iCOUVI1p9F\n", + "External URLs: https://open.spotify.com/track/1boXOL0ua7N2iCOUVI1p9F\n", + "Preview: https://p.scdn.co/mp3-preview/ee5340b8b4f71426681b2a59a5118fd14ea19b4f?cid=c112067061f74b66ba1bbf813eacbc08\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Superpowers\n", + "Album: NEVER ENOUGH\n", + "ID: 736PP5LTtREkDgktNmX3Gu\n", + "External URLs: https://open.spotify.com/track/736PP5LTtREkDgktNmX3Gu\n", + "Preview: None\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Loose\n", + "Album: Freudian\n", + "ID: 59acp1OhcvxwVBwQJBYKuX\n", + "External URLs: https://open.spotify.com/track/59acp1OhcvxwVBwQJBYKuX\n", + "Preview: https://p.scdn.co/mp3-preview/b08c29b19a6fbe2b320d72c97d83b9c74589a4d6?cid=c112067061f74b66ba1bbf813eacbc08\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: CYANIDE\n", + "Album: CASE STUDY 01\n", + "ID: 3uouaAVXpQR3X8RYkJyitQ\n", + "External URLs: https://open.spotify.com/track/3uouaAVXpQR3X8RYkJyitQ\n", + "Preview: https://p.scdn.co/mp3-preview/5069a8ff35f6c416c290b9da7c2e094a9702b3b6?cid=c112067061f74b66ba1bbf813eacbc08\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Who Hurt You?\n", + "Album: Who Hurt You?\n", + "ID: 23c9gmiiv7RCu7twft0Mym\n", + "External URLs: https://open.spotify.com/track/23c9gmiiv7RCu7twft0Mym\n", + "Preview: https://p.scdn.co/mp3-preview/f6a819d48858ea32cffcbb8815e0e4d55a2e45da?cid=c112067061f74b66ba1bbf813eacbc08\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Name: Let Me Go\n", + "Album: NEVER ENOUGH\n", + "ID: 3ym8ajVmKm6Fybgov3WBI5\n", + "External URLs: https://open.spotify.com/track/3ym8ajVmKm6Fybgov3WBI5\n", + "Preview: None\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n" + ] + } + ], + "source": [ + "if data:\n", + " artist_name = data['tracks'][0]['artists'][0]['name']\n", + " print(f\"Top 10 Tracks by {artist_name}:\")\n", + " print(\"\\n\")\n", + " \n", + " for track in data['tracks']:\n", + " artist_info = {\n", + " \"Name\": track['name'],\n", + " \"Album\": track['album']['name'],\n", + " \"ID\": track['id'],\n", + " \"External URLs\": track['external_urls'].get(\"spotify\"),\n", + " \"Preview\": track['preview_url'],\n", + " \"Image\": track['album']['images'][0].get(\"url\"),\n", + " }\n", + "\n", + " for key, value in artist_info.items():\n", + " if key == \"Image\":\n", + " display(Image(url=value, width=300))\n", + " else:\n", + " print(f\"{key}: {value}\")\n", + " print(\"\\n\")\n", + "else:\n", + " print(\"Failed to retrieve artist information.\")" + ] + } + ], + "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.9.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}