8000 Implement ONEVENT_COMMAND and ONEVENT_POST_ENDPOINT config options by QuadratClown · Pull Request #92 · GioF71/librespot-docker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement ONEVENT_COMMAND and ONEVENT_POST_ENDPOINT config options #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ ENV AUDIO_GID=""
ENV PARAMETER_PRIORITY=""
ENV LOG_COMMAND_LINE=""

ENV ONEVENT_COMMAND=""
ENV ONEVENT_POST_ENDPOINT=""

VOLUME /data/cache
VOLUME /data/system-cache
VOLUME /user/config
Expand All @@ -112,6 +115,7 @@ RUN which librespot
COPY app/bin/run-librespot.sh /app/bin/
COPY app/bin/read-file.sh /app/bin/
COPY app/bin/get-value.sh /app/bin/
COPY app/bin/post-event-data.sh /app/bin/

RUN chmod u+x /app/bin/*.sh

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ PUID||Set this value the the user which should run the application, defaults to
PGID||Set this value the the user which should run the application, defaults to `1000` if not set when using the `pulseaudio` backend
AUDIO_GID||Specifies the gid for the group `audio`, it is required if you want to use, e.g., the `alsa` backend in user mode. Refer to [this page](https://github.com/GioF71/squeezelite-docker/blob/main/doc/example-alsa-user-mode.md) from my squeezelite-docker repository for more details.
PARAMETER_PRIORITY||Where to look for a parameter first: `env` or `file`. For example, the `credentials.txt` file compared to `SPOTIFY_USERNAME` and `SPOTIFY_PASSWORD` environment variables. Defaults to `file`, meaning that each file is considered if it exists and if it contains the required values.
ONEVENT_COMMAND||Specifies the name of a user defined script/executable that will be executed whenever a player event occurs. User defined scripts must be mounted to the `/userscripts/` folder and be made executable via `chmod u+x`. Internally maps to the `--onevent` flag of `librespot`. More info about usage can be found in [librespot's player event handler](https://github.com/librespot-org/librespot/blob/dev/src/player_event_handler.rs).
ONEVENT_POST_ENDPOINT||Send a `POST` request with event data to the specified endpoint URL whenever a player event occurs. Request body is `json` encoded and contains all available fields specified by the [librespot's player event handler](https://github.com/librespot-org/librespot/blob/dev/src/player_event_handler.rs). Will be ignored if `ONEVENT_COMMAND` is set.
LOG_COMMAND_LINE||Set to `Y` or `y` to enable, `N` or `n` to disable. Defaults to `Y`.

### Volumes
Expand Down
51 changes: 51 additions & 0 deletions app/bin/post-event-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# read url input parameter
while [ $# -gt 0 ]; do
case "$1" in
--url=*)
endpoint_url="${1#*=}"
;;
esac
shift
done

# post current event data the given endpoint URL
curl -X POST \
-s \
-H "Content-Type: application/json" \
-d '{
"PLAYER_EVENT": "'"$PLAYER_EVENT"'",
"TRACK_ID": "'"$TRACK_ID"'",
"URI": "'"$URI"'",
"NAME": "'"$NAME"'",
"COVERS": "'"${COVERS//$'\n'/,}"'",
"LANGUAGE": "'"$LANGUAGE"'",
"DURATION_MS": "'"$DURATION_MS"'",
"NAME": "'"$NAME"'",
"IS_EXPLICIT": "'"$IS_EXPLICIT"'",
"ITEM_TYPE": "'"$ITEM_TYPE"'",
"ARTISTS": "'"$ARTISTS"'",
"ALBUM_ARTISTS": "'"$ALBUM_ARTISTS"'",
"ALBUM": "'"$ALBUM"'",
"NUMBER": "'"$NUMBER"'",
"DISC_NUMBER": "'"$DISC_NUMBER"'",
"DESCRIPTION": "'"$DESCRIPTION"'",
"PUBLISH_TIME": "'"$PUBLISH_TIME"'",
"SHOW_NAME": "'"$SHOW_NAME"'",
"POSITION_MS": "'"$POSITION_MS"'",
"CONNECTION_ID": "'"$CONNECTION_ID"'",
"USER_NAME": "'"$USER_NAME"'",
"CLIENT_ID": "'"$CLIENT_ID"'",
"CLIENT_NAME": "'"$CLIENT_NAME"'",
"CLIENT_BRAND_NAME": "'"$CLIENT_BRAND_NAME"'",
"CLIENT_MODEL_NAME": "'"$CLIENT_MODEL_NAME"'",
"VOLUME": "'"$VOLUME"'",
"SHUFFLE": "'"$SHUFFLE"'",
"REPEAT": "'"$REPEAT"'",
"AUTO_PLAY": "'"$AUTO_PLAY"'",
"FILTER": "'"$FILTER"'",
"SINK_STATUS": "'"$SINK_STATUS"'"
}' \
$endpoint_url

9 changes: 9 additions & 0 deletions app/bin/run-librespot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ if [ "${PASSTHROUGH^^}" = "Y" ]; then
CMD_LINE="$CMD_LINE --passthrough"
fi

# parse onevent related config options
# if both onevent options are set,
# the user defined script takes precedence
if [[ -n "$ONEVENT_COMMAND" ]]; then
CMD_LINE="$CMD_LINE --onevent '/userscripts/$ONEVENT_COMMAND'"
elif [[ -n "$ONEVENT_POST_ENDPOINT" ]]; then
CMD_LINE="$CMD_LINE --onevent '/app/bin/post-event-data.sh --url=$ONEVENT_POST_ENDPOINT'"
fi

if [[ -z "${LOG_COMMAND_LINE}" || "${LOG_COMMAND_LINE^^}" = "Y" ]]; then
ur=$(printf '*%.0s' $(seq 1 ${#SPOTIFY_USERNAME}))
pr=$(printf '*%.0s' $(seq 1 ${#SPOTIFY_PASSWORD}))
Expand Down
0