https://github.com/codetheweb/librespot-node
https://github.com/codetheweb/librespot-node
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/codetheweb/librespot-node
- Owner: codetheweb
- License: mit
- Created: 2020-10-26T22:05:37.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-26T22:11:07.000Z (over 5 years ago)
- Last Synced: 2025-07-18T21:20:04.298Z (8 months ago)
- Language: Rust
- Size: 37.1 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# librespot-node
An easy to use Node.js wrapper for [librespot](https://github.com/librespot-org/librespot), an open source Spotify client, based on [neon](https://github.com/neon-bindings/neon)
## Building
1. Clone this repo
2. run `npm install` inside the root folder
3. Once everything is installed, run `npx neon build` to start building the native module
4. Build Typescript code with `npm run build` / `npm run watch`
## Basic Examples
### Playing a song
```js
const { Spotify } = require('../native');
const spotify = new Spotify('', '');
// Load specified track (by id) and starts playing
spotify.play('');
setInterval(() => {
console.log('playing? ', spotify.isPlaying());
}, 1000);
```
### Getting web token (can be used for retrieving metadata)
```js
const { Spotify } = require('../native');
const spotify = new Spotify('', '');
spotify.getToken('', '', (token) => {
console.log(token.getToken(), token.getExpiry(), token.getScope());
});
```
## API (Work in progress)
```ts
interface Spotify {
constructor({
username: string,
password: string,
quality?: enum
cacheDir?: string,
connect {
type: enum,
name: string
}
})
play(trackId: string);
stop();
pause();
seek(positionMs: number) throws;
getPosition(): throws number
getTrack(): throws string
isPlaying(): boolean;
emit: started, stopped, loading, playing, paused, endoftrack, volumeset
}
get current volume
interface AccessToken {
getToken(): string;
getExpiry(): number;
getScope(): string[];
}
```