jq->jaq
All checks were successful
Nix Build / build-nixos (push) Successful in 4m53s

This commit is contained in:
soraefir
2024-04-13 19:16:52 +02:00
parent 41efe10dd4
commit 52e9726ba7
3 changed files with 15 additions and 15 deletions

View File

@@ -19,11 +19,11 @@ PAUSED=$(( $PID == 0 || $RADIO_ID == 0 ? 1 : 0 ))
STATUS="{}"
get_radio() {
echo "$STATIONS" | jq -r --argjson sel_id "$RADIO_ID" 'map(select(.id == $sel_id)).[0]'
echo "$STATIONS" | jaq -r --argjson sel_id "$RADIO_ID" 'map(select(.id == $sel_id)).[0]'
}
get_song() {
echo $(curl -s "$URL_BASE/station/history/?id=$RADIO_ID" | jq '.result.history[0] | ({id, artist, song, image600})')
echo $(curl -s "$URL_BASE/station/history/?id=$RADIO_ID" | jaq '.result.history[0] | ({id, artist, song, image600})')
}
@@ -34,8 +34,8 @@ update() {
}
start() {
STATIONS=$(curl -s "$URL_BASE/stations/" | jq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})')
RADIO_URL=$(get_radio | jq -r '.stream_hls')
STATIONS=$(curl -s "$URL_BASE/stations/" | jaq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})')
RADIO_URL=$(get_radio | jaq -r '.stream_hls')
if [ "$PAUSED" = 0 ]; then
kill -9 $PID
fi
@@ -55,14 +55,14 @@ toggle() {
}
status() {
echo $(jq -cnr --argjson pid "$PID" --argjson stations "$STATIONS" --argjson radio_id "$RADIO_ID" --argjson is_paused "$PAUSED" --argjson info "$INFO" '{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations}')
echo $(jaq -cnr --argjson pid "$PID" --argjson stations "$STATIONS" --argjson radio_id "$RADIO_ID" --argjson is_paused "$PAUSED" --argjson info "$INFO" '{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations}')
}
status_loop() {
STATUS=$(status)
echo $STATUS
STATIONS=$(curl -s "$URL_BASE/stations/" | jq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})')
STATIONS=$(curl -s "$URL_BASE/stations/" | jaq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})')
last_time_info=0
last_time=0
while true; do
@@ -82,9 +82,9 @@ status_loop() {
fi
if [[ $delta_i -gt 15000 ]]; then
if [ "$PAUSED" = 1 ]; then
INFO="{\"id\":null,\"artist\":null,\"song\":null,\"image600\": \"$(get_radio | jq -r '.icon_fill_white')\"}"
INFO="{\"id\":null,\"artist\":null,\"song\":null,\"image600\": \"$(get_radio | jaq -r '.icon_fill_white')\"}"
else
INFO=$(echo "$INFO" "$(get_song)" | jq -s ' reduce .[] as $item ( {}; . + (
INFO=$(echo "$INFO" "$(get_song)" | jaq -s ' reduce .[] as $item ( {}; . + (
reduce ($item | to_entries[]) as $entry ( {}; if $entry.value != null then .[$entry.key] = $entry.value else . end
)) )')
fi