Skip to content

Repository files navigation

LicenseStarsForksDeepSource

Counter

Librespot-Python

Open Source Spotify Client

Support Project

If you find our project useful and want to support its development, please consider making a donation. Your contribution will help us maintain and improve the project, ensuring that it remains free and accessible to everyone.

GitHub SponsorLiberapay receiving

About The Project

This project was developed to make the music streaming service Spotify available on any device.

Attention!

This repository has been completely rewritten from the transplant.
There may be some functions that are not implemented yet.
If so, please feel free to open an issue.

Note

It is still in the idea stage, so there is a possibility of unintended behavior or major specification changes.
We DO NOT encourage piracy and DO NOT support any form of downloader/recorder designed with the help of this repository and in general anything that goes against the Spotify ToS.
For other guidelines, please see CODE_OF_CONDUCT.md.

Getting Started

Prerequisites

Installation

Stable Version

pip install librespot

Snapshot Version *Recommended

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

Usage

Use Zeroconf for Login

fromlibrespot.zeroconfimportZeroconfServerzeroconf=ZeroconfServer.Builder().create()

Use OAuth for Login

Without auth url callback

fromlibrespot.coreimportSession# This will log an url in the terminal that you have to opensession=Session.Builder() \
.oauth(None) \
.create()

With auth url callback

fromlibrespot.coreimportSession# This will pass the auth url to the methoddefauth_url_callback(url):
print(url)
session=Session.Builder() \
.oauth(auth_url_callback) \
.create()

Use Stored Credentials for Login

fromlibrespot.coreimportSession# Supports both Python and Rust librespot credential formatssession=Session.Builder() \
.stored_file("/path/to/credentials.json") \
.create()

Get Spotify's OAuth token

fromlibrespot.coreimportSessionsession=Session.Builder() \
.oauth(None) \
.create()
access_token=session.tokens().get("playlist-read")

Get Music Stream

*Currently, music streaming is supported, but it may cause unintended behavior.

fromlibrespot.coreimportSessionfromlibrespot.metadataimportTrackIdfromlibrespot.audio.decodersimportAudioQuality, VorbisOnlyAudioQualitysession=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.

Other uses are examples or read this document for detailed specifications.

Debug

To display the debug information, you need to inject the following code at the top of the code.

importlogginglogging.basicConfig(level=logging.DEBUG)

Contributing

Pull requests are welcome.

License

Distributed under the Apache-2.0 License. See LICENSE.txt for more information.

Related Projects

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages