2021-04-10 01:22:02 +02:00
|
|
|
![License](https://img.shields.io/github/license/kokarare1212/librespot-python.svg)
|
|
|
|
![Stars](https://img.shields.io/github/stars/kokarare1212/librespot-python.svg)
|
|
|
|
![Forks](https://img.shields.io/github/forks/kokarare1212/librespot-python.svg)
|
|
|
|
[![DeepSource](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-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
# Librespot-Python
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:44:57 +01:00
|
|
|
Open Source Spotify Client
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## About The Project
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
This project was developed to make the music streaming service Spotify available
|
|
|
|
on any device.
|
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## Note
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
It is still in the idea stage, so there is a possibility of unintended behavior
|
2021-05-22 03:26:41 +02:00
|
|
|
or major specification changes.
|
2021-05-22 03:26:37 +02:00
|
|
|
We **DO NOT** encourage piracy and **DO NOT** support any form of
|
|
|
|
downloader/recorder designed with the help of this repository and in general
|
2021-05-22 03:26:41 +02:00
|
|
|
anything that goes against the Spotify ToS.
|
2021-05-22 03:26:37 +02:00
|
|
|
For other guidelines, please see
|
|
|
|
[CODE_OF_CONDUCT.md](https://github.com/kokarare1212/librespot-python/blob/main/CODE_OF_CONDUCT.md).
|
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## Getting Started
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
### Prerequisites
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
- [Python](https://python.org/)
|
|
|
|
|
2021-02-25 22:51:44 +01:00
|
|
|
### Installation
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-03-28 09:05:22 +02:00
|
|
|
Stable Version **\*still not working.**
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-25 22:51:44 +01:00
|
|
|
```commandline
|
|
|
|
pip install librespot
|
|
|
|
```
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-03-28 09:05:22 +02:00
|
|
|
Snapshot Version \***Recommended**
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-25 22:51:44 +01:00
|
|
|
```commandline
|
|
|
|
pip install git+https://github.com/kokarare1212/librespot-python
|
|
|
|
```
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## Usage
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-03-28 09:18:26 +02:00
|
|
|
### Get Spotify's OAuth token
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-25 22:59:13 +01:00
|
|
|
```python
|
|
|
|
from librespot.core import Session
|
|
|
|
|
|
|
|
|
|
|
|
session = Session.Builder() \
|
2021-04-24 12:50:43 +02:00
|
|
|
.user_pass("Username", "Password") \
|
2021-02-25 22:59:13 +01:00
|
|
|
.create()
|
|
|
|
|
|
|
|
aceess_token = session.tokens().get("playlist-read")
|
|
|
|
```
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-03-28 09:18:26 +02:00
|
|
|
### Get Music Stream
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-03-28 09:18:26 +02:00
|
|
|
\*Currently, music streaming is supported, but it may cause unintended behavior.
|
2021-05-20 00:03:32 +02:00
|
|
|
|
2021-03-28 09:18:26 +02:00
|
|
|
```python
|
|
|
|
from librespot.core import Session
|
2021-04-24 12:50:43 +02:00
|
|
|
from librespot.metadata import TrackId
|
2021-05-20 00:03:32 +02:00
|
|
|
from librespot.player.codecs import VorbisOnlyAudioQuality
|
|
|
|
from librespot.audio.decoders import AudioQuality
|
2021-03-28 09:18:26 +02:00
|
|
|
|
2021-05-20 00:03:32 +02:00
|
|
|
session = Session.Builder()
|
|
|
|
.user_pass("Username", "Password")
|
2021-03-28 09:18:26 +02:00
|
|
|
.create()
|
|
|
|
|
2021-04-24 12:50:43 +02:00
|
|
|
track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
|
2021-05-20 00:03:32 +02:00
|
|
|
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.AudioQuality.VERY_HIGH), False,
|
|
|
|
None)
|
2021-04-25 02:27: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-03-28 09:18:26 +02:00
|
|
|
```
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
Other uses are
|
|
|
|
[examples](https://github.com/kokarare1212/librespot-python/tree/main/examples)
|
|
|
|
or read [this document](https://librespot-python.rtfd.io) for detailed
|
|
|
|
specifications.
|
2021-04-24 23:38:01 +02:00
|
|
|
|
|
|
|
## Debug
|
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-04-24 23:38:01 +02:00
|
|
|
```python
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
```
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## Roadmap
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
Please read
|
|
|
|
[ROADMAP.md](https://github.com/kokarare1212/librespot-python/blob/main/ROADMAP.md).
|
|
|
|
|
2021-04-06 00:08:31 +02:00
|
|
|
## Contributing
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-04-06 00:08:31 +02:00
|
|
|
Pull requests are welcome.
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## License
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
Distributed under the Apache-2.0 License. See
|
|
|
|
[LICENSE.txt](https://github.com/kokarare1212/librespot-python/blob/main/LICENSE.txt)
|
|
|
|
for more information.
|
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## Related Projects
|
2021-05-22 03:26:37 +02:00
|
|
|
|
|
|
|
- [Librespot](https://github.com/librespot-org/librespot) (Concept)
|
|
|
|
- [Librespot-Java](https://github.com/librespot-org/librespot-java) (Core)
|
|
|
|
|
2021-02-24 00:46:59 +01:00
|
|
|
## Special thanks
|
2021-05-22 03:26:37 +02:00
|
|
|
|
2021-03-28 08:58:08 +02:00
|
|
|
Coming soon
|