如何使用 Python 播放 Spotify 音频?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32309322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:22:42  来源:igfitidea点击:

How can I play a Spotify audio with Python?

pythonpython-2.7spotify

提问by NeoMahler

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

我想知道是否可以使用 Python(如果可能,版本 2.7)播放 Spotify 中的歌曲以及如何播放。

采纳答案by Michael Thelin

Although I understand that you're being downvoted since the question isn't very well-formed, I would like to give you an answer.

虽然我知道您因为问题的格式不是很好而被否决了,但我想给您一个答案。

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 fulltracks. 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 Androidand iOS.

有多种方式可以与 Spotify 进行交互,目前流行的帖子是 Web API。Web API 提供了许多功能,但不能播放完整曲目。因此,无论您使用的是 Python、Java、C# 还是任何语言,您仍然无法使用 Web API 播放音乐。然而,有支持播放的移动 SDK,可用于AndroidiOS

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.

但是,您可以使用 Web API 播放预览曲目(30 秒)。查看spotipy,它是更好的 Python 客户端之一,如果不是最好的。

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.

还有其他直接与 Spotify 桌面应用程序交互的方法,但没有一种方法得到 Spotify 的正式支持,我不能推荐它们,因为它们可能会在任何时间点停止工作。

Edit:As the other answer to this question correctly states, Libspotifycould 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.

编辑:正如这个问题的另一个答案正确指出的那样,Libspotify可以为您解决这个问题。我没有提到它的原因是它已被弃用。我们的目标是在 2015 年底之前更换它。

回答by jodal

With pyspotifyyou 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.

使用pyspotify,您可以访问所有(旧的但仍在工作的)libspotify API,并且您可以播放完整曲目。它适用于 Python 2.7 以及 Python 3.2+ 和 PyPy。