Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I play a Spotify audio with Python?

I would like to know if it's possible to play songs from Spotify with Python (version 2.7 if possible) and how.

like image 662
NeoMahler Avatar asked Aug 31 '15 10:08

NeoMahler


People also ask

Can you control Spotify with Python?

Go to Python Foundation and download and install Python. Follow the instructions given on the page and install it. After you have installed the library you need to get a client ID and client secretof Spotify in order to use their API. Go to the Dashboard for Spotify developers and login with your Spotify account.

How do you stream music in Python?

Method 1: The playsound module To play the music we just have to use the playsound function and pass the music file path as a parameter. The library works for both mp3 and wav files. The music is played once in the background and then the program is ready for the next part of code to be executed.

Can we play songs using Spotify API?

Starting playback The namesake feature of our Player API is the /v1/me/player/play endpoint — your tool for beginning or continuing the playback of music or podcasts on Spotify. It's more powerful than the play button that you see in Spotify's mobile app.


2 Answers

There are several ways to interact with Spotify, where the post popular right now is the Web API. The Web API offers a lot of features, but not playback of full tracks.

Therefore, it doesn't matter if you're using Python, Java, C#, or whatever language. You'll still not be able to play music using the Web API. There are, however, mobile SDKs that support playback, available for both Android and iOS.

You can however play preview tracks (30 seconds) using the Web API. Check out spotipy. It's one of the better Python clients, if not the best.

There are other ways to interact directly with the Spotify desktop application, but none that are supported officially by Spotify, and I can't recommend them since they may stop working at any point in time.

As another answer correctly states, Libspotify could solve this problem for you. The reason I didn't mention it is that it's deprecated. We're aiming to have a replacement for it by the end of 2015.

like image 100
Michael Thelin Avatar answered Oct 17 '22 15:10

Michael Thelin


With pyspotify you get access to all of the (old, but still working) libspotify API and you can play full tracks. It works on Python 2.7 as well as Python 3.2+ and PyPy.

like image 43
jodal Avatar answered Oct 17 '22 15:10

jodal