librespot-python/README.md

127 lines
3.8 KiB
Markdown
Raw Permalink Normal View History

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
2023-10-29 13:53:43 +01:00
![Counter](https://count.getloli.com/get/@librespot-python?theme=moebooru)
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
2023-10-29 13:53:43 +01:00
## 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.<br><br>
[![GitHub Sponsor](https://img.shields.io/github/sponsors/kokarare1212?label=GitHub%20Sponsor&logo=GitHub)](https://github.com/sponsors/kokarare1212)
[![Liberapay receiving](https://img.shields.io/liberapay/receives/kokarare1212?label=Liberapay&logo=Liberapay)](https://liberapay.com/kokarare1212/)
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-09-12 06:04:57 +02:00
## Attention!
This repository has been completely rewritten from the transplant.<br>
There may be some functions that are not implemented yet.<br>
2021-09-12 06:33:39 +02:00
If so, please feel free to open an issue.<br>
2021-09-12 06:04:57 +02:00
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-09-12 06:33:39 +02:00
or major specification changes.<br>
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.<br>
For other guidelines, please see [CODE_OF_CONDUCT.md](https://github.com/kokarare1212/librespot-python/blob/main/CODE_OF_CONDUCT.md).<br>
2021-05-22 03:26:37 +02:00
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
2022-02-09 12:55:27 +01:00
Stable Version
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-09-14 14:09:11 +02:00
### Use Zeroconf for Login
```python
from librespot.zeroconf import ZeroconfServer
zeroconf = ZeroconfServer.Builder().create()
```
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() \
.user_pass("Username", "Password") \
2021-02-25 22:59:13 +01:00
.create()
access_token = session.tokens().get("playlist-read")
2021-02-25 22:59:13 +01:00
```
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-09-12 06:33:39 +02:00
*Currently, music streaming is supported, but it may cause unintended behavior.<br>
2021-05-20 00:03:32 +02:00
2021-03-28 09:18:26 +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-03-28 09:18:26 +02:00
2021-09-12 06:33:39 +02:00
session = Session.Builder() \
.user_pass("Username", "Password") \
2021-03-28 09:18:26 +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, None)
2021-04-25 02:27:03 +02:00
# stream.input_stream.stream().read() to get one byte of the music stream.
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-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)