API local
BitSpring pe computer poate fi controlat prin rețeaua locală din Home Assistant, un Stream Deck, Scurtături Apple sau un script propriu. Este același mic server pe care îl folosește telecomanda pe telefon.
- Dezactivat implicit. Rulează doar cât timp telecomanda pe telefon este activată în Setări și se oprește când o dezactivezi.
- Doar în rețeaua locală. BitSpring nu îl deschide niciodată spre internet.
- Fiecare cerere are nevoie de tokenul din adresa telecomenzii. „Adresă nouă” din panoul telecomenzii creează unul nou, iar tot ce avea tokenul vechi pierde accesul.
- Redă doar ce se află în biblioteca ta: o cerere nu poate face BitSpring să deschidă niciun alt fișier.
Referința de mai jos este în engleză.
Address and token
Switch the remote on in Settings. BitSpring shows an address like this:
http://192.168.1.20:48173/?t=3f9c…e1
The part before /?t= is the server, the part after t= is the token. Send the token in any of these ways:
Authorization: Bearer <token>
X-Token: <token>
…/api/v1/state?t=<token>
Without it the answer is 403. This page describes version 1: the addresses and fields listed here stay as they are, and later versions of BitSpring may add new ones.
curl -H "Authorization: Bearer $TOKEN" http://192.168.1.20:48173/api/v1/state
Reading
GET /api/v1/state
{
"state": "playing",
"position": 61.5,
"duration": 251.0,
"buffering": false,
"track": {
"path": "/Music/Miles Davis/Kind of Blue/01 So What.flac",
"title": "So What",
"artist": "Miles Davis",
"album": "Kind of Blue",
"year": "1959",
"duration": 251.0,
"albumId": "8c1f0a9be2d34f10",
"favorite": true,
"rating": 4,
"cover": "/api/v1/cover/current?rev=7"
},
"signal": {
"output": "FiiO Q7",
"sourceRate": 96000,
"sourceBits": 24,
"outputRate": 96000.0,
"outputBits": 24,
"bitPerfect": true,
"lossy": false
},
"queue": { "index": 0, "length": 5 },
"shuffle": false,
"repeat": "off"
}
state:playing,pausedorstopped.positionanddurationare in seconds.trackandsignalarenullwhen nothing is loaded.albumIdisnullfor a file outside the library,coverwhen the file has no cover.track.favoriteandtrack.rating(0 to 5 stars, 0: not rated) are the listener's marks, since 0.21.1. A file outside the library has none:falseand0.signal.bitPerfect: the samples reach the DAC untouched. ThesourceRateof a DSD file is its 1-bit rate (2822400 for DSD64).repeat:off,all(the queue) orone(the track).
GET /api/v1/queue
{
"index": 0,
"tracks": [
{ "path": "/Music/…/01 So What.flac", "title": "So What", "artist": "Miles Davis", "duration": 251.0, "albumId": "8c1f0a9be2d34f10" }
]
}
GET /api/v1/library
Every album and track of the library, as albums and tracks. A track's path is what the queue commands take; an album's tracks are positions in the tracks list.
GET /api/v1/favorites
Since 0.21.1. Everything the listener marked in the library: tracks by path, and the ids of favourite albums. A track is listed when it is a favourite, has a rating, or both.
{
"tracks": {
"/Music/…/01 So What.flac": { "favorite": true, "rating": 5 },
"/Music/…/02 Freddie Freeloader.flac": { "favorite": false, "rating": 4 }
},
"albums": ["8c1f0a9be2d34f10"]
}
GET /api/v1/cover/<albumId>, GET /api/v1/cover/current
The cover of an album, or of the track that plays now. 404 when there is none.
GET /api/v1/volume
{"volume": 40}, 0 to 100, when the output is a network player (UPnP, Chromecast) with a volume of its own. null otherwise: BitSpring doesn't scale the samples it sends to a DAC.
GET /api/v1/info
The app's name and version, and the API version: {"app": "BitSpring", "version": "0.21.1", "api": 1}.
Events
GET /api/v1/events
A Server-Sent Events stream. It sends the state (the same object as GET state) at once, and again whenever something changes: another track, play or pause, a seek, the queue, shuffle or repeat, the playing track's marks.
event: state
data: {"state":"playing","position":61.5, …}
The position is not sent while it simply runs on: count it from the last event. A comment line (: ping) comes after 15 seconds of silence. At most 8 connections per client address.
Commands
All are POST; those with values take a JSON body. The answer is {"ok":true}. The BitSpring window carries a command out the way its own buttons work, so the state changes a moment after the answer. favorite and rating are the exception: the mark is saved before the answer comes, and stays on the device like the marks made in the app.
| Address | Body | What it does |
|---|---|---|
/api/v1/play | Plays: resumes, or starts the queue. | |
/api/v1/pause | Pauses. | |
/api/v1/toggle | Play or pause, whichever applies. | |
/api/v1/stop | Stops and lets go of the output. | |
/api/v1/next | Next track of the queue. | |
/api/v1/previous | Previous track; more than 3 s into a track, back to its start. | |
/api/v1/seek | {"position": 90} | Jumps to that second of the track. |
/api/v1/shuffle | {"on": true} | Shuffle on or off. Without a body: the other one. |
/api/v1/repeat | {"mode": "all"} | off, all or one. Without a body: the next one. |
/api/v1/volume | {"volume": 40} | The network player's volume, 0 to 100. |
/api/v1/queue/jump | {"index": 3} | Plays that entry of the queue. |
/api/v1/queue/play | {"paths": […], "index": 0} | Replaces the queue with these library tracks and plays from index. |
/api/v1/queue/add | {"paths": […]} | Adds these library tracks to the end of the queue. |
/api/v1/favorite | {"path": "…", "on": true} | Makes a library track a favourite, or no longer one. Without on: the other one. Without path: the track that plays. With "albumId": "…" instead of path: the album. Answers {"ok":true,"favorite":true}. Since 0.21.1. |
/api/v1/rating | {"path": "…", "rating": 4} | Gives a library track 1 to 5 stars; 0 takes them away. Without path: the track that plays. Since 0.21.1. |
curl -X POST -H "Authorization: Bearer $TOKEN" http://192.168.1.20:48173/api/v1/toggle
curl -X POST -H "Authorization: Bearer $TOKEN" -d '{"position": 90}' http://192.168.1.20:48173/api/v1/seek
Home Assistant
rest_command:
bitspring:
url: "http://192.168.1.20:48173/api/v1/{{ command }}"
method: post
headers:
Authorization: "Bearer !secret bitspring_token"
sensor:
- platform: rest
name: BitSpring
resource: http://192.168.1.20:48173/api/v1/state
headers:
Authorization: "Bearer !secret bitspring_token"
value_template: "{{ value_json.state }}"
json_attributes: [track, signal, position, duration]
scan_interval: 5
Then call rest_command.bitspring with command: toggle.
Errors
400 | The command's values are missing or out of range, or a path isn't in the library. |
403 | No token, or not the current one. |
404 | No such address. |
405 | The address exists, with another method. |
409 | Nothing is playing (volume). |