WebApi: Extra fields showing playback status
Is your feature request related to a problem? Please describe. Repro:
- Create a local web server with a
song.mp3file at root (e.g.php.exe -S 0.0.0.0:8080) - Run these commands:
# create bot
curl -s http://127.0.0.1:58913/api/settings/create/test
curl -s http://127.0.0.1:58913/api/settings/bot/set/test/connect.address/127.0.0.1
curl -s http://127.0.0.1:58913/api/bot/connect/template/test
# create playlist
curl -s http://127.0.0.1:58913/api/bot/use/0/(/list/create/test)
curl -s http://127.0.0.1:58913/api/bot/use/0/(/list/add/test/http%3A%2F%2F127.0.0.1%3A8080%2Fsong.mp3)
# play it on loop
curl -s http://127.0.0.1:58913/api/bot/use/0/(/repeat/all)
curl -s http://127.0.0.1:58913/api/bot/use/0/(/list/play/test)
- Stop the webserver (so the link would stop working)
- Try to detect link failure from the api
λ curl -s http://127.0.0.1:58913/api/bot/use/0/(/bot/info) | jq
{
"Id": 0,
"Name": "test",
"Server": "127.0.0.1",
"Status": 2
}
λ curl -s http://127.0.0.1:58913/api/bot/use/0/(/song) | jq
{
"Position": 0,
"Length": 0,
"Paused": false,
"Link": "http://127.0.0.1:8080/song.mp3",
"Title": "http://127.0.0.1:8080/song.mp3",
"AudioType": "media"
}
- It says it's still playing (which it isn't)
Tested on:
λ TS3AudioBot.exe --version
Version: 0.11.4
Branch: master
CommitHash: 4f17b2971e03bee94d1e630a2b5ce37d8a15e5ca
λ ffmpeg --version
ffmpeg version N-89496-g2d131fc31b Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
Describe the solution you'd like
An extra field in /bot/info to show streaming status (equivalent to the blue light in TeamSpeak) instead of just connected/connecting/disconnected.
-or-
An extra field in /song in addition to the existing field paused showing one of:
- Buffer size in seconds/bytes
- Boolean showing if it's buffering (stopped playback pending data from source)
- Boolean if a sound packet has been sent in the last 1 sec
- Number of seconds since the last audio packet was sent (Equivalent to Idle time in TeamSpeak connection info)
Describe alternatives you've considered
- Polling
/songevery second to see if the Position field is increasing or stuck. - Using the
Lengthfield. As seen in the output above the Length is 0 for failing links.
However, this workaround has multiple shortcomings. It won't work if a link fails in the middle of the song until it retries playing it and reset the length. And more importantly, it won't work for streams (e.g. online radios)curl -s http://127.0.0.1:58913/api/bot/use/0/(/song) | jq "Position": 12.899999999999999, "Length": 212.69, "Paused": false, "Link": "http://127.0.0.1:8080/song.mp3", "Title": "http://127.0.0.1:8080/song.mp3", "AudioType": "media" - Waiting until the retry limit finishes and the bot gives up, at which point
/songwill display this:
I'm not sure if this works with multiple songs in the playlist? Even if it does, depending on timeout/retry settings it can take a long time for the failure to be detectable by the API.curl -s http://127.0.0.1:58913/api/bot/use/0/(/song) | jq "ErrorCode": 10, "ErrorName": "CommandError", "ErrorMessage": "There is nothing on right now..."
If I'm reading your request correctly, most of your suggested solutions kinda feel like workarounds for the basic problem that the api endpoint /song is bugged and doesn't swich back to 'nothing on' after finishing the last song.
I've also noticed that the last song isn't cleared on my webinterface too, and had it remembered, but but kinda forgot about it again.
Another thing is I don't like polling via api. It just feels bad and it's inefficient. My goal in the future is to add a websocket for events. Stuff like NewSongStarted, SongChanged, etc
workarounds for the basic problem that the API endpoint /song is bugged
I have made an alternative panel for the bot, and in the main list I wanted to show the state of the bot as Not connected, Not playing, Playing. Ideally, I would get enough info to show that using just /bot/list. But since it doesn't include playing status, currently I have the bot also call /song for all the bots in one /json/merge call.
last song isn't cleared
The point was to not have a last song. hence the /repeat/all. In my case, I mostly play online radios which don't end. The repeat is a workaround for it to retry on failed connections. However, the failure is not always from my side, sometimes the radios go down.
My goal was to be able to find at a glance which radios are bugged without connecting to each server and joining each bot channel.
I don't like polling via api.
Me neither. But unfortunately, due to repeat all, it never stops being in the song. even if it fails and goes next, the next song is still the same radio station with a broken link. The only way I found to check if it is playing or not using the API is to fetch /song twice with a 1sec sleep in between and compare the Position.
Which is an ugly solution, with false positives when it's genuinely buffering and not dropped. hence the feature request.