Skip to main content

Open Source Spotify Client

Project description

License Stars Forks DeepSource

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 Sponsor Liberapay 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

from librespot.zeroconf import ZeroconfServer

zeroconf = ZeroconfServer.Builder().create()

Use OAuth for Login

Without auth url callback

from librespot.core import Session

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

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

With auth url callback and changing the content of the success page

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()

Use Stored Credentials for Login

from librespot.core import Session

# Supports both Python and Rust librespot credential formats

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

Get Spotify's OAuth token

from librespot.core import Session


session = 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.

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.

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.

import logging


logging.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

librespot-0.0.10.tar.gz (107.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

librespot-0.0.10-py3-none-any.whl (139.4 kB view details)

Uploaded Python 3

File details

Details for the file librespot-0.0.10.tar.gz.

File metadata

  • Download URL: librespot-0.0.10.tar.gz
  • Upload date:
  • Size: 107.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for librespot-0.0.10.tar.gz
Algorithm Hash digest
SHA256 e79e954dc8e51e641d813814112942717ff3c3888a153569613b6f3d17e032d2
MD5 cd87b2da04fe5756e699a0691984f9d0
BLAKE2b-256 e1a6702c1793d24dc59196826b7ffc5d9e93842efa2e0cb5b70c74866e98bd39

See more details on using hashes here.

File details

Details for the file librespot-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: librespot-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 139.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for librespot-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cb3ee4ac63062c986cd91732e29ba0e66c091bc02badf2861bdc8b7d995f7e38
MD5 acfa238a4075d03e975b576e5cf8bef3
BLAKE2b-256 a68dfb07a7162ddadbb2f9b0368efcbab1ce2d3a8b08746fc7a7c32f20e64689

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page