diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..424c482 Binary files /dev/null and b/.DS_Store differ diff --git a/notebooks/spotify_rest_api_challenge.ipynb b/notebooks/spotify_rest_api_challenge.ipynb deleted file mode 100644 index 5e4f8f7..0000000 --- a/notebooks/spotify_rest_api_challenge.ipynb +++ /dev/null @@ -1,243 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "ef05c1d6", - "metadata": {}, - "source": [ - "![spotify_logo](../img/spotify_logo.png)\n", - "\n", - "# Spotify REST API Challenge\n", - "\n", - "__What to listen?__\n", - "\n", - "Create your own playlist based on the related artists and their most popular tracks using the [Spotify REST API](https://developer.spotify.com/)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "17a49776", - "metadata": {}, - "outputs": [], - "source": [ - "# Imports\n", - "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "4e97884c", - "metadata": {}, - "source": [ - "### Get access!!!\n", - "\n", - "Get your `client_id` and `client_secret` to generate your __token__ access" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7b5d2e52", - "metadata": {}, - "outputs": [], - "source": [ - "# Generate token with a POST request\n", - "\n", - "client_id = # CLIENT ID\n", - "client_secret = # CLIENT SECRET\n", - "auth_url = 'https://accounts.spotify.com/api/token'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c7901d1e", - "metadata": {}, - "outputs": [], - "source": [ - "auth_response = requests.post(auth_url, {'grant_type': 'client_credentials',\n", - " 'client_id': client_id,\n", - " 'client_secret': client_secret}).json()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "262e7e18", - "metadata": {}, - "outputs": [], - "source": [ - "access_token = auth_response['access_token']\n", - "auth_response" - ] - }, - { - "cell_type": "markdown", - "id": "e617caff", - "metadata": {}, - "source": [ - "### Set your main variables!!!\n", - "\n", - "Set the `base_uri` (i.e.: end-point), parameters and `headers` for your __GET__ operations" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "62e6d4fb", - "metadata": {}, - "outputs": [], - "source": [ - "# Base end-point construction\n", - "\n", - "base_url = 'https://api.spotify.com/v1/'\n", - "resource = 'artists/'\n", - "\n", - "header_info = {'Authorization': 'Bearer {token}'.format(token=access_token)}" - ] - }, - { - "cell_type": "markdown", - "id": "16660a9b", - "metadata": {}, - "source": [ - "### Create your new playlist!!!\n", - "\n", - "Use [`/related-artists`](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-related-artists) and [`/top-tracks`](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks) in order to get the data that you need.\n", - "\n", - "__Here you have the different artists to start with:__\n", - "\n", - "- __Option 1:__ 0L8ExT028jH3ddEcZwqJJ5\n", - "\n", - "- __Option 2:__ 4Y7tXHSEejGu1vQ9bwDdXW\n", - "\n", - "- __Option 3:__ 6FBDaR13swtiWwGhX1WQsP\n", - "\n", - "- __Option 4:__ 0kyQwKHCZnKE7kTXkxXjrB\n", - "\n", - "- __Option 5:__ 2d0hyoQ5ynDBnkvAbJKORj\n", - "\n", - "- __Option 6:__ 3bgsNtcf5d5h9jbQbohfBK\n", - "\n", - "- __Option 7:__ 7mWCSSOYqm4E9mB7V4ot6S\n", - "\n", - "- __Option 8:__ 64KEffDW9EtZ1y2vBYgq8T\n", - "\n", - "- __Option 9:__ 4k1ELeJKT1ISyDv8JivPpB\n", - "\n", - "- __Option 10:__ 4Z8W4fKeB5YxbusRsdQVPb\n", - "\n", - "- __Option 11:__ 26dSoYclwsYLMAKD3tpOr4\n", - "\n", - "- __Option 12:__ 7y97mc3bZRFXzT2szRM4L4\n", - "\n", - "- __Option 13:__ 1w5Kfo2jwwIPruYS2UWh56\n", - "\n", - "\n", - "> Remember to check the [Requests](https://requests.readthedocs.io/en/latest/) library docs!!!\n", - "\n", - "---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "04f85940", - "metadata": {}, - "outputs": [], - "source": [ - "# Here you can complete your endpoint URI\n", - "\n", - "full_endpoint = \n", - "full_endpoint" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "50ec3959", - "metadata": {}, - "outputs": [], - "source": [ - "# Start building your playlist!!!\n", - "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "98827be6", - "metadata": {}, - "source": [ - "---\n", - "\n", - "### Bonus track!!!\n", - "\n", - "You can publish your own Playlist with [`/playlists`](https://developer.spotify.com/documentation/web-api/reference/#/operations/create-playlist) and [`/tracks`](https://developer.spotify.com/documentation/web-api/reference/#/operations/add-tracks-to-playlist).\n", - "\n", - "![I quit](https://media.giphy.com/media/gui67fZ3xIneM/giphy.gif)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2e5f0905", - "metadata": {}, - "outputs": [], - "source": [ - "# Bonus\n", - "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "9436b623", - "metadata": {}, - "source": [ - "---" - ] - }, - { - "cell_type": "markdown", - "id": "a9487ef7", - "metadata": {}, - "source": [ - "You can always try with the [wrapper](https://github.com/plamere/spotipy)!!!\n", - "\n", - "![I quit](https://media.giphy.com/media/3oFzlXPvXYZ4q8VQOs/giphy.gif)" - ] - }, - { - "cell_type": "markdown", - "id": "0a399ce8", - "metadata": {}, - "source": [ - "---" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [conda env:.conda-ironhack]", - "language": "python", - "name": "conda-env-.conda-ironhack-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.7.11" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/spotify_rest_api_challenge_SOLUCIONES_con_BONUS.ipynb b/notebooks/spotify_rest_api_challenge_SOLUCIONES_con_BONUS.ipynb new file mode 100644 index 0000000..f1b10ff --- /dev/null +++ b/notebooks/spotify_rest_api_challenge_SOLUCIONES_con_BONUS.ipynb @@ -0,0 +1,1879 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "37219dd7", + "metadata": {}, + "source": [ + "## Acceso" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d9ba4ce5", + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import pandas as pd\n", + "import json\n", + "import string\n", + "import random\n", + "from flask import Flask, request, redirect #No sé muy bien qué hace esto\n", + "import base64" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "1a6a0d91", + "metadata": {}, + "outputs": [], + "source": [ + "from dotenv import dotenv_values" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "322e807a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OrderedDict([('client_id', 'f3c31c7678ae4a9887fc4c626a1e9bc1'), ('client_secret', 'a7ec3c800df3483cbc128524bec99fd3')])\n" + ] + } + ], + "source": [ + "config = dotenv_values(\".env\")\n", + "print(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3ac2cac6", + "metadata": {}, + "outputs": [], + "source": [ + "client_id = config[\"client_id\"]\n", + "client_secret = config[\"client_secret\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "f86d27d9", + "metadata": {}, + "outputs": [], + "source": [ + "auth_url = 'https://accounts.spotify.com/api/token'" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "3d4d0c29", + "metadata": {}, + "outputs": [], + "source": [ + "auth_response = requests.post(auth_url, {'grant_type': 'client_credentials',\n", + " 'client_id': client_id,\n", + " 'client_secret': client_secret}).json()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "80f9f763", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'BQD29JwI_VgodIy35tqumuLJ2OrfWOps2Dx_mB_IhieCva38QQ9CPD8MfQx8PMpftFezL4x8yRpF6ajh6KE0p2vARKR41lUpQnjFK5bxvFXfFPnI7Z4'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "access_token = auth_response[\"access_token\"]\n", + "access_token" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4f609df6", + "metadata": {}, + "outputs": [], + "source": [ + "base_url = 'https://api.spotify.com/v1/'\n", + "resource = 'artists/'\n", + "\n", + "header_info = {'Authorization': 'Bearer {token}'.format(token=access_token)}" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "34a960cd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Authorization': 'Bearer BQD29JwI_VgodIy35tqumuLJ2OrfWOps2Dx_mB_IhieCva38QQ9CPD8MfQx8PMpftFezL4x8yRpF6ajh6KE0p2vARKR41lUpQnjFK5bxvFXfFPnI7Z4'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "header_info" + ] + }, + { + "cell_type": "markdown", + "id": "0e81f95b", + "metadata": {}, + "source": [ + "## Creación de una playlist de artista + relacionados" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "a938a7e2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3ZXXJ9nO1Dn9B0AJ25eAQY'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#En este caso, yo voy a coger a Hamilton Leithauser\n", + "artist_id = \"3ZXXJ9nO1Dn9B0AJ25eAQY\"\n", + "artist_id" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "8b90892c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/3ZXXJ9nO1Dn9B0AJ25eAQY/related-artists'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "artist_id = \"3ZXXJ9nO1Dn9B0AJ25eAQY\"\n", + "method = \"/related-artists\"\n", + "argument = \"market = ES\"\n", + "full_endpoint = base_url + resource + artist_id + method \n", + "full_endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "498c223f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "related_artists_response = requests.get(full_endpoint, headers = header_info)\n", + "related_artists_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "434bd193", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/3h0w83PsjASrm5999trG4n'},\n", + " 'followers': {'href': None, 'total': 51178},\n", + " 'genres': ['ambient folk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3h0w83PsjASrm5999trG4n',\n", + " 'id': '3h0w83PsjASrm5999trG4n',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebf97b946adea21df03434101a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174f97b946adea21df03434101a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178f97b946adea21df03434101a',\n", + " 'width': 160}],\n", + " 'name': 'Hamilton Leithauser + Rostam',\n", + " 'popularity': 7,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3h0w83PsjASrm5999trG4n'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6kFay2DQ5aZfeu5OsrF3Pw'},\n", + " 'followers': {'href': None, 'total': 193249},\n", + " 'genres': ['chamber pop', 'indie rock', 'noise pop'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6kFay2DQ5aZfeu5OsrF3Pw',\n", + " 'id': '6kFay2DQ5aZfeu5OsrF3Pw',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebaefcc48f32686224654746ca',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174aefcc48f32686224654746ca',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178aefcc48f32686224654746ca',\n", + " 'width': 160}],\n", + " 'name': 'The Walkmen',\n", + " 'popularity': 44,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6kFay2DQ5aZfeu5OsrF3Pw'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/04XggbrM51GcFPTxBYtRXT'},\n", + " 'followers': {'href': None, 'total': 78947},\n", + " 'genres': ['art pop'],\n", + " 'href': 'https://api.spotify.com/v1/artists/04XggbrM51GcFPTxBYtRXT',\n", + " 'id': '04XggbrM51GcFPTxBYtRXT',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb927fc6434315284d758fa2cd',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174927fc6434315284d758fa2cd',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178927fc6434315284d758fa2cd',\n", + " 'width': 160}],\n", + " 'name': 'Rostam',\n", + " 'popularity': 44,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:04XggbrM51GcFPTxBYtRXT'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0TDphr7Qpz3y4s2yhTBVNr'},\n", + " 'followers': {'href': None, 'total': 454},\n", + " 'genres': [],\n", + " 'href': 'https://api.spotify.com/v1/artists/0TDphr7Qpz3y4s2yhTBVNr',\n", + " 'id': '0TDphr7Qpz3y4s2yhTBVNr',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb8ef4fa63c15a643c5c287762',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051748ef4fa63c15a643c5c287762',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1788ef4fa63c15a643c5c287762',\n", + " 'width': 160}],\n", + " 'name': 'Paul Maroon',\n", + " 'popularity': 12,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0TDphr7Qpz3y4s2yhTBVNr'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4ZMQlzOFrvOftjt1rjl8YR'},\n", + " 'followers': {'href': None, 'total': 4061},\n", + " 'genres': ['garage psych'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4ZMQlzOFrvOftjt1rjl8YR',\n", + " 'id': '4ZMQlzOFrvOftjt1rjl8YR',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb7c7dac3f52ef8ff0aabfdac6',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051747c7dac3f52ef8ff0aabfdac6',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1787c7dac3f52ef8ff0aabfdac6',\n", + " 'width': 160}],\n", + " 'name': 'Peter Matthew Bauer',\n", + " 'popularity': 14,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4ZMQlzOFrvOftjt1rjl8YR'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6fxk3UXHTFYET8qCT9WlBF'},\n", + " 'followers': {'href': None, 'total': 282212},\n", + " 'genres': ['chamber pop', 'indie rock', 'kc indie', 'modern folk rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6fxk3UXHTFYET8qCT9WlBF',\n", + " 'id': '6fxk3UXHTFYET8qCT9WlBF',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb292b964365b5de1a53216852',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174292b964365b5de1a53216852',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178292b964365b5de1a53216852',\n", + " 'width': 160}],\n", + " 'name': 'Kevin Morby',\n", + " 'popularity': 48,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6fxk3UXHTFYET8qCT9WlBF'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1HvCWUrKX1xKeT3yQXjPeI'},\n", + " 'followers': {'href': None, 'total': 9011},\n", + " 'genres': [],\n", + " 'href': 'https://api.spotify.com/v1/artists/1HvCWUrKX1xKeT3yQXjPeI',\n", + " 'id': '1HvCWUrKX1xKeT3yQXjPeI',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebe11b3639c8159dbaea0c1243',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174e11b3639c8159dbaea0c1243',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178e11b3639c8159dbaea0c1243',\n", + " 'width': 160}],\n", + " 'name': 'Walter Martin',\n", + " 'popularity': 23,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1HvCWUrKX1xKeT3yQXjPeI'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/22ojy4H4ZVpowC4lRRC8In'},\n", + " 'followers': {'href': None, 'total': 170636},\n", + " 'genres': ['art pop',\n", + " 'chamber pop',\n", + " 'indie rock',\n", + " 'indietronica',\n", + " 'noise pop',\n", + " 'vancouver indie'],\n", + " 'href': 'https://api.spotify.com/v1/artists/22ojy4H4ZVpowC4lRRC8In',\n", + " 'id': '22ojy4H4ZVpowC4lRRC8In',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb5a06b396f61778ebc0747b55',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051745a06b396f61778ebc0747b55',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1785a06b396f61778ebc0747b55',\n", + " 'width': 160}],\n", + " 'name': 'Destroyer',\n", + " 'popularity': 37,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:22ojy4H4ZVpowC4lRRC8In'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0XSqX2PB3C5dTMv7SZaxSm'},\n", + " 'followers': {'href': None, 'total': 158411},\n", + " 'genres': ['canadian indie',\n", + " 'indie rock',\n", + " 'indietronica',\n", + " 'noise pop',\n", + " 'quebec indie'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0XSqX2PB3C5dTMv7SZaxSm',\n", + " 'id': '0XSqX2PB3C5dTMv7SZaxSm',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebe0ee9d6c0075af4fabb763bb',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174e0ee9d6c0075af4fabb763bb',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178e0ee9d6c0075af4fabb763bb',\n", + " 'width': 160}],\n", + " 'name': 'Wolf Parade',\n", + " 'popularity': 36,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0XSqX2PB3C5dTMv7SZaxSm'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5IWCU0V9evBlW4gIeGY4zF'},\n", + " 'followers': {'href': None, 'total': 174464},\n", + " 'genres': ['alabama indie',\n", + " 'art pop',\n", + " 'bubblegrunge',\n", + " 'chamber pop',\n", + " 'countrygaze',\n", + " 'indie pop',\n", + " 'indie rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5IWCU0V9evBlW4gIeGY4zF',\n", + " 'id': '5IWCU0V9evBlW4gIeGY4zF',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb7c9318ae648ff7f53c14fdaf',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051747c9318ae648ff7f53c14fdaf',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1787c9318ae648ff7f53c14fdaf',\n", + " 'width': 160}],\n", + " 'name': 'Waxahatchee',\n", + " 'popularity': 45,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5IWCU0V9evBlW4gIeGY4zF'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7fSjnDr8tBO37Xbb2UXuYr'},\n", + " 'followers': {'href': None, 'total': 45012},\n", + " 'genres': [],\n", + " 'href': 'https://api.spotify.com/v1/artists/7fSjnDr8tBO37Xbb2UXuYr',\n", + " 'id': '7fSjnDr8tBO37Xbb2UXuYr',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebf269afd754a34817acd0b343',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174f269afd754a34817acd0b343',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178f269afd754a34817acd0b343',\n", + " 'width': 160}],\n", + " 'name': 'Richard Swift',\n", + " 'popularity': 35,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7fSjnDr8tBO37Xbb2UXuYr'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3zsR0Nsw8G2KuzKSdmosPI'},\n", + " 'followers': {'href': None, 'total': 73448},\n", + " 'genres': ['indie rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3zsR0Nsw8G2KuzKSdmosPI',\n", + " 'id': '3zsR0Nsw8G2KuzKSdmosPI',\n", + " 'images': [{'height': 665,\n", + " 'url': 'https://i.scdn.co/image/daf8fa1f9159d424dcaad7e7c1719e82e27d0e21',\n", + " 'width': 1000},\n", + " {'height': 425,\n", + " 'url': 'https://i.scdn.co/image/9509cf0caa26482bb4e89ec24723707520d75f27',\n", + " 'width': 640},\n", + " {'height': 133,\n", + " 'url': 'https://i.scdn.co/image/2f3cddd01c0ffa89bd01908d44d64e2a270703b5',\n", + " 'width': 200},\n", + " {'height': 43,\n", + " 'url': 'https://i.scdn.co/image/9960df72cc54ba146882b172d400d9c2ff5a4116',\n", + " 'width': 64}],\n", + " 'name': 'EL VY',\n", + " 'popularity': 30,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3zsR0Nsw8G2KuzKSdmosPI'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4nZTcwItN2j9H21sJBZ2Nq'},\n", + " 'followers': {'href': None, 'total': 30686},\n", + " 'genres': [],\n", + " 'href': 'https://api.spotify.com/v1/artists/4nZTcwItN2j9H21sJBZ2Nq',\n", + " 'id': '4nZTcwItN2j9H21sJBZ2Nq',\n", + " 'images': [{'height': 1000,\n", + " 'url': 'https://i.scdn.co/image/ab6772690000c46cd34be1e044e87be8781dccc8',\n", + " 'width': 1000},\n", + " {'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6772690000dd22d34be1e044e87be8781dccc8',\n", + " 'width': 640},\n", + " {'height': 200,\n", + " 'url': 'https://i.scdn.co/image/ab6772690000bac3d34be1e044e87be8781dccc8',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67726900008f74d34be1e044e87be8781dccc8',\n", + " 'width': 64}],\n", + " 'name': 'Muzz',\n", + " 'popularity': 25,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4nZTcwItN2j9H21sJBZ2Nq'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2sBPVEeMBXKNsZtYaJixnJ'},\n", + " 'followers': {'href': None, 'total': 100019},\n", + " 'genres': ['brooklyn indie',\n", + " 'chamber pop',\n", + " 'freak folk',\n", + " 'indie rock',\n", + " 'modern folk rock',\n", + " 'neo-psychedelic',\n", + " 'noise pop'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2sBPVEeMBXKNsZtYaJixnJ',\n", + " 'id': '2sBPVEeMBXKNsZtYaJixnJ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb457ad88617a18d83d7f3bbd3',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174457ad88617a18d83d7f3bbd3',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178457ad88617a18d83d7f3bbd3',\n", + " 'width': 160}],\n", + " 'name': 'Woods',\n", + " 'popularity': 37,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2sBPVEeMBXKNsZtYaJixnJ'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/27jRNjIvlUcGN7FBRDnqhp'},\n", + " 'followers': {'href': None, 'total': 82499},\n", + " 'genres': [],\n", + " 'href': 'https://api.spotify.com/v1/artists/27jRNjIvlUcGN7FBRDnqhp',\n", + " 'id': '27jRNjIvlUcGN7FBRDnqhp',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebdf796c4a5ad87ff40b45cf8a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174df796c4a5ad87ff40b45cf8a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178df796c4a5ad87ff40b45cf8a',\n", + " 'width': 160}],\n", + " 'name': 'Matt Berninger',\n", + " 'popularity': 41,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:27jRNjIvlUcGN7FBRDnqhp'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1jwOuEBcOKq0BeudSarbEM'},\n", + " 'followers': {'href': None, 'total': 68488},\n", + " 'genres': ['art pop', 'chamber pop', 'modern psychedelic folk', 'popgaze'],\n", + " 'href': 'https://api.spotify.com/v1/artists/1jwOuEBcOKq0BeudSarbEM',\n", + " 'id': '1jwOuEBcOKq0BeudSarbEM',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb875f84589a2d188940634732',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174875f84589a2d188940634732',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178875f84589a2d188940634732',\n", + " 'width': 160}],\n", + " 'name': 'Amen Dunes',\n", + " 'popularity': 33,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1jwOuEBcOKq0BeudSarbEM'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2iUVQjheBnvOt8vaBrxXJz'},\n", + " 'followers': {'href': None, 'total': 160452},\n", + " 'genres': ['baroque pop',\n", + " 'chamber pop',\n", + " 'indie rock',\n", + " 'neo-psychedelic',\n", + " 'singer-songwriter'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2iUVQjheBnvOt8vaBrxXJz',\n", + " 'id': '2iUVQjheBnvOt8vaBrxXJz',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebe234c3d8b4211a0698827bd3',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174e234c3d8b4211a0698827bd3',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178e234c3d8b4211a0698827bd3',\n", + " 'width': 160}],\n", + " 'name': 'Cass McCombs',\n", + " 'popularity': 49,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2iUVQjheBnvOt8vaBrxXJz'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/57kIMCLPgkzQlXjblX7XXP'},\n", + " 'followers': {'href': None, 'total': 225645},\n", + " 'genres': ['alternative americana',\n", + " 'chamber pop',\n", + " 'countrygaze',\n", + " 'indie folk',\n", + " 'indie rock',\n", + " 'stomp and holler',\n", + " 'swedish americana'],\n", + " 'href': 'https://api.spotify.com/v1/artists/57kIMCLPgkzQlXjblX7XXP',\n", + " 'id': '57kIMCLPgkzQlXjblX7XXP',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb0695eb77e4b7e89669d83723',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051740695eb77e4b7e89669d83723',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1780695eb77e4b7e89669d83723',\n", + " 'width': 160}],\n", + " 'name': 'Phosphorescent',\n", + " 'popularity': 46,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:57kIMCLPgkzQlXjblX7XXP'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6Qm9stX6XO1a4c7BXQDDgc'},\n", + " 'followers': {'href': None, 'total': 168825},\n", + " 'genres': ['chamber pop',\n", + " 'indie folk',\n", + " 'indie rock',\n", + " 'new americana',\n", + " 'stomp and holler'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6Qm9stX6XO1a4c7BXQDDgc',\n", + " 'id': '6Qm9stX6XO1a4c7BXQDDgc',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebfc63c3630989a598f892b93b',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174fc63c3630989a598f892b93b',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178fc63c3630989a598f892b93b',\n", + " 'width': 160}],\n", + " 'name': 'Fruit Bats',\n", + " 'popularity': 52,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6Qm9stX6XO1a4c7BXQDDgc'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2rDxtYUzTAYJJE3Bl3Z5IN'},\n", + " 'followers': {'href': None, 'total': 88918},\n", + " 'genres': ['alternative country',\n", + " 'chamber pop',\n", + " 'folk',\n", + " 'roots rock',\n", + " 'singer-songwriter'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2rDxtYUzTAYJJE3Bl3Z5IN',\n", + " 'id': '2rDxtYUzTAYJJE3Bl3Z5IN',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebfbddc561042109b5528d43d8',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174fbddc561042109b5528d43d8',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178fbddc561042109b5528d43d8',\n", + " 'width': 160}],\n", + " 'name': 'Jeff Tweedy',\n", + " 'popularity': 40,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2rDxtYUzTAYJJE3Bl3Z5IN'}]}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "related_artists_json = related_artists_response.json()\n", + "related_artists_json" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "6338e607", + "metadata": {}, + "outputs": [], + "source": [ + "# Voy a coger los top_tracks de mi artista seleccionado:\n", + "\n", + "def get_top_tracks(artist_id):\n", + " resource = \"artists\"\n", + " parameters = f\"/{artist_id}/top-tracks?market=ES\"\n", + " url = base_url + resource + parameters\n", + " response = requests.get(url, headers=header_info).json()\n", + " df_tracks = pd.DataFrame(response[\"tracks\"])[[\"id\", \"href\", \"name\", \"uri\"]]\n", + " return df_tracks" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "010335e3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "pandas.core.frame.DataFrame" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "top_tracks_artist = get_top_tracks(\"3ZXXJ9nO1Dn9B0AJ25eAQY\")\n", + "type(top_tracks_artist)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "a2896c59", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\ntop_tracks_artist = top_tracks_artist.rename(columns = {\"id\": \"original_artist_id\",\\n \"name\":\"original_artist_name\",\\n \"genres\":\"original_artist_genres\",\\n \"popularity\": \"original_artist_popularity\",\\n \"followers\": \"original_artist_followers\"\\n })\\n \\n'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "top_tracks_artist = top_tracks_artist.rename(columns = {\"id\": \"original_artist_id\",\n", + " \"name\":\"original_artist_name\",\n", + " \"genres\":\"original_artist_genres\",\n", + " \"popularity\": \"original_artist_popularity\",\n", + " \"followers\": \"original_artist_followers\"\n", + " })\n", + " \n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "0383ed82", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idhrefnameuri
07dfQNWgVxikbrdvEmsfPMAhttps://api.spotify.com/v1/tracks/7dfQNWgVxikb...A 1000 Timesspotify:track:7dfQNWgVxikbrdvEmsfPMA
12ZBzOL0HTCQCw7W3luTZtBhttps://api.spotify.com/v1/tracks/2ZBzOL0HTCQC...In a Black Outspotify:track:2ZBzOL0HTCQCw7W3luTZtB
26UuOsC3oeu6SgC6mono7XShttps://api.spotify.com/v1/tracks/6UuOsC3oeu6S...When the Truth Is...spotify:track:6UuOsC3oeu6SgC6mono7XS
360y3z4xCQhmhQ7cwqHGKzohttps://api.spotify.com/v1/tracks/60y3z4xCQhmh...Here They Comespotify:track:60y3z4xCQhmhQ7cwqHGKzo
427NWwTGqZSd0WsNi4NxJaAhttps://api.spotify.com/v1/tracks/27NWwTGqZSd0...Sick as a Dogspotify:track:27NWwTGqZSd0WsNi4NxJaA
54O8uW41RxfVF6AJRehcG9Whttps://api.spotify.com/v1/tracks/4O8uW41RxfVF...Virginia Beachspotify:track:4O8uW41RxfVF6AJRehcG9W
60GMe0UKs0YDq5OHGnrEu22https://api.spotify.com/v1/tracks/0GMe0UKs0YDq...The Silent Orchestraspotify:track:0GMe0UKs0YDq5OHGnrEu22
72aoPczdg7KqPieRRCBePkqhttps://api.spotify.com/v1/tracks/2aoPczdg7KqP...Heartstruck (Wild Hunger)spotify:track:2aoPczdg7KqPieRRCBePkq
83s9bSPogDpCCNhbAcmKHorhttps://api.spotify.com/v1/tracks/3s9bSPogDpCC...1959spotify:track:3s9bSPogDpCCNhbAcmKHor
95cqrgqsNudu6qV2vjJyUMLhttps://api.spotify.com/v1/tracks/5cqrgqsNudu6...The Bride's Dadspotify:track:5cqrgqsNudu6qV2vjJyUML
\n", + "
" + ], + "text/plain": [ + " id href \\\n", + "0 7dfQNWgVxikbrdvEmsfPMA https://api.spotify.com/v1/tracks/7dfQNWgVxikb... \n", + "1 2ZBzOL0HTCQCw7W3luTZtB https://api.spotify.com/v1/tracks/2ZBzOL0HTCQC... \n", + "2 6UuOsC3oeu6SgC6mono7XS https://api.spotify.com/v1/tracks/6UuOsC3oeu6S... \n", + "3 60y3z4xCQhmhQ7cwqHGKzo https://api.spotify.com/v1/tracks/60y3z4xCQhmh... \n", + "4 27NWwTGqZSd0WsNi4NxJaA https://api.spotify.com/v1/tracks/27NWwTGqZSd0... \n", + "5 4O8uW41RxfVF6AJRehcG9W https://api.spotify.com/v1/tracks/4O8uW41RxfVF... \n", + "6 0GMe0UKs0YDq5OHGnrEu22 https://api.spotify.com/v1/tracks/0GMe0UKs0YDq... \n", + "7 2aoPczdg7KqPieRRCBePkq https://api.spotify.com/v1/tracks/2aoPczdg7KqP... \n", + "8 3s9bSPogDpCCNhbAcmKHor https://api.spotify.com/v1/tracks/3s9bSPogDpCC... \n", + "9 5cqrgqsNudu6qV2vjJyUML https://api.spotify.com/v1/tracks/5cqrgqsNudu6... \n", + "\n", + " name uri \n", + "0 A 1000 Times spotify:track:7dfQNWgVxikbrdvEmsfPMA \n", + "1 In a Black Out spotify:track:2ZBzOL0HTCQCw7W3luTZtB \n", + "2 When the Truth Is... spotify:track:6UuOsC3oeu6SgC6mono7XS \n", + "3 Here They Come spotify:track:60y3z4xCQhmhQ7cwqHGKzo \n", + "4 Sick as a Dog spotify:track:27NWwTGqZSd0WsNi4NxJaA \n", + "5 Virginia Beach spotify:track:4O8uW41RxfVF6AJRehcG9W \n", + "6 The Silent Orchestra spotify:track:0GMe0UKs0YDq5OHGnrEu22 \n", + "7 Heartstruck (Wild Hunger) spotify:track:2aoPczdg7KqPieRRCBePkq \n", + "8 1959 spotify:track:3s9bSPogDpCCNhbAcmKHor \n", + "9 The Bride's Dad spotify:track:5cqrgqsNudu6qV2vjJyUML " + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "top_tracks_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "75d9720a", + "metadata": {}, + "outputs": [], + "source": [ + "#Ahora voy a sacar los artistas relacionados con sus id.\n", + "def get_related_artists(artist_id):\n", + " parameters = f\"/{artist_id}/related-artists\"\n", + " url = base_url + resource + parameters\n", + " response = related_artists_json\n", + " df_related_artists= pd.DataFrame(response[\"artists\"])[[\"id\", \"name\"]]\n", + " df_related_artists\n", + " return df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "9e5d3b93", + "metadata": {}, + "outputs": [], + "source": [ + "df_related_artists = get_related_artists(\"3ZXXJ9nO1Dn9B0AJ25eAQY\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "464f237b", + "metadata": {}, + "outputs": [], + "source": [ + "df_related_artists = df_related_artists.drop(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "36cd6bc7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idname
16kFay2DQ5aZfeu5OsrF3PwThe Walkmen
204XggbrM51GcFPTxBYtRXTRostam
30TDphr7Qpz3y4s2yhTBVNrPaul Maroon
44ZMQlzOFrvOftjt1rjl8YRPeter Matthew Bauer
56fxk3UXHTFYET8qCT9WlBFKevin Morby
61HvCWUrKX1xKeT3yQXjPeIWalter Martin
722ojy4H4ZVpowC4lRRC8InDestroyer
80XSqX2PB3C5dTMv7SZaxSmWolf Parade
95IWCU0V9evBlW4gIeGY4zFWaxahatchee
107fSjnDr8tBO37Xbb2UXuYrRichard Swift
113zsR0Nsw8G2KuzKSdmosPIEL VY
124nZTcwItN2j9H21sJBZ2NqMuzz
132sBPVEeMBXKNsZtYaJixnJWoods
1427jRNjIvlUcGN7FBRDnqhpMatt Berninger
151jwOuEBcOKq0BeudSarbEMAmen Dunes
162iUVQjheBnvOt8vaBrxXJzCass McCombs
1757kIMCLPgkzQlXjblX7XXPPhosphorescent
186Qm9stX6XO1a4c7BXQDDgcFruit Bats
192rDxtYUzTAYJJE3Bl3Z5INJeff Tweedy
\n", + "
" + ], + "text/plain": [ + " id name\n", + "1 6kFay2DQ5aZfeu5OsrF3Pw The Walkmen\n", + "2 04XggbrM51GcFPTxBYtRXT Rostam\n", + "3 0TDphr7Qpz3y4s2yhTBVNr Paul Maroon\n", + "4 4ZMQlzOFrvOftjt1rjl8YR Peter Matthew Bauer\n", + "5 6fxk3UXHTFYET8qCT9WlBF Kevin Morby\n", + "6 1HvCWUrKX1xKeT3yQXjPeI Walter Martin\n", + "7 22ojy4H4ZVpowC4lRRC8In Destroyer\n", + "8 0XSqX2PB3C5dTMv7SZaxSm Wolf Parade\n", + "9 5IWCU0V9evBlW4gIeGY4zF Waxahatchee\n", + "10 7fSjnDr8tBO37Xbb2UXuYr Richard Swift\n", + "11 3zsR0Nsw8G2KuzKSdmosPI EL VY\n", + "12 4nZTcwItN2j9H21sJBZ2Nq Muzz\n", + "13 2sBPVEeMBXKNsZtYaJixnJ Woods\n", + "14 27jRNjIvlUcGN7FBRDnqhp Matt Berninger\n", + "15 1jwOuEBcOKq0BeudSarbEM Amen Dunes\n", + "16 2iUVQjheBnvOt8vaBrxXJz Cass McCombs\n", + "17 57kIMCLPgkzQlXjblX7XXP Phosphorescent\n", + "18 6Qm9stX6XO1a4c7BXQDDgc Fruit Bats\n", + "19 2rDxtYUzTAYJJE3Bl3Z5IN Jeff Tweedy" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "f72b0593", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1 6kFay2DQ5aZfeu5OsrF3Pw\n", + "2 04XggbrM51GcFPTxBYtRXT\n", + "3 0TDphr7Qpz3y4s2yhTBVNr\n", + "4 4ZMQlzOFrvOftjt1rjl8YR\n", + "5 6fxk3UXHTFYET8qCT9WlBF\n", + "6 1HvCWUrKX1xKeT3yQXjPeI\n", + "7 22ojy4H4ZVpowC4lRRC8In\n", + "8 0XSqX2PB3C5dTMv7SZaxSm\n", + "9 5IWCU0V9evBlW4gIeGY4zF\n", + "10 7fSjnDr8tBO37Xbb2UXuYr\n", + "11 3zsR0Nsw8G2KuzKSdmosPI\n", + "12 4nZTcwItN2j9H21sJBZ2Nq\n", + "13 2sBPVEeMBXKNsZtYaJixnJ\n", + "14 27jRNjIvlUcGN7FBRDnqhp\n", + "15 1jwOuEBcOKq0BeudSarbEM\n", + "16 2iUVQjheBnvOt8vaBrxXJz\n", + "17 57kIMCLPgkzQlXjblX7XXP\n", + "18 6Qm9stX6XO1a4c7BXQDDgc\n", + "19 2rDxtYUzTAYJJE3Bl3Z5IN\n", + "Name: id, dtype: object" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_related_artists[\"id\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "3b3e282c", + "metadata": {}, + "outputs": [], + "source": [ + "#Voy a sacar un df con las top-tracks de cada uno de ellos." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "ffe9fb2c", + "metadata": {}, + "outputs": [], + "source": [ + "def make_playlist(dataframe):\n", + " playlist = pd.DataFrame() \n", + " for artist_id in dataframe:\n", + " artist_name = df_related_artists[df_related_artists[\"id\"] == artist_id][\"name\"].values[0]\n", + " top_tracks = get_top_tracks(artist_id)\n", + " top_tracks[\"artist_name\"] = artist_name\n", + " playlist = pd.concat([playlist, top_tracks])\n", + " playlist = playlist.reset_index(drop=True)\n", + " return playlist" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "39be86d6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idhrefnameuriartist_name
02YIOkqKgg3jZEFoL5qcEPThttps://api.spotify.com/v1/tracks/2YIOkqKgg3jZ...The Ratspotify:track:2YIOkqKgg3jZEFoL5qcEPTThe Walkmen
13ji1o94rKqulYA4I2eDKathttps://api.spotify.com/v1/tracks/3ji1o94rKqul...Heavenspotify:track:3ji1o94rKqulYA4I2eDKatThe Walkmen
21BoH28Sopj6wkd1Fbb5B0Khttps://api.spotify.com/v1/tracks/1BoH28Sopj6w...We've Been Hadspotify:track:1BoH28Sopj6wkd1Fbb5B0KThe Walkmen
31cLq7fqXkTWenCCUdogdbDhttps://api.spotify.com/v1/tracks/1cLq7fqXkTWe...On The Waterspotify:track:1cLq7fqXkTWenCCUdogdbDThe Walkmen
42CDdxtnp24GCx6uqxkjbcohttps://api.spotify.com/v1/tracks/2CDdxtnp24GC...Red Moonspotify:track:2CDdxtnp24GCx6uqxkjbcoThe Walkmen
54KlEGra3FXtqfaGfx4k9Hehttps://api.spotify.com/v1/tracks/4KlEGra3FXtq...They're Winningspotify:track:4KlEGra3FXtqfaGfx4k9HeThe Walkmen
62iSMH5kI4Ge0PPuS8xlmWbhttps://api.spotify.com/v1/tracks/2iSMH5kI4Ge0...In The New Yearspotify:track:2iSMH5kI4Ge0PPuS8xlmWbThe Walkmen
72DhBFr722vzR5VF4V2AalWhttps://api.spotify.com/v1/tracks/2DhBFr722vzR...The Witchspotify:track:2DhBFr722vzR5VF4V2AalWThe Walkmen
83308hstupmMUcRwbam0EPshttps://api.spotify.com/v1/tracks/3308hstupmMU...Another One Goes Byspotify:track:3308hstupmMUcRwbam0EPsThe Walkmen
95SVbK6xHvb8Lru8YfBeEFIhttps://api.spotify.com/v1/tracks/5SVbK6xHvb8L...Angela Surf Cityspotify:track:5SVbK6xHvb8Lru8YfBeEFIThe Walkmen
107dfQNWgVxikbrdvEmsfPMAhttps://api.spotify.com/v1/tracks/7dfQNWgVxikb...A 1000 Timesspotify:track:7dfQNWgVxikbrdvEmsfPMARostam
112ZBzOL0HTCQCw7W3luTZtBhttps://api.spotify.com/v1/tracks/2ZBzOL0HTCQC...In a Black Outspotify:track:2ZBzOL0HTCQCw7W3luTZtBRostam
127gmusWQX2xxYxda2ba10N5https://api.spotify.com/v1/tracks/7gmusWQX2xxY...Waterspotify:track:7gmusWQX2xxYxda2ba10N5Rostam
133mPEQcWspL9kFSUQ35bks5https://api.spotify.com/v1/tracks/3mPEQcWspL9k...In a River (Acoustic)spotify:track:3mPEQcWspL9kFSUQ35bks5Rostam
145eum0L07wuKd7Agse5Lgy1https://api.spotify.com/v1/tracks/5eum0L07wuKd...In a Riverspotify:track:5eum0L07wuKd7Agse5Lgy1Rostam
151acb8u70kClk6NjITaZyuGhttps://api.spotify.com/v1/tracks/1acb8u70kClk...Bike Dreamspotify:track:1acb8u70kClk6NjITaZyuGRostam
166OrLovzoCKCwsiGYydDpKthttps://api.spotify.com/v1/tracks/6OrLovzoCKCw...From the Back of a Cab - Ben Böhmer Remixspotify:track:6OrLovzoCKCwsiGYydDpKtRostam
173kduxaRADVX6gVfZ6IeqcBhttps://api.spotify.com/v1/tracks/3kduxaRADVX6...4Runnerspotify:track:3kduxaRADVX6gVfZ6IeqcBRostam
186UuOsC3oeu6SgC6mono7XShttps://api.spotify.com/v1/tracks/6UuOsC3oeu6S...When the Truth Is...spotify:track:6UuOsC3oeu6SgC6mono7XSRostam
190DgWa8oXi3wn3Q67MaHRdwhttps://api.spotify.com/v1/tracks/0DgWa8oXi3wn...Half-Light (feat. Kelly Zutrau)spotify:track:0DgWa8oXi3wn3Q67MaHRdwRostam
\n", + "
" + ], + "text/plain": [ + " id href \\\n", + "0 2YIOkqKgg3jZEFoL5qcEPT https://api.spotify.com/v1/tracks/2YIOkqKgg3jZ... \n", + "1 3ji1o94rKqulYA4I2eDKat https://api.spotify.com/v1/tracks/3ji1o94rKqul... \n", + "2 1BoH28Sopj6wkd1Fbb5B0K https://api.spotify.com/v1/tracks/1BoH28Sopj6w... \n", + "3 1cLq7fqXkTWenCCUdogdbD https://api.spotify.com/v1/tracks/1cLq7fqXkTWe... \n", + "4 2CDdxtnp24GCx6uqxkjbco https://api.spotify.com/v1/tracks/2CDdxtnp24GC... \n", + "5 4KlEGra3FXtqfaGfx4k9He https://api.spotify.com/v1/tracks/4KlEGra3FXtq... \n", + "6 2iSMH5kI4Ge0PPuS8xlmWb https://api.spotify.com/v1/tracks/2iSMH5kI4Ge0... \n", + "7 2DhBFr722vzR5VF4V2AalW https://api.spotify.com/v1/tracks/2DhBFr722vzR... \n", + "8 3308hstupmMUcRwbam0EPs https://api.spotify.com/v1/tracks/3308hstupmMU... \n", + "9 5SVbK6xHvb8Lru8YfBeEFI https://api.spotify.com/v1/tracks/5SVbK6xHvb8L... \n", + "10 7dfQNWgVxikbrdvEmsfPMA https://api.spotify.com/v1/tracks/7dfQNWgVxikb... \n", + "11 2ZBzOL0HTCQCw7W3luTZtB https://api.spotify.com/v1/tracks/2ZBzOL0HTCQC... \n", + "12 7gmusWQX2xxYxda2ba10N5 https://api.spotify.com/v1/tracks/7gmusWQX2xxY... \n", + "13 3mPEQcWspL9kFSUQ35bks5 https://api.spotify.com/v1/tracks/3mPEQcWspL9k... \n", + "14 5eum0L07wuKd7Agse5Lgy1 https://api.spotify.com/v1/tracks/5eum0L07wuKd... \n", + "15 1acb8u70kClk6NjITaZyuG https://api.spotify.com/v1/tracks/1acb8u70kClk... \n", + "16 6OrLovzoCKCwsiGYydDpKt https://api.spotify.com/v1/tracks/6OrLovzoCKCw... \n", + "17 3kduxaRADVX6gVfZ6IeqcB https://api.spotify.com/v1/tracks/3kduxaRADVX6... \n", + "18 6UuOsC3oeu6SgC6mono7XS https://api.spotify.com/v1/tracks/6UuOsC3oeu6S... \n", + "19 0DgWa8oXi3wn3Q67MaHRdw https://api.spotify.com/v1/tracks/0DgWa8oXi3wn... \n", + "\n", + " name \\\n", + "0 The Rat \n", + "1 Heaven \n", + "2 We've Been Had \n", + "3 On The Water \n", + "4 Red Moon \n", + "5 They're Winning \n", + "6 In The New Year \n", + "7 The Witch \n", + "8 Another One Goes By \n", + "9 Angela Surf City \n", + "10 A 1000 Times \n", + "11 In a Black Out \n", + "12 Water \n", + "13 In a River (Acoustic) \n", + "14 In a River \n", + "15 Bike Dream \n", + "16 From the Back of a Cab - Ben Böhmer Remix \n", + "17 4Runner \n", + "18 When the Truth Is... \n", + "19 Half-Light (feat. Kelly Zutrau) \n", + "\n", + " uri artist_name \n", + "0 spotify:track:2YIOkqKgg3jZEFoL5qcEPT The Walkmen \n", + "1 spotify:track:3ji1o94rKqulYA4I2eDKat The Walkmen \n", + "2 spotify:track:1BoH28Sopj6wkd1Fbb5B0K The Walkmen \n", + "3 spotify:track:1cLq7fqXkTWenCCUdogdbD The Walkmen \n", + "4 spotify:track:2CDdxtnp24GCx6uqxkjbco The Walkmen \n", + "5 spotify:track:4KlEGra3FXtqfaGfx4k9He The Walkmen \n", + "6 spotify:track:2iSMH5kI4Ge0PPuS8xlmWb The Walkmen \n", + "7 spotify:track:2DhBFr722vzR5VF4V2AalW The Walkmen \n", + "8 spotify:track:3308hstupmMUcRwbam0EPs The Walkmen \n", + "9 spotify:track:5SVbK6xHvb8Lru8YfBeEFI The Walkmen \n", + "10 spotify:track:7dfQNWgVxikbrdvEmsfPMA Rostam \n", + "11 spotify:track:2ZBzOL0HTCQCw7W3luTZtB Rostam \n", + "12 spotify:track:7gmusWQX2xxYxda2ba10N5 Rostam \n", + "13 spotify:track:3mPEQcWspL9kFSUQ35bks5 Rostam \n", + "14 spotify:track:5eum0L07wuKd7Agse5Lgy1 Rostam \n", + "15 spotify:track:1acb8u70kClk6NjITaZyuG Rostam \n", + "16 spotify:track:6OrLovzoCKCwsiGYydDpKt Rostam \n", + "17 spotify:track:3kduxaRADVX6gVfZ6IeqcB Rostam \n", + "18 spotify:track:6UuOsC3oeu6SgC6mono7XS Rostam \n", + "19 spotify:track:0DgWa8oXi3wn3Q67MaHRdw Rostam " + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "playlist = make_playlist(df_related_artists[\"id\"])\n", + "playlist.head(20)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "56c53536", + "metadata": {}, + "outputs": [], + "source": [ + "#Ahora me voy a quedar sólo con las columnas que quiero\n", + "\n", + "playlist = playlist.drop(\"href\", axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "94a5519e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnameuriartist_name
02YIOkqKgg3jZEFoL5qcEPTThe Ratspotify:track:2YIOkqKgg3jZEFoL5qcEPTThe Walkmen
13ji1o94rKqulYA4I2eDKatHeavenspotify:track:3ji1o94rKqulYA4I2eDKatThe Walkmen
21BoH28Sopj6wkd1Fbb5B0KWe've Been Hadspotify:track:1BoH28Sopj6wkd1Fbb5B0KThe Walkmen
31cLq7fqXkTWenCCUdogdbDOn The Waterspotify:track:1cLq7fqXkTWenCCUdogdbDThe Walkmen
42CDdxtnp24GCx6uqxkjbcoRed Moonspotify:track:2CDdxtnp24GCx6uqxkjbcoThe Walkmen
...............
18564Eddq5GDqysRp5LV6p1gELong Black Veilspotify:track:64Eddq5GDqysRp5LV6p1gEJeff Tweedy
1866VxW98Zfexy6LKeCxlVz8gLow Keyspotify:track:6VxW98Zfexy6LKeCxlVz8gJeff Tweedy
1871x3uCuAcNVZvSwd4WFDzRRWarm (When The Sun Has Died)spotify:track:1x3uCuAcNVZvSwd4WFDzRRJeff Tweedy
1882LjpcdgyjRIIoGUDwDk2kLI Am Trying to Break Your Heartspotify:track:2LjpcdgyjRIIoGUDwDk2kLJeff Tweedy
1890zRooGATNcoPQpSsT6EgscThe Ballad of the Opening Bandspotify:track:0zRooGATNcoPQpSsT6EgscJeff Tweedy
\n", + "

190 rows × 4 columns

\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 2YIOkqKgg3jZEFoL5qcEPT The Rat \n", + "1 3ji1o94rKqulYA4I2eDKat Heaven \n", + "2 1BoH28Sopj6wkd1Fbb5B0K We've Been Had \n", + "3 1cLq7fqXkTWenCCUdogdbD On The Water \n", + "4 2CDdxtnp24GCx6uqxkjbco Red Moon \n", + ".. ... ... \n", + "185 64Eddq5GDqysRp5LV6p1gE Long Black Veil \n", + "186 6VxW98Zfexy6LKeCxlVz8g Low Key \n", + "187 1x3uCuAcNVZvSwd4WFDzRR Warm (When The Sun Has Died) \n", + "188 2LjpcdgyjRIIoGUDwDk2kL I Am Trying to Break Your Heart \n", + "189 0zRooGATNcoPQpSsT6Egsc The Ballad of the Opening Band \n", + "\n", + " uri artist_name \n", + "0 spotify:track:2YIOkqKgg3jZEFoL5qcEPT The Walkmen \n", + "1 spotify:track:3ji1o94rKqulYA4I2eDKat The Walkmen \n", + "2 spotify:track:1BoH28Sopj6wkd1Fbb5B0K The Walkmen \n", + "3 spotify:track:1cLq7fqXkTWenCCUdogdbD The Walkmen \n", + "4 spotify:track:2CDdxtnp24GCx6uqxkjbco The Walkmen \n", + ".. ... ... \n", + "185 spotify:track:64Eddq5GDqysRp5LV6p1gE Jeff Tweedy \n", + "186 spotify:track:6VxW98Zfexy6LKeCxlVz8g Jeff Tweedy \n", + "187 spotify:track:1x3uCuAcNVZvSwd4WFDzRR Jeff Tweedy \n", + "188 spotify:track:2LjpcdgyjRIIoGUDwDk2kL Jeff Tweedy \n", + "189 spotify:track:0zRooGATNcoPQpSsT6Egsc Jeff Tweedy \n", + "\n", + "[190 rows x 4 columns]" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "playlist" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "5c5c7ec8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 spotify:track:2YIOkqKgg3jZEFoL5qcEPT\n", + "1 spotify:track:3ji1o94rKqulYA4I2eDKat\n", + "2 spotify:track:1BoH28Sopj6wkd1Fbb5B0K\n", + "3 spotify:track:1cLq7fqXkTWenCCUdogdbD\n", + "4 spotify:track:2CDdxtnp24GCx6uqxkjbco\n", + " ... \n", + "185 spotify:track:64Eddq5GDqysRp5LV6p1gE\n", + "186 spotify:track:6VxW98Zfexy6LKeCxlVz8g\n", + "187 spotify:track:1x3uCuAcNVZvSwd4WFDzRR\n", + "188 spotify:track:2LjpcdgyjRIIoGUDwDk2kL\n", + "189 spotify:track:0zRooGATNcoPQpSsT6Egsc\n", + "Name: uri, Length: 190, dtype: object" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "playlist[\"uri\"]" + ] + }, + { + "cell_type": "markdown", + "id": "811e1ee5", + "metadata": {}, + "source": [ + "## Voy a intentar publicar la playlist" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "63312430", + "metadata": {}, + "outputs": [], + "source": [ + "import webbrowser\n", + "from urllib.parse import urlparse, parse_qs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f1b15684", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "b2c841ff", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Open the following URL in your web browser to authorize:\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Aquí uso la función que utilicé para mi último lab. \n", + "\n", + "def randomstring(length=16, num_strings=1):\n", + " strings = []\n", + " letters = string.ascii_lowercase\n", + " numbers = \"\".join([str(x) for x in range(1, length)])\n", + " numbers_letters = letters + numbers\n", + " \n", + " for i in range(num_strings):\n", + " string_length = length\n", + " random_string = \"\".join(random.choice(numbers_letters) for i in range(length))\n", + " strings.append(random_string)\n", + " return strings\n", + "\n", + "def login():\n", + " client_id = \"f3c31c7678ae4a9887fc4c626a1e9bc1\"\n", + " redirect_uri = 'https://example.com/callback'\n", + " state = randomstring(16)\n", + " scope = 'playlist-read-private playlist-read-collaborative playlist-modify-private playlist-modify-public'\n", + " auth_url = 'https://accounts.spotify.com/authorize'\n", + " params = {\n", + " 'response_type': 'code',\n", + " 'client_id': client_id,\n", + " 'scope': scope,\n", + " 'redirect_uri': redirect_uri,\n", + " 'state': state\n", + " }\n", + " \n", + " authorization_url = f\"{auth_url}?{'&'.join([f'{key}={value}' for key, value in params.items()])}\"\n", + " print(\"Open the following URL in your web browser to authorize:\")\n", + " return requests.get(authorization_url)\n", + "\n", + "login = login()\n", + "webbrowser.open(login.url)" + ] + }, + { + "cell_type": "markdown", + "id": "28c1d242", + "metadata": {}, + "source": [ + "## Para parsear el token" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "07657ff2", + "metadata": {}, + "outputs": [], + "source": [ + "url = \"https://example.com/callback?code=AQA02URJhL5Em1aAgOaMrl5CQOkG7LU3aJllqDiTXFb6p53jbesY-lcmBUDa3Eiv45QZAm1ns42Kiadbb2MRrL5QEst4_mJnOhzwLa7a-ND9oolOVxU6C2NA10WRU9jyg59o0kgKs10oqajVWIDsvZiQSgjtTl43KERtmM8SlXtCPSGMoL504GGM5jFBndfAIEKlqWdSGijeGqB9fsA_81OclEdlYXwXxZtjPlbOwzt8opudiBSW4MSbPzPtk-8K30XwIsm4YiIWfza7KHru9012jq2GGaprj_AEoZ-Q9dyvWi_oKg&state=%5B%27o59111716dylrug1%27%5D\"\n", + "code = url.replace('https://example.com/callback?code=','').split('&state')[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "0c6dfd09", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'AQA02URJhL5Em1aAgOaMrl5CQOkG7LU3aJllqDiTXFb6p53jbesY-lcmBUDa3Eiv45QZAm1ns42Kiadbb2MRrL5QEst4_mJnOhzwLa7a-ND9oolOVxU6C2NA10WRU9jyg59o0kgKs10oqajVWIDsvZiQSgjtTl43KERtmM8SlXtCPSGMoL504GGM5jFBndfAIEKlqWdSGijeGqB9fsA_81OclEdlYXwXxZtjPlbOwzt8opudiBSW4MSbPzPtk-8K30XwIsm4YiIWfza7KHru9012jq2GGaprj_AEoZ-Q9dyvWi_oKg'" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "code" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "6cb056b5", + "metadata": {}, + "outputs": [], + "source": [ + "def callback():\n", + " redirect_uri='https://example.com/callback'\n", + " auth_options = {\n", + " 'url': 'https://accounts.spotify.com/api/token',\n", + " 'data': {\n", + " 'code': code,\n", + " 'redirect_uri': redirect_uri,\n", + " 'grant_type': 'authorization_code'\n", + " },\n", + " 'headers': {\n", + " 'Content-Type': 'application/x-www-form-urlencoded',\n", + " 'Authorization': 'Basic ' + base64.b64encode(f'{client_id}:{client_secret}'.encode()).decode()\n", + " }\n", + " }\n", + "\n", + " response = requests.post(auth_options['url'], data=auth_options['data'], headers=auth_options['headers'])\n", + " return response.json()\n", + "\n", + "access_token = callback()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "4dee276d", + "metadata": {}, + "outputs": [], + "source": [ + "access_token = access_token[\"access_token\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "8b7e9e60", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter a playlist name:playlist silvia\n", + "Playlist created successfully:\n", + "{'collaborative': False, 'description': 'Description of your playlist playlist silvia', 'external_urls': {'spotify': 'https://open.spotify.com/playlist/362OCdVbQ4xgIGEcCJojmX'}, 'followers': {'href': None, 'total': 0}, 'href': 'https://api.spotify.com/v1/playlists/362OCdVbQ4xgIGEcCJojmX', 'id': '362OCdVbQ4xgIGEcCJojmX', 'images': [], 'name': 'playlist silvia', 'owner': {'display_name': 'Silvia Martínez Valero', 'external_urls': {'spotify': 'https://open.spotify.com/user/1150209529'}, 'href': 'https://api.spotify.com/v1/users/1150209529', 'id': '1150209529', 'type': 'user', 'uri': 'spotify:user:1150209529'}, 'primary_color': None, 'public': True, 'snapshot_id': 'MSxkOTE2MTQ0M2Q0NTMxMjY1OGQ3MDQ4NDYyYjQ0YTdiN2E5MThjMzI4', 'tracks': {'href': 'https://api.spotify.com/v1/playlists/362OCdVbQ4xgIGEcCJojmX/tracks', 'items': [], 'limit': 100, 'next': None, 'offset': 0, 'previous': None, 'total': 0}, 'type': 'playlist', 'uri': 'spotify:playlist:362OCdVbQ4xgIGEcCJojmX'}\n" + ] + } + ], + "source": [ + "# Replace these variables with your own values\n", + "#access_token = “your_access_token_here”\n", + "user_id = \"1150209529\" # “your_user_id_here”\n", + "playlist_name = input(\"Enter a playlist name:\")\n", + "playlist_description = f\"Description of your playlist {playlist_name}\"\n", + "# Define the API endpoint and headers\n", + "api_endpoint = f\"https://api.spotify.com/v1/users/{user_id}/playlists\"\n", + "headers = {\n", + " \"Authorization\": f\"Bearer {access_token}\",\n", + " \"Content-Type\": \"application/json\"\n", + "}\n", + "# Create the playlist\n", + "playlist_data = {\n", + " \"name\": playlist_name,\n", + " \"description\": playlist_description,\n", + " \"public\": True # You can change the visibility as needed\n", + "}\n", + "response = requests.post(api_endpoint, headers=headers, json=playlist_data)\n", + "if response.status_code == 201:\n", + " playlist_info = response.json()\n", + " print(\"Playlist created successfully:\")\n", + " print(playlist_info)\n", + "else:\n", + " print(\"Failed to create the playlist.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "c8a69765", + "metadata": {}, + "outputs": [], + "source": [ + "def add_tracks_to_playlist(access_token, playlist_id):\n", + " api_endpoint = f\"https://api.spotify.com/v1/playlists/{playlist_id}/tracks\"\n", + " headers = {\n", + " \"Authorization\": f\"Bearer {access_token}\",\n", + " \"Content-Type\": \"application/json\"\n", + " }\n", + " data = {\n", + " \"uris\": list(playlist[\"uri\"])[:99]\n", + " }\n", + " response = requests.post(api_endpoint, headers=headers, json=data)\n", + " if response.status_code == 201:\n", + " print(\"Tracks added to the playlist successfully.\")\n", + " else:\n", + " print(\"Failed to add tracks to the playlist\")" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "6aa11625", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tracks added to the playlist successfully.\n" + ] + } + ], + "source": [ + "add_tracks_to_playlist(access_token,\"362OCdVbQ4xgIGEcCJojmX\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python (m1_env)", + "language": "python", + "name": "m1_env" + }, + "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.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/spotify_rest_api_challenge_pruebas.ipynb b/notebooks/spotify_rest_api_challenge_pruebas.ipynb new file mode 100644 index 0000000..bcb0fcb --- /dev/null +++ b/notebooks/spotify_rest_api_challenge_pruebas.ipynb @@ -0,0 +1,2033 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "ef05c1d6", + "metadata": {}, + "source": [ + "![spotify_logo](../img/spotify_logo.png)\n", + "\n", + "# Spotify REST API Challenge\n", + "\n", + "__What to listen?__\n", + "\n", + "Create your own playlist based on the related artists and their most popular tracks using the [Spotify REST API](https://developer.spotify.com/)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "17a49776", + "metadata": {}, + "outputs": [], + "source": [ + "# Imports\n", + "import requests\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "4e97884c", + "metadata": {}, + "source": [ + "### Get access!!!\n", + "\n", + "Get your `client_id` and `client_secret` to generate your __token__ access" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7b5d2e52", + "metadata": {}, + "outputs": [], + "source": [ + "# Generate token with a POST request\n", + "\n", + "client_id = \"f3c31c7678ae4a9887fc4c626a1e9bc1\" #Client ID\n", + "client_secret = \"a7ec3c800df3483cbc128524bec99fd3\" #Cliente Secret\n", + "auth_url = 'https://accounts.spotify.com/api/token'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c7901d1e", + "metadata": {}, + "outputs": [], + "source": [ + "auth_response = requests.post(auth_url, {'grant_type': 'client_credentials',\n", + " 'client_id': client_id,\n", + " 'client_secret': client_secret}).json()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "262e7e18", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'access_token': 'BQDdllnwwsH7IiRVIMdZYgUZZsQalRB91aDK93J-Ee58NAo-2lnRzI_UWDZ__m70s2WrmndDKfz_et7KYicN4bf88AA4TK3PDJqPu19niYbtZVtUCOc',\n", + " 'token_type': 'Bearer',\n", + " 'expires_in': 3600}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "access_token = auth_response['access_token']\n", + "auth_response" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "791c8a7b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'BQDdllnwwsH7IiRVIMdZYgUZZsQalRB91aDK93J-Ee58NAo-2lnRzI_UWDZ__m70s2WrmndDKfz_et7KYicN4bf88AA4TK3PDJqPu19niYbtZVtUCOc'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "access_token" + ] + }, + { + "cell_type": "markdown", + "id": "e617caff", + "metadata": {}, + "source": [ + "### Set your main variables!!!\n", + "\n", + "Set the `base_uri` (i.e.: end-point), parameters and `headers` for your __GET__ operations" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "62e6d4fb", + "metadata": {}, + "outputs": [], + "source": [ + "# Base end-point construction\n", + "\n", + "base_url = 'https://api.spotify.com/v1/'\n", + "resource = 'artists/'\n", + "\n", + "header_info = {'Authorization': 'Bearer {token}'.format(token=access_token)}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "7f1195e2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Authorization': 'Bearer BQDdllnwwsH7IiRVIMdZYgUZZsQalRB91aDK93J-Ee58NAo-2lnRzI_UWDZ__m70s2WrmndDKfz_et7KYicN4bf88AA4TK3PDJqPu19niYbtZVtUCOc'}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "header_info" + ] + }, + { + "cell_type": "markdown", + "id": "16660a9b", + "metadata": {}, + "source": [ + "### Create your new playlist!!!\n", + "\n", + "Use [`/related-artists`](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-related-artists) and [`/top-tracks`](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks) in order to get the data that you need.\n", + "\n", + "__Here you have the different artists to start with:__\n", + "\n", + "- __Option 1:__ 0L8ExT028jH3ddEcZwqJJ5\n", + "\n", + "- __Option 2:__ 4Y7tXHSEejGu1vQ9bwDdXW\n", + "\n", + "- __Option 3:__ 6FBDaR13swtiWwGhX1WQsP\n", + "\n", + "- __Option 4:__ 0kyQwKHCZnKE7kTXkxXjrB\n", + "\n", + "- __Option 5:__ 2d0hyoQ5ynDBnkvAbJKORj\n", + "\n", + "- __Option 6:__ 3bgsNtcf5d5h9jbQbohfBK\n", + "\n", + "- __Option 7:__ 7mWCSSOYqm4E9mB7V4ot6S\n", + "\n", + "- __Option 8:__ 64KEffDW9EtZ1y2vBYgq8T\n", + "\n", + "- __Option 9:__ 4k1ELeJKT1ISyDv8JivPpB\n", + "\n", + "- __Option 10:__ 4Z8W4fKeB5YxbusRsdQVPb\n", + "\n", + "- __Option 11:__ 26dSoYclwsYLMAKD3tpOr4\n", + "\n", + "- __Option 12:__ 7y97mc3bZRFXzT2szRM4L4\n", + "\n", + "- __Option 13:__ 1w5Kfo2jwwIPruYS2UWh56\n", + "\n", + "\n", + "> Remember to check the [Requests](https://requests.readthedocs.io/en/latest/) library docs!!!\n", + "\n", + "---" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "04f85940", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/0kyQwKHCZnKE7kTXkxXjrB/related-artists'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Here you can complete your endpoint URI\n", + "\n", + "artist_id = \"0kyQwKHCZnKE7kTXkxXjrB\"\n", + "method = \"/related-artists\"\n", + "argument = \"market = ES\"\n", + "full_endpoint = base_url + resource + artist_id + method \n", + "full_endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "50ec3959", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Start building your playlist!!!\n", + "related_artists_response = requests.get(full_endpoint, headers = header_info)\n", + "related_artists_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f0900f61", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/38Wv3iDJm7vyk4OvaHWZxx'},\n", + " 'followers': {'href': None, 'total': 69575},\n", + " 'genres': ['venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/38Wv3iDJm7vyk4OvaHWZxx',\n", + " 'id': '38Wv3iDJm7vyk4OvaHWZxx',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb272c47d395c7b3ecb1bf9e55',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174272c47d395c7b3ecb1bf9e55',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178272c47d395c7b3ecb1bf9e55',\n", + " 'width': 160}],\n", + " 'name': 'Zapato3',\n", + " 'popularity': 29,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:38Wv3iDJm7vyk4OvaHWZxx'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6xPMZgR2peupwU41WF9qi7'},\n", + " 'followers': {'href': None, 'total': 42221},\n", + " 'genres': ['venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6xPMZgR2peupwU41WF9qi7',\n", + " 'id': '6xPMZgR2peupwU41WF9qi7',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebbe265e982c8a304bca29e626',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174be265e982c8a304bca29e626',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178be265e982c8a304bca29e626',\n", + " 'width': 160}],\n", + " 'name': 'Malanga',\n", + " 'popularity': 30,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6xPMZgR2peupwU41WF9qi7'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7nx8DlJ8j0sUGBvFtpoEwz'},\n", + " 'followers': {'href': None, 'total': 42712},\n", + " 'genres': ['latin rock', 'rock gotico', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7nx8DlJ8j0sUGBvFtpoEwz',\n", + " 'id': '7nx8DlJ8j0sUGBvFtpoEwz',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb0eabcda0a565599e11ad1160',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051740eabcda0a565599e11ad1160',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1780eabcda0a565599e11ad1160',\n", + " 'width': 160}],\n", + " 'name': 'Sentimiento Muerto',\n", + " 'popularity': 23,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7nx8DlJ8j0sUGBvFtpoEwz'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7jLOrU2XbkSEDJL26be4Mr'},\n", + " 'followers': {'href': None, 'total': 35053},\n", + " 'genres': [],\n", + " 'href': 'https://api.spotify.com/v1/artists/7jLOrU2XbkSEDJL26be4Mr',\n", + " 'id': '7jLOrU2XbkSEDJL26be4Mr',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb8cbc036931e48ab7b603f0bd',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051748cbc036931e48ab7b603f0bd',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1788cbc036931e48ab7b603f0bd',\n", + " 'width': 160}],\n", + " 'name': 'Mulato',\n", + " 'popularity': 5,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7jLOrU2XbkSEDJL26be4Mr'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5nZlhgO7iNedGlO0gKu9us'},\n", + " 'followers': {'href': None, 'total': 98037},\n", + " 'genres': ['venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5nZlhgO7iNedGlO0gKu9us',\n", + " 'id': '5nZlhgO7iNedGlO0gKu9us',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebd915aa801b9c654b6b1ffd44',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174d915aa801b9c654b6b1ffd44',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178d915aa801b9c654b6b1ffd44',\n", + " 'width': 160}],\n", + " 'name': 'King Chango',\n", + " 'popularity': 40,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5nZlhgO7iNedGlO0gKu9us'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1b2FooqkEdKdykGcdEof02'},\n", + " 'followers': {'href': None, 'total': 54368},\n", + " 'genres': ['venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/1b2FooqkEdKdykGcdEof02',\n", + " 'id': '1b2FooqkEdKdykGcdEof02',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eba67da944d309915e1407975d',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174a67da944d309915e1407975d',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178a67da944d309915e1407975d',\n", + " 'width': 160}],\n", + " 'name': 'Mermelada Bunch',\n", + " 'popularity': 24,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1b2FooqkEdKdykGcdEof02'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0WmmhplJiEohqKsYoRLsbq'},\n", + " 'followers': {'href': None, 'total': 30652},\n", + " 'genres': ['venezuelan hip hop', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0WmmhplJiEohqKsYoRLsbq',\n", + " 'id': '0WmmhplJiEohqKsYoRLsbq',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb9877593d432b8443b98ac093',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051749877593d432b8443b98ac093',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1789877593d432b8443b98ac093',\n", + " 'width': 160}],\n", + " 'name': 'PapaShanty SaundSystem',\n", + " 'popularity': 22,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0WmmhplJiEohqKsYoRLsbq'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/48NeXVOrqMUIRc4M8g0lnZ'},\n", + " 'followers': {'href': None, 'total': 37419},\n", + " 'genres': ['classic venezuelan pop', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/48NeXVOrqMUIRc4M8g0lnZ',\n", + " 'id': '48NeXVOrqMUIRc4M8g0lnZ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273ece78d66f04c9d05a7901371',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02ece78d66f04c9d05a7901371',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851ece78d66f04c9d05a7901371',\n", + " 'width': 64}],\n", + " 'name': 'Aditus',\n", + " 'popularity': 25,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:48NeXVOrqMUIRc4M8g0lnZ'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2jZIvxOfIP6hhzthCqRmqI'},\n", + " 'followers': {'href': None, 'total': 27537},\n", + " 'genres': ['venezuelan hip hop', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2jZIvxOfIP6hhzthCqRmqI',\n", + " 'id': '2jZIvxOfIP6hhzthCqRmqI',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b2734b3f3163fc13dc1a8757d396',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e024b3f3163fc13dc1a8757d396',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d000048514b3f3163fc13dc1a8757d396',\n", + " 'width': 64}],\n", + " 'name': 'Cuarto Poder',\n", + " 'popularity': 21,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2jZIvxOfIP6hhzthCqRmqI'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0gt2Xy6uSRTFTWYrHOHx82'},\n", + " 'followers': {'href': None, 'total': 24642},\n", + " 'genres': ['venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0gt2Xy6uSRTFTWYrHOHx82',\n", + " 'id': '0gt2Xy6uSRTFTWYrHOHx82',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebcc1ba8f81e2482e1fedc9a24',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174cc1ba8f81e2482e1fedc9a24',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178cc1ba8f81e2482e1fedc9a24',\n", + " 'width': 160}],\n", + " 'name': 'Los Mentas',\n", + " 'popularity': 17,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0gt2Xy6uSRTFTWYrHOHx82'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2i99x70sDfixFZ95bIYayb'},\n", + " 'followers': {'href': None, 'total': 30453},\n", + " 'genres': ['venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2i99x70sDfixFZ95bIYayb',\n", + " 'id': '2i99x70sDfixFZ95bIYayb',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb5aadf695d08d1eda5af7bf1e',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051745aadf695d08d1eda5af7bf1e',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1785aadf695d08d1eda5af7bf1e',\n", + " 'width': 160}],\n", + " 'name': 'Tomates Fritos',\n", + " 'popularity': 24,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2i99x70sDfixFZ95bIYayb'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5rTdxb1YVVZMXscz4wexGu'},\n", + " 'followers': {'href': None, 'total': 62438},\n", + " 'genres': ['venezuelan hip hop', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5rTdxb1YVVZMXscz4wexGu',\n", + " 'id': '5rTdxb1YVVZMXscz4wexGu',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebd7aa84d02112f3b4f4903ebf',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174d7aa84d02112f3b4f4903ebf',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178d7aa84d02112f3b4f4903ebf',\n", + " 'width': 160}],\n", + " 'name': '3 Dueños',\n", + " 'popularity': 33,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5rTdxb1YVVZMXscz4wexGu'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2TPLqqQ9arRHA6Xt7gvZTZ'},\n", + " 'followers': {'href': None, 'total': 25341},\n", + " 'genres': ['caracas indie', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2TPLqqQ9arRHA6Xt7gvZTZ',\n", + " 'id': '2TPLqqQ9arRHA6Xt7gvZTZ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb72bd2f8d2a6142eda84bec24',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517472bd2f8d2a6142eda84bec24',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17872bd2f8d2a6142eda84bec24',\n", + " 'width': 160}],\n", + " 'name': 'Candy66',\n", + " 'popularity': 22,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2TPLqqQ9arRHA6Xt7gvZTZ'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3ZReJfzCEVpHWUSWd5emic'},\n", + " 'followers': {'href': None, 'total': 49390},\n", + " 'genres': ['classic venezuelan pop', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3ZReJfzCEVpHWUSWd5emic',\n", + " 'id': '3ZReJfzCEVpHWUSWd5emic',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebb075a2351facacd595bd4aa5',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174b075a2351facacd595bd4aa5',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178b075a2351facacd595bd4aa5',\n", + " 'width': 160}],\n", + " 'name': 'Frank Quintero',\n", + " 'popularity': 28,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3ZReJfzCEVpHWUSWd5emic'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0D8yIOlFPxp7OL6n6UzJ38'},\n", + " 'followers': {'href': None, 'total': 88901},\n", + " 'genres': ['classic venezuelan pop', 'gaita zuliana'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0D8yIOlFPxp7OL6n6UzJ38',\n", + " 'id': '0D8yIOlFPxp7OL6n6UzJ38',\n", + " 'images': [{'height': 1000,\n", + " 'url': 'https://i.scdn.co/image/33917a8ffe165003b49e95a03077c234e0979756',\n", + " 'width': 1000},\n", + " {'height': 640,\n", + " 'url': 'https://i.scdn.co/image/cd8a6e7d007c430ddeba76503a212450d3c7b1bf',\n", + " 'width': 640},\n", + " {'height': 200,\n", + " 'url': 'https://i.scdn.co/image/0d559560a7f1e714302eb02048a244deab679519',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/85e27c08f38b9869d757e4ac8a78e3fd4062db6e',\n", + " 'width': 64}],\n", + " 'name': 'Gran Coquivacoa',\n", + " 'popularity': 41,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0D8yIOlFPxp7OL6n6UzJ38'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4SBlgsYD1T6dUV17RDrEBN'},\n", + " 'followers': {'href': None, 'total': 20543},\n", + " 'genres': ['venezuelan hip hop', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4SBlgsYD1T6dUV17RDrEBN',\n", + " 'id': '4SBlgsYD1T6dUV17RDrEBN',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eba4eeae888ec5fadac554a03a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174a4eeae888ec5fadac554a03a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178a4eeae888ec5fadac554a03a',\n", + " 'width': 160}],\n", + " 'name': 'La Corte',\n", + " 'popularity': 19,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4SBlgsYD1T6dUV17RDrEBN'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2zwh4WnVBGZcfnllC7DUxt'},\n", + " 'followers': {'href': None, 'total': 70202},\n", + " 'genres': ['caracas indie', 'rock en espanol', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2zwh4WnVBGZcfnllC7DUxt',\n", + " 'id': '2zwh4WnVBGZcfnllC7DUxt',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb17b22b5d7cc2b0043ea039b3',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517417b22b5d7cc2b0043ea039b3',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17817b22b5d7cc2b0043ea039b3',\n", + " 'width': 160}],\n", + " 'name': 'Viniloversus',\n", + " 'popularity': 36,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2zwh4WnVBGZcfnllC7DUxt'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6dTMVeRubUzINO6gmQhWat'},\n", + " 'followers': {'href': None, 'total': 43757},\n", + " 'genres': ['classic venezuelan pop',\n", + " 'folklore venezolano',\n", + " 'musica llanera',\n", + " 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6dTMVeRubUzINO6gmQhWat',\n", + " 'id': '6dTMVeRubUzINO6gmQhWat',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273f3ab1260f5e5858750e11b47',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02f3ab1260f5e5858750e11b47',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851f3ab1260f5e5858750e11b47',\n", + " 'width': 64}],\n", + " 'name': 'Un Solo Pueblo',\n", + " 'popularity': 27,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6dTMVeRubUzINO6gmQhWat'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4FNbNj9mlDLitaic9vXlwZ'},\n", + " 'followers': {'href': None, 'total': 102961},\n", + " 'genres': ['pop reggaeton', 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4FNbNj9mlDLitaic9vXlwZ',\n", + " 'id': '4FNbNj9mlDLitaic9vXlwZ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb1a56b039362f96ac5cdd952d',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051741a56b039362f96ac5cdd952d',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1781a56b039362f96ac5cdd952d',\n", + " 'width': 160}],\n", + " 'name': 'Tecupae',\n", + " 'popularity': 34,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4FNbNj9mlDLitaic9vXlwZ'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1V6FooKFiokndcPHKJ4Tmz'},\n", + " 'followers': {'href': None, 'total': 96047},\n", + " 'genres': ['classic venezuelan pop', 'gaita zuliana'],\n", + " 'href': 'https://api.spotify.com/v1/artists/1V6FooKFiokndcPHKJ4Tmz',\n", + " 'id': '1V6FooKFiokndcPHKJ4Tmz',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb4daf2241bb915e6358e06f3e',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051744daf2241bb915e6358e06f3e',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1784daf2241bb915e6358e06f3e',\n", + " 'width': 160}],\n", + " 'name': 'Maracaibo 15',\n", + " 'popularity': 42,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1V6FooKFiokndcPHKJ4Tmz'}]}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "related_artists_json = related_artists_response.json()\n", + "related_artists_json" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "80148a1e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Zapato3',\n", + " 'Malanga',\n", + " 'Sentimiento Muerto',\n", + " 'Mulato',\n", + " 'King Chango',\n", + " 'Mermelada Bunch',\n", + " 'PapaShanty SaundSystem',\n", + " 'Aditus',\n", + " 'Cuarto Poder',\n", + " 'Los Mentas',\n", + " 'Tomates Fritos',\n", + " '3 Dueños',\n", + " 'Candy66',\n", + " 'Frank Quintero',\n", + " 'Gran Coquivacoa',\n", + " 'La Corte',\n", + " 'Viniloversus',\n", + " 'Un Solo Pueblo',\n", + " 'Tecupae',\n", + " 'Maracaibo 15']" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[related_artists_json[\"artists\"][i][\"name\"] for i in range(len(related_artists_json[\"artists\"]))]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "7ced2ebf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/0kyQwKHCZnKE7kTXkxXjrB/top-tracks?market=ES'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "artist_id = \"0kyQwKHCZnKE7kTXkxXjrB\"\n", + "method = \"/top-tracks\"\n", + "argument = \"?market=ES\"\n", + "full_endpoint = base_url + resource + artist_id + method + argument\n", + "full_endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "b4985554", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "top_tracks_response = requests.get(full_endpoint, headers = header_info)\n", + "top_tracks_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "228bbcc9", + "metadata": {}, + "outputs": [], + "source": [ + "top_tracks_json = top_tracks_response.json()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "2a614fac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Allá Cayó',\n", + " 'Los Que Se Quedan, los Que Se Van',\n", + " 'Tiembla - En Vivo',\n", + " 'La Danza de los Esqueletos',\n", + " 'La Cumbia - Desorden Público rinde Homenaje al Indio Pastor López',\n", + " 'Tiemble',\n", + " 'Combate',\n", + " 'Música de Fiesta',\n", + " 'Traicionera / El Reo Ausente - Desorden Público rinde Homenaje al Indio Pastor López',\n", + " 'Latex - En Vivo']" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[top_tracks_json[\"tracks\"][i][\"name\"] for i in range(len(top_tracks_json[\"tracks\"]))]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "daf0fdea", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://api.spotify.com/v1/artists/0kyQwKHCZnKE7kTXkxXjrB\n" + ] + }, + { + "data": { + "text/plain": [ + "{'external_urls': {'spotify': 'https://open.spotify.com/artist/0kyQwKHCZnKE7kTXkxXjrB'},\n", + " 'followers': {'href': None, 'total': 136338},\n", + " 'genres': ['caracas indie',\n", + " 'latin alternative',\n", + " 'latin ska',\n", + " 'venezuelan rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0kyQwKHCZnKE7kTXkxXjrB',\n", + " 'id': '0kyQwKHCZnKE7kTXkxXjrB',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb856a4c8434bc80e2518a1091',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174856a4c8434bc80e2518a1091',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178856a4c8434bc80e2518a1091',\n", + " 'width': 160}],\n", + " 'name': 'Desorden Público',\n", + " 'popularity': 37,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0kyQwKHCZnKE7kTXkxXjrB'}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "id_selected = \"0kyQwKHCZnKE7kTXkxXjrB\"\n", + "resource = \"artists\"\n", + "parameters = f\"/{id_selected}\"\n", + "url = base_url + resource + parameters\n", + "print(url)\n", + "response = requests.get(url, headers=header_info).json()\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "cad5dc33", + "metadata": {}, + "outputs": [], + "source": [ + "dict_artist = dict((key, [response[key]]) for key in [\"id\", \"name\", \"genres\", \"popularity\", \"followers\"] if key in response.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "c4a185b8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': ['0kyQwKHCZnKE7kTXkxXjrB'],\n", + " 'name': ['Desorden Público'],\n", + " 'genres': [['caracas indie',\n", + " 'latin alternative',\n", + " 'latin ska',\n", + " 'venezuelan rock']],\n", + " 'popularity': [37],\n", + " 'followers': [{'href': None, 'total': 136338}]}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "00868c77", + "metadata": {}, + "outputs": [], + "source": [ + "def get_top_tracks(artist_id):\n", + " resource = \"artists\"\n", + " parameters = f\"/{artist_id}/top-tracks?market=ES\"\n", + " url = base_url + resource + parameters\n", + " response = requests.get(url, headers=header_info).json()\n", + " df_tracks = pd.DataFrame(response[\"tracks\"])[[\"id\", \"href\", \"name\", \"uri\"]]\n", + " df_tracks[\"related_id\"] = artist_id\n", + " return df_tracks" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "97ac3902", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idhrefnameurirelated_id
06F7uqfzvcdl5Y42mJBVc9Vhttps://api.spotify.com/v1/tracks/6F7uqfzvcdl5...Allá Cayóspotify:track:6F7uqfzvcdl5Y42mJBVc9V0kyQwKHCZnKE7kTXkxXjrB
12ntUj3hnSU7GQTKA9oZWW1https://api.spotify.com/v1/tracks/2ntUj3hnSU7G...Los Que Se Quedan, los Que Se Vanspotify:track:2ntUj3hnSU7GQTKA9oZWW10kyQwKHCZnKE7kTXkxXjrB
26tJn0JYD6QKE6eXbh4829bhttps://api.spotify.com/v1/tracks/6tJn0JYD6QKE...Tiembla - En Vivospotify:track:6tJn0JYD6QKE6eXbh4829b0kyQwKHCZnKE7kTXkxXjrB
31f9X3c8Bzn79zkCwnZ2vayhttps://api.spotify.com/v1/tracks/1f9X3c8Bzn79...La Danza de los Esqueletosspotify:track:1f9X3c8Bzn79zkCwnZ2vay0kyQwKHCZnKE7kTXkxXjrB
41TQLNy86xeKIBnB4O2LOWrhttps://api.spotify.com/v1/tracks/1TQLNy86xeKI...La Cumbia - Desorden Público rinde Homenaje al...spotify:track:1TQLNy86xeKIBnB4O2LOWr0kyQwKHCZnKE7kTXkxXjrB
51eEFMib4nzsUaeWYN0n5Othttps://api.spotify.com/v1/tracks/1eEFMib4nzsU...Tiemblespotify:track:1eEFMib4nzsUaeWYN0n5Ot0kyQwKHCZnKE7kTXkxXjrB
66B9NhbeAAvCX0oqQLL4inQhttps://api.spotify.com/v1/tracks/6B9NhbeAAvCX...Combatespotify:track:6B9NhbeAAvCX0oqQLL4inQ0kyQwKHCZnKE7kTXkxXjrB
75iuzPrZExQitcYGBShOSvWhttps://api.spotify.com/v1/tracks/5iuzPrZExQit...Música de Fiestaspotify:track:5iuzPrZExQitcYGBShOSvW0kyQwKHCZnKE7kTXkxXjrB
84DPRgzo3TmEOM6DZM11cZUhttps://api.spotify.com/v1/tracks/4DPRgzo3TmEO...Traicionera / El Reo Ausente - Desorden Públic...spotify:track:4DPRgzo3TmEOM6DZM11cZU0kyQwKHCZnKE7kTXkxXjrB
94KrHDgpSoSFj6zDj3Jzbz3https://api.spotify.com/v1/tracks/4KrHDgpSoSFj...Latex - En Vivospotify:track:4KrHDgpSoSFj6zDj3Jzbz30kyQwKHCZnKE7kTXkxXjrB
\n", + "
" + ], + "text/plain": [ + " id href \\\n", + "0 6F7uqfzvcdl5Y42mJBVc9V https://api.spotify.com/v1/tracks/6F7uqfzvcdl5... \n", + "1 2ntUj3hnSU7GQTKA9oZWW1 https://api.spotify.com/v1/tracks/2ntUj3hnSU7G... \n", + "2 6tJn0JYD6QKE6eXbh4829b https://api.spotify.com/v1/tracks/6tJn0JYD6QKE... \n", + "3 1f9X3c8Bzn79zkCwnZ2vay https://api.spotify.com/v1/tracks/1f9X3c8Bzn79... \n", + "4 1TQLNy86xeKIBnB4O2LOWr https://api.spotify.com/v1/tracks/1TQLNy86xeKI... \n", + "5 1eEFMib4nzsUaeWYN0n5Ot https://api.spotify.com/v1/tracks/1eEFMib4nzsU... \n", + "6 6B9NhbeAAvCX0oqQLL4inQ https://api.spotify.com/v1/tracks/6B9NhbeAAvCX... \n", + "7 5iuzPrZExQitcYGBShOSvW https://api.spotify.com/v1/tracks/5iuzPrZExQit... \n", + "8 4DPRgzo3TmEOM6DZM11cZU https://api.spotify.com/v1/tracks/4DPRgzo3TmEO... \n", + "9 4KrHDgpSoSFj6zDj3Jzbz3 https://api.spotify.com/v1/tracks/4KrHDgpSoSFj... \n", + "\n", + " name \\\n", + "0 Allá Cayó \n", + "1 Los Que Se Quedan, los Que Se Van \n", + "2 Tiembla - En Vivo \n", + "3 La Danza de los Esqueletos \n", + "4 La Cumbia - Desorden Público rinde Homenaje al... \n", + "5 Tiemble \n", + "6 Combate \n", + "7 Música de Fiesta \n", + "8 Traicionera / El Reo Ausente - Desorden Públic... \n", + "9 Latex - En Vivo \n", + "\n", + " uri related_id \n", + "0 spotify:track:6F7uqfzvcdl5Y42mJBVc9V 0kyQwKHCZnKE7kTXkxXjrB \n", + "1 spotify:track:2ntUj3hnSU7GQTKA9oZWW1 0kyQwKHCZnKE7kTXkxXjrB \n", + "2 spotify:track:6tJn0JYD6QKE6eXbh4829b 0kyQwKHCZnKE7kTXkxXjrB \n", + "3 spotify:track:1f9X3c8Bzn79zkCwnZ2vay 0kyQwKHCZnKE7kTXkxXjrB \n", + "4 spotify:track:1TQLNy86xeKIBnB4O2LOWr 0kyQwKHCZnKE7kTXkxXjrB \n", + "5 spotify:track:1eEFMib4nzsUaeWYN0n5Ot 0kyQwKHCZnKE7kTXkxXjrB \n", + "6 spotify:track:6B9NhbeAAvCX0oqQLL4inQ 0kyQwKHCZnKE7kTXkxXjrB \n", + "7 spotify:track:5iuzPrZExQitcYGBShOSvW 0kyQwKHCZnKE7kTXkxXjrB \n", + "8 spotify:track:4DPRgzo3TmEOM6DZM11cZU 0kyQwKHCZnKE7kTXkxXjrB \n", + "9 spotify:track:4KrHDgpSoSFj6zDj3Jzbz3 0kyQwKHCZnKE7kTXkxXjrB " + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_top_tracks(artist_id = \"0kyQwKHCZnKE7kTXkxXjrB\")" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "20c8dd11", + "metadata": {}, + "outputs": [], + "source": [ + "df_artist = pd.DataFrame(dict_artist)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "d4b5e79f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamegenrespopularityfollowers
00kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37{'href': None, 'total': 136338}
\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "\n", + " genres popularity \\\n", + "0 [caracas indie, latin alternative, latin ska, ... 37 \n", + "\n", + " followers \n", + "0 {'href': None, 'total': 136338} " + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "79d82dad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
artist_idartist_nameartist_genresartist_popularityartist_followers
00kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37{'href': None, 'total': 136338}
\n", + "
" + ], + "text/plain": [ + " artist_id artist_name \\\n", + "0 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "\n", + " artist_genres artist_popularity \\\n", + "0 [caracas indie, latin alternative, latin ska, ... 37 \n", + "\n", + " artist_followers \n", + "0 {'href': None, 'total': 136338} " + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_artist = df_artist.rename(columns = {\"id\": \"artist_id\",\n", + " \"name\":\"artist_name\",\n", + " \"genres\":\"artist_genres\",\n", + " \"popularity\": \"artist_popularity\",\n", + " \"followers\": \"artist_followers\"\n", + " })\n", + "df_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "dd3b4c65", + "metadata": {}, + "outputs": [], + "source": [ + "df_artist.drop(\"artist_followers\", axis = 1, inplace = True)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "9629ab32", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
artist_idartist_nameartist_genresartist_popularity
00kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
\n", + "
" + ], + "text/plain": [ + " artist_id artist_name \\\n", + "0 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "\n", + " artist_genres artist_popularity \n", + "0 [caracas indie, latin alternative, latin ska, ... 37 " + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "a204db5a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://api.spotify.com/v1/artists/0kyQwKHCZnKE7kTXkxXjrB/related-artists\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamegenrespopularityfollowers
038Wv3iDJm7vyk4OvaHWZxxZapato3[venezuelan rock]29{'href': None, 'total': 69575}
16xPMZgR2peupwU41WF9qi7Malanga[venezuelan rock]30{'href': None, 'total': 42221}
27nx8DlJ8j0sUGBvFtpoEwzSentimiento Muerto[latin rock, rock gotico, venezuelan rock]23{'href': None, 'total': 42712}
37jLOrU2XbkSEDJL26be4MrMulato[]5{'href': None, 'total': 35053}
45nZlhgO7iNedGlO0gKu9usKing Chango[venezuelan rock]40{'href': None, 'total': 98037}
51b2FooqkEdKdykGcdEof02Mermelada Bunch[venezuelan rock]24{'href': None, 'total': 54368}
60WmmhplJiEohqKsYoRLsbqPapaShanty SaundSystem[venezuelan hip hop, venezuelan rock]22{'href': None, 'total': 30652}
748NeXVOrqMUIRc4M8g0lnZAditus[classic venezuelan pop, venezuelan rock]25{'href': None, 'total': 37419}
82jZIvxOfIP6hhzthCqRmqICuarto Poder[venezuelan hip hop, venezuelan rock]21{'href': None, 'total': 27537}
90gt2Xy6uSRTFTWYrHOHx82Los Mentas[venezuelan rock]17{'href': None, 'total': 24642}
102i99x70sDfixFZ95bIYaybTomates Fritos[venezuelan rock]24{'href': None, 'total': 30453}
115rTdxb1YVVZMXscz4wexGu3 Dueños[venezuelan hip hop, venezuelan rock]33{'href': None, 'total': 62438}
122TPLqqQ9arRHA6Xt7gvZTZCandy66[caracas indie, venezuelan rock]22{'href': None, 'total': 25341}
133ZReJfzCEVpHWUSWd5emicFrank Quintero[classic venezuelan pop, venezuelan rock]28{'href': None, 'total': 49390}
140D8yIOlFPxp7OL6n6UzJ38Gran Coquivacoa[classic venezuelan pop, gaita zuliana]41{'href': None, 'total': 88901}
154SBlgsYD1T6dUV17RDrEBNLa Corte[venezuelan hip hop, venezuelan rock]19{'href': None, 'total': 20543}
162zwh4WnVBGZcfnllC7DUxtViniloversus[caracas indie, rock en espanol, venezuelan rock]36{'href': None, 'total': 70202}
176dTMVeRubUzINO6gmQhWatUn Solo Pueblo[classic venezuelan pop, folklore venezolano, ...27{'href': None, 'total': 43757}
184FNbNj9mlDLitaic9vXlwZTecupae[pop reggaeton, venezuelan rock]34{'href': None, 'total': 102961}
191V6FooKFiokndcPHKJ4TmzMaracaibo 15[classic venezuelan pop, gaita zuliana]42{'href': None, 'total': 96047}
\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 38Wv3iDJm7vyk4OvaHWZxx Zapato3 \n", + "1 6xPMZgR2peupwU41WF9qi7 Malanga \n", + "2 7nx8DlJ8j0sUGBvFtpoEwz Sentimiento Muerto \n", + "3 7jLOrU2XbkSEDJL26be4Mr Mulato \n", + "4 5nZlhgO7iNedGlO0gKu9us King Chango \n", + "5 1b2FooqkEdKdykGcdEof02 Mermelada Bunch \n", + "6 0WmmhplJiEohqKsYoRLsbq PapaShanty SaundSystem \n", + "7 48NeXVOrqMUIRc4M8g0lnZ Aditus \n", + "8 2jZIvxOfIP6hhzthCqRmqI Cuarto Poder \n", + "9 0gt2Xy6uSRTFTWYrHOHx82 Los Mentas \n", + "10 2i99x70sDfixFZ95bIYayb Tomates Fritos \n", + "11 5rTdxb1YVVZMXscz4wexGu 3 Dueños \n", + "12 2TPLqqQ9arRHA6Xt7gvZTZ Candy66 \n", + "13 3ZReJfzCEVpHWUSWd5emic Frank Quintero \n", + "14 0D8yIOlFPxp7OL6n6UzJ38 Gran Coquivacoa \n", + "15 4SBlgsYD1T6dUV17RDrEBN La Corte \n", + "16 2zwh4WnVBGZcfnllC7DUxt Viniloversus \n", + "17 6dTMVeRubUzINO6gmQhWat Un Solo Pueblo \n", + "18 4FNbNj9mlDLitaic9vXlwZ Tecupae \n", + "19 1V6FooKFiokndcPHKJ4Tmz Maracaibo 15 \n", + "\n", + " genres popularity \\\n", + "0 [venezuelan rock] 29 \n", + "1 [venezuelan rock] 30 \n", + "2 [latin rock, rock gotico, venezuelan rock] 23 \n", + "3 [] 5 \n", + "4 [venezuelan rock] 40 \n", + "5 [venezuelan rock] 24 \n", + "6 [venezuelan hip hop, venezuelan rock] 22 \n", + "7 [classic venezuelan pop, venezuelan rock] 25 \n", + "8 [venezuelan hip hop, venezuelan rock] 21 \n", + "9 [venezuelan rock] 17 \n", + "10 [venezuelan rock] 24 \n", + "11 [venezuelan hip hop, venezuelan rock] 33 \n", + "12 [caracas indie, venezuelan rock] 22 \n", + "13 [classic venezuelan pop, venezuelan rock] 28 \n", + "14 [classic venezuelan pop, gaita zuliana] 41 \n", + "15 [venezuelan hip hop, venezuelan rock] 19 \n", + "16 [caracas indie, rock en espanol, venezuelan rock] 36 \n", + "17 [classic venezuelan pop, folklore venezolano, ... 27 \n", + "18 [pop reggaeton, venezuelan rock] 34 \n", + "19 [classic venezuelan pop, gaita zuliana] 42 \n", + "\n", + " followers \n", + "0 {'href': None, 'total': 69575} \n", + "1 {'href': None, 'total': 42221} \n", + "2 {'href': None, 'total': 42712} \n", + "3 {'href': None, 'total': 35053} \n", + "4 {'href': None, 'total': 98037} \n", + "5 {'href': None, 'total': 54368} \n", + "6 {'href': None, 'total': 30652} \n", + "7 {'href': None, 'total': 37419} \n", + "8 {'href': None, 'total': 27537} \n", + "9 {'href': None, 'total': 24642} \n", + "10 {'href': None, 'total': 30453} \n", + "11 {'href': None, 'total': 62438} \n", + "12 {'href': None, 'total': 25341} \n", + "13 {'href': None, 'total': 49390} \n", + "14 {'href': None, 'total': 88901} \n", + "15 {'href': None, 'total': 20543} \n", + "16 {'href': None, 'total': 70202} \n", + "17 {'href': None, 'total': 43757} \n", + "18 {'href': None, 'total': 102961} \n", + "19 {'href': None, 'total': 96047} " + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parameters = f\"/{id_selected}/related-artists\"\n", + "url = base_url + resource + parameters\n", + "print(url)\n", + "response = requests.get(url, headers=header_info).json()\n", + "response\n", + "df_related_artists= pd.DataFrame(response[\"artists\"])[[\"id\", \"name\", \"genres\", \"popularity\", \"followers\"]]\n", + "df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "17fa1fd9", + "metadata": {}, + "outputs": [], + "source": [ + "df_related_artists = df_related_artists.rename(columns={\"id\": \"related_id\",\n", + " \"name\":\"related_name\",\n", + " \"genres\":\"related_genres\",\n", + " \"popularity\": \"related_popularity\",\n", + " \"followers\": \"related_followers\"\n", + " })" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "f83905c9", + "metadata": {}, + "outputs": [], + "source": [ + "df_related_artists[\"artist_id\"] = id_selected" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "6a4086c4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
related_idrelated_namerelated_genresrelated_popularityrelated_followersartist_idartist_nameartist_genresartist_popularity
038Wv3iDJm7vyk4OvaHWZxxZapato3[venezuelan rock]29{'href': None, 'total': 69575}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
16xPMZgR2peupwU41WF9qi7Malanga[venezuelan rock]30{'href': None, 'total': 42221}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
27nx8DlJ8j0sUGBvFtpoEwzSentimiento Muerto[latin rock, rock gotico, venezuelan rock]23{'href': None, 'total': 42712}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
37jLOrU2XbkSEDJL26be4MrMulato[]5{'href': None, 'total': 35053}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
45nZlhgO7iNedGlO0gKu9usKing Chango[venezuelan rock]40{'href': None, 'total': 98037}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
51b2FooqkEdKdykGcdEof02Mermelada Bunch[venezuelan rock]24{'href': None, 'total': 54368}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
60WmmhplJiEohqKsYoRLsbqPapaShanty SaundSystem[venezuelan hip hop, venezuelan rock]22{'href': None, 'total': 30652}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
748NeXVOrqMUIRc4M8g0lnZAditus[classic venezuelan pop, venezuelan rock]25{'href': None, 'total': 37419}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
82jZIvxOfIP6hhzthCqRmqICuarto Poder[venezuelan hip hop, venezuelan rock]21{'href': None, 'total': 27537}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
90gt2Xy6uSRTFTWYrHOHx82Los Mentas[venezuelan rock]17{'href': None, 'total': 24642}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
102i99x70sDfixFZ95bIYaybTomates Fritos[venezuelan rock]24{'href': None, 'total': 30453}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
115rTdxb1YVVZMXscz4wexGu3 Dueños[venezuelan hip hop, venezuelan rock]33{'href': None, 'total': 62438}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
122TPLqqQ9arRHA6Xt7gvZTZCandy66[caracas indie, venezuelan rock]22{'href': None, 'total': 25341}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
133ZReJfzCEVpHWUSWd5emicFrank Quintero[classic venezuelan pop, venezuelan rock]28{'href': None, 'total': 49390}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
140D8yIOlFPxp7OL6n6UzJ38Gran Coquivacoa[classic venezuelan pop, gaita zuliana]41{'href': None, 'total': 88901}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
154SBlgsYD1T6dUV17RDrEBNLa Corte[venezuelan hip hop, venezuelan rock]19{'href': None, 'total': 20543}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
162zwh4WnVBGZcfnllC7DUxtViniloversus[caracas indie, rock en espanol, venezuelan rock]36{'href': None, 'total': 70202}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
176dTMVeRubUzINO6gmQhWatUn Solo Pueblo[classic venezuelan pop, folklore venezolano, ...27{'href': None, 'total': 43757}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
184FNbNj9mlDLitaic9vXlwZTecupae[pop reggaeton, venezuelan rock]34{'href': None, 'total': 102961}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
191V6FooKFiokndcPHKJ4TmzMaracaibo 15[classic venezuelan pop, gaita zuliana]42{'href': None, 'total': 96047}0kyQwKHCZnKE7kTXkxXjrBDesorden Público[caracas indie, latin alternative, latin ska, ...37
\n", + "
" + ], + "text/plain": [ + " related_id related_name \\\n", + "0 38Wv3iDJm7vyk4OvaHWZxx Zapato3 \n", + "1 6xPMZgR2peupwU41WF9qi7 Malanga \n", + "2 7nx8DlJ8j0sUGBvFtpoEwz Sentimiento Muerto \n", + "3 7jLOrU2XbkSEDJL26be4Mr Mulato \n", + "4 5nZlhgO7iNedGlO0gKu9us King Chango \n", + "5 1b2FooqkEdKdykGcdEof02 Mermelada Bunch \n", + "6 0WmmhplJiEohqKsYoRLsbq PapaShanty SaundSystem \n", + "7 48NeXVOrqMUIRc4M8g0lnZ Aditus \n", + "8 2jZIvxOfIP6hhzthCqRmqI Cuarto Poder \n", + "9 0gt2Xy6uSRTFTWYrHOHx82 Los Mentas \n", + "10 2i99x70sDfixFZ95bIYayb Tomates Fritos \n", + "11 5rTdxb1YVVZMXscz4wexGu 3 Dueños \n", + "12 2TPLqqQ9arRHA6Xt7gvZTZ Candy66 \n", + "13 3ZReJfzCEVpHWUSWd5emic Frank Quintero \n", + "14 0D8yIOlFPxp7OL6n6UzJ38 Gran Coquivacoa \n", + "15 4SBlgsYD1T6dUV17RDrEBN La Corte \n", + "16 2zwh4WnVBGZcfnllC7DUxt Viniloversus \n", + "17 6dTMVeRubUzINO6gmQhWat Un Solo Pueblo \n", + "18 4FNbNj9mlDLitaic9vXlwZ Tecupae \n", + "19 1V6FooKFiokndcPHKJ4Tmz Maracaibo 15 \n", + "\n", + " related_genres related_popularity \\\n", + "0 [venezuelan rock] 29 \n", + "1 [venezuelan rock] 30 \n", + "2 [latin rock, rock gotico, venezuelan rock] 23 \n", + "3 [] 5 \n", + "4 [venezuelan rock] 40 \n", + "5 [venezuelan rock] 24 \n", + "6 [venezuelan hip hop, venezuelan rock] 22 \n", + "7 [classic venezuelan pop, venezuelan rock] 25 \n", + "8 [venezuelan hip hop, venezuelan rock] 21 \n", + "9 [venezuelan rock] 17 \n", + "10 [venezuelan rock] 24 \n", + "11 [venezuelan hip hop, venezuelan rock] 33 \n", + "12 [caracas indie, venezuelan rock] 22 \n", + "13 [classic venezuelan pop, venezuelan rock] 28 \n", + "14 [classic venezuelan pop, gaita zuliana] 41 \n", + "15 [venezuelan hip hop, venezuelan rock] 19 \n", + "16 [caracas indie, rock en espanol, venezuelan rock] 36 \n", + "17 [classic venezuelan pop, folklore venezolano, ... 27 \n", + "18 [pop reggaeton, venezuelan rock] 34 \n", + "19 [classic venezuelan pop, gaita zuliana] 42 \n", + "\n", + " related_followers artist_id artist_name \\\n", + "0 {'href': None, 'total': 69575} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "1 {'href': None, 'total': 42221} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "2 {'href': None, 'total': 42712} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "3 {'href': None, 'total': 35053} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "4 {'href': None, 'total': 98037} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "5 {'href': None, 'total': 54368} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "6 {'href': None, 'total': 30652} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "7 {'href': None, 'total': 37419} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "8 {'href': None, 'total': 27537} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "9 {'href': None, 'total': 24642} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "10 {'href': None, 'total': 30453} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "11 {'href': None, 'total': 62438} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "12 {'href': None, 'total': 25341} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "13 {'href': None, 'total': 49390} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "14 {'href': None, 'total': 88901} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "15 {'href': None, 'total': 20543} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "16 {'href': None, 'total': 70202} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "17 {'href': None, 'total': 43757} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "18 {'href': None, 'total': 102961} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "19 {'href': None, 'total': 96047} 0kyQwKHCZnKE7kTXkxXjrB Desorden Público \n", + "\n", + " artist_genres artist_popularity \n", + "0 [caracas indie, latin alternative, latin ska, ... 37 \n", + "1 [caracas indie, latin alternative, latin ska, ... 37 \n", + "2 [caracas indie, latin alternative, latin ska, ... 37 \n", + "3 [caracas indie, latin alternative, latin ska, ... 37 \n", + "4 [caracas indie, latin alternative, latin ska, ... 37 \n", + "5 [caracas indie, latin alternative, latin ska, ... 37 \n", + "6 [caracas indie, latin alternative, latin ska, ... 37 \n", + "7 [caracas indie, latin alternative, latin ska, ... 37 \n", + "8 [caracas indie, latin alternative, latin ska, ... 37 \n", + "9 [caracas indie, latin alternative, latin ska, ... 37 \n", + "10 [caracas indie, latin alternative, latin ska, ... 37 \n", + "11 [caracas indie, latin alternative, latin ska, ... 37 \n", + "12 [caracas indie, latin alternative, latin ska, ... 37 \n", + "13 [caracas indie, latin alternative, latin ska, ... 37 \n", + "14 [caracas indie, latin alternative, latin ska, ... 37 \n", + "15 [caracas indie, latin alternative, latin ska, ... 37 \n", + "16 [caracas indie, latin alternative, latin ska, ... 37 \n", + "17 [caracas indie, latin alternative, latin ska, ... 37 \n", + "18 [caracas indie, latin alternative, latin ska, ... 37 \n", + "19 [caracas indie, latin alternative, latin ska, ... 37 " + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_related_artists = pd.merge(df_related_artists, df_artist, on=\"artist_id\")\n", + "df_related_artists" + ] + }, + { + "cell_type": "markdown", + "id": "98827be6", + "metadata": {}, + "source": [ + "---\n", + "\n", + "### Bonus track!!!\n", + "\n", + "You can publish your own Playlist with [`/playlists`](https://developer.spotify.com/documentation/web-api/reference/#/operations/create-playlist) and [`/tracks`](https://developer.spotify.com/documentation/web-api/reference/#/operations/add-tracks-to-playlist).\n", + "\n", + "![I quit](https://media.giphy.com/media/gui67fZ3xIneM/giphy.gif)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "2e5f0905", + "metadata": {}, + "outputs": [], + "source": [ + "# Bonus\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "9436b623", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "markdown", + "id": "a9487ef7", + "metadata": {}, + "source": [ + "You can always try with the [wrapper](https://github.com/plamere/spotipy)!!!\n", + "\n", + "![I quit](https://media.giphy.com/media/3oFzlXPvXYZ4q8VQOs/giphy.gif)" + ] + }, + { + "cell_type": "markdown", + "id": "0a399ce8", + "metadata": {}, + "source": [ + "---" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python (m1_env)", + "language": "python", + "name": "m1_env" + }, + "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.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}