Search code examples
pythonuriaudio-playerspotipyspotify-app

How to get URI of the Artist from Spotify without having to manually copy the URI of Artist from Spotify


I'm working on this Music player project which I built with Pygame, there are many tutorials on how to make a music player - the UI, the widgets, the functionality but every tutorial uses the choose from folder feature, but I am planning to make this a desktop application and conert into exe so that it works on the user's system even without having a collection of mp3 files downloaded on their pc, in order to do that I want to stream music which I tried using Spotify API, after which I came to know I need the Artist's URI in order to get the Music URLs along with Posters, but when I searched for how to get Artists's URI all I found was '1.right click on artist name, 2.copy URI'.

But is there a way to do that using code(without using selenium) becasue only then can I build this feature in my app. Is there a better way to stream music metadata using Python, this is the first time I'm trying this and any answers would really help me a lot get through this. Thanks in Advance


Solution

  • So here's how it's done, adding onto Martin's answer,

    artist_info = requests.get(
    'https://api.spotify.com/v1/search',
    headers={
        'Authorization': 'Bearer {token}'.format(token=access_token)
    },
    params={ 'q': artist_name, 'type': 'artist' })
    

    What I missed earlier was the formatting of the access token for authorization, thanks to the journal . Now it's working perfectly.