Monday, 12 March 2018

python - Finding if a song exists by the name of a given input text




I am working on an application which would allow users to enter some text as song name and another input for the artist name, and then will check whether a song exists that matches both the input parameters. I'm currently using Spotify's API for the same by querying for the song 'Get In The Game' using this endpoint:



https://api.spotify.com/v1/search?q=get%20in%20the%20game&type=track



However, Spotify's API does not allow filtering the results using both the song name and artist name together. As a result, the above query returns a list of all songs that match the Get in the Game song title.



How can I find whether a song exists based on the song and artist name?


Answer



You could use the last.fm API, specifically the track.getInfo Endpoint. This lets you specify both artist and track at once.




On success (you could also request for a json response) you get something like:





Shine on You Crazy Diamond
cb20321d-ecda-4fc1-a32a-0439a096a1bc

http://www.last.fm/music/Pink+Floyd/_/Shine+on+You+Crazy+Diamond


763000
0
256400
1511578

Pink Floyd
83d91898-7763-47d7-b03b-b92132375c47
http://www.last.fm/music/Pink+Floyd


...




when the song is not found:




Track not found



No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...