2021-05-15 04:10:47 +02:00
|
|
|
![](https://img.shields.io/github/license/kokarare1212/librespot-python.svg)
|
|
|
|
![](https://img.shields.io/github/stars/kokarare1212/librespot-python.svg)
|
|
|
|
![](https://img.shields.io/github/forks/kokarare1212/librespot-python.svg)
|
|
|
|
[![](https://deepsource.io/gh/kokarare1212/librespot-python.svg/?label=active+issues&show_trend=true)](https://deepsource.io/gh/kokarare1212/librespot-python/?ref=repository-badge)
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
# Get Started
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-16 01:08:54 +02:00
|
|
|
## Contents
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-22 03:26:37 +02:00
|
|
|
- [Get Started](index.md)
|
|
|
|
- [Supported Futures](supported.md)
|
|
|
|
- [API Reference](api.md)
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
## What's librespot-python?
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-22 03:26:37 +02:00
|
|
|
librespot-python is a python port of Spotify's open source client library
|
2021-09-12 06:33:39 +02:00
|
|
|
[librespot](https://github.com/librespot-org/librespot). <br>
|
|
|
|
It was created to play Spotify on various platforms and devices.<br>
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
## What do you need?
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-09-12 06:33:39 +02:00
|
|
|
In order to develop with this library, you need to use Python.<br>
|
|
|
|
Python can be downloaded from [the official website here](https://python.org/). <br>
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
## Disclaimer
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-09-12 06:33:39 +02:00
|
|
|
Please keep in mind that this library is not like Spotify approved.<br>
|
|
|
|
Therefore, the worst that can happen is that you will be banned from Spotify.<br>
|
|
|
|
Also, please keep in mind that this library is in alpha and may behave in unintended ways.<br>
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
## Installation
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-09-12 06:33:39 +02:00
|
|
|
You can download this library in the following way.<br><br>
|
2022-02-09 12:55:27 +01:00
|
|
|
Stable Version
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
```commandline
|
|
|
|
pip install librespot
|
|
|
|
```
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-22 03:26:37 +02:00
|
|
|
Snapshot Version **\*Recommended**
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
```commandline
|
|
|
|
pip install git+https://github.com/kokarare1212/librespot-python
|
|
|
|
```
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
## Usage
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
### Get Spotify's OAuth token
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
```python
|
|
|
|
from librespot.core import Session
|
|
|
|
|
|
|
|
|
|
|
|
session = Session.Builder() \
|
|
|
|
.user_pass("Username", "Password") \
|
|
|
|
.create()
|
|
|
|
|
|
|
|
aceess_token = session.tokens().get("playlist-read")
|
|
|
|
```
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
### Get Music Stream
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-09-12 06:33:39 +02:00
|
|
|
*Currently, music streaming is supported, but it may cause unintended behavior.<br>
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
```python
|
|
|
|
from librespot.core import Session
|
|
|
|
from librespot.metadata import TrackId
|
2021-09-14 12:54:55 +02:00
|
|
|
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
|
2021-05-15 04:09:03 +02:00
|
|
|
|
2021-09-12 06:33:39 +02:00
|
|
|
session = Session.Builder() \
|
|
|
|
.user_pass("Username", "Password") \
|
2021-05-15 04:09:03 +02:00
|
|
|
.create()
|
|
|
|
|
|
|
|
track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
|
2021-09-14 12:54:55 +02:00
|
|
|
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False,
|
2021-05-20 00:03:32 +02:00
|
|
|
None)
|
2021-05-15 04:09:03 +02:00
|
|
|
# stream.input_stream.stream().read() to get one byte of the music stream.
|
|
|
|
# ex: 1 (If there is no more voice data, -1 is received as the result.)
|
|
|
|
```
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
## Debug
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-22 03:26:37 +02:00
|
|
|
To display the debug information, you need to inject the following code at the
|
|
|
|
top of the code.
|
2021-05-17 05:58:04 +02:00
|
|
|
|
2021-05-15 04:09:03 +02:00
|
|
|
```python
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
2021-05-22 03:26:37 +02:00
|
|
|
```
|