-1

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

gracyashhh
  • 89
  • 1
  • 11
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 21 '21 at 07:57

2 Answers2

0

you can use the spotify api to do that.

You could search -> don't forget to specify the type to artist !

As you can see, it will return an array with many results, you can then loop to find the matching one or take the first one. And for each item, there'll be your id !

polypode
  • 501
  • 3
  • 14
  • I can only see the query in Curl, can you please tell how to do the same with python? Tried this `artist_info = requests.get( 'https://api.spotify.com/v1/search', headers={ 'access_token': access_token }, params={ 'q': artist_name, 'type': 'artist' })` and got 401 "No token provided" but I did add access token though – gracyashhh Oct 21 '21 at 08:41
  • Well I didn't did it in python, but with some research, you can find a [wrapper](https://spotipy.readthedocs.io/en/2.16.1/) to use the spotify API more easily. Or you could use a library that [does the basics](https://stackoverflow.com/questions/11322430/how-to-send-post-request) and code it yourself ! – polypode Oct 21 '21 at 08:46
0

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.

gracyashhh
  • 89
  • 1
  • 11