로컬 API

컴퓨터의 BitSpring은 로컬 네트워크에서 Home Assistant, Stream Deck, Apple 단축어 또는 직접 만든 스크립트로 제어할 수 있습니다. 휴대폰 리모컨이 사용하는 것과 같은 작은 서버입니다.

아래 참고 문서는 영어로 작성되어 있습니다.

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"
}

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.

AddressBodyWhat it does
/api/v1/playPlays: resumes, or starts the queue.
/api/v1/pausePauses.
/api/v1/togglePlay or pause, whichever applies.
/api/v1/stopStops and lets go of the output.
/api/v1/nextNext track of the queue.
/api/v1/previousPrevious 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

400The command's values are missing or out of range, or a path isn't in the library.
403No token, or not the current one.
404No such address.
405The address exists, with another method.
409Nothing is playing (volume).