ITADN
kokarare1212/librespot-python
kokarare1212/librespot-python · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

License Stars Forks DeepSource

Counter

Librespot-Python

开源 Spotify 客户端

支持项目

如果您觉得我们的项目有用并希望支持其开发,请考虑进行捐赠。您的贡献将帮助我们维护和改进该项目,确保它保持免费并对所有人开放。

GitHub Sponsor Liberapay receiving

关于本项目

本项目旨在让 Spotify 音乐流媒体服务 在任何设备上可用。

注意!

本仓库已从移植版本完全重写。
可能有一些功能尚未实现。
如果是这样,请随时提交 issue。

备注

目前仍处于构思阶段,因此可能会出现意外行为 或重大规范变更。
我们鼓励盗版,也支持任何利用本仓库帮助设计的下载器/录音器,以及任何违反 Spotify 服务条款的行为。
其他准则请参阅 CODE_OF_CONDUCT.md

快速开始

前提条件

安装

稳定版本

pip install librespot

快照版本 *推荐

pip install git+https://github.com/kokarare1212/librespot-python

用法

使用 Zeroconf 进行登录

from librespot.zeroconf import ZeroconfServer

zeroconf = ZeroconfServer.Builder().create()

使用 OAuth 进行登录

无 auth url 回调

from librespot.core import Session

# This will log an url in the terminal that you have to open

session = Session.Builder() \
    .oauth(None) \
    .create()

使用 auth url 回调并更改成功页面的内容

from librespot.core import Session
import webbrowser

# This will pass the auth url to the method

def auth_url_callback(url):
    webbrowser.open(url)

# This is the response sent to the browser once the flow has been completed successfully
success_page = "<html><body><h1>Login Successful</h1><p>You can close this window now.</p><script>setTimeout(() => {window.close()}, 100);</script></body></html>"

session = Session.Builder() \
    .oauth(auth_url_callback, success_page) \
    .create()

使用存储的凭据进行登录

from librespot.core import Session

# Supports both Python and Rust librespot credential formats

session = Session.Builder() \
    .stored_file("/path/to/credentials.json") \
    .create()

获取 Spotify 的 OAuth 令牌

from librespot.core import Session


session = Session.Builder() \
    .oauth(None) \
    .create()

access_token = session.tokens().get("playlist-read")

获取音乐流

*目前,支持音乐流,但可能会导致意外行为。

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality

session = Session.Builder() \
    .oauth(None) \
    .create()

track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
# stream.input_stream.stream().read() to get one byte of the music stream.

其他用途是 示例 或阅读本文档以获取详细 规格说明。

调试

要显示调试信息,您需要在代码 顶部注入以下代码。

import logging


logging.basicConfig(level=logging.DEBUG)

贡献

欢迎提交 Pull requests。

许可证

基于 Apache-2.0 许可证分发。详见 LICENSE.txt 以获取更多信息。

相关项目