Compare commits

...

2 Commits

Author SHA1 Message Date
Renovate Bot
c3ceacc725 Lock file maintenance 2023-12-02 01:01:54 +00:00
09e3a2af95 Update modules/home/wayland/apps/eww/bar/scripts/radio 2023-12-01 15:50:07 +01:00
2 changed files with 130 additions and 130 deletions

44
flake.lock generated
View File

@ -39,11 +39,11 @@
},
"hardware": {
"locked": {
"lastModified": 1700559156,
"narHash": "sha256-gL4epO/qf+wo30JjC3g+b5Bs8UrpxzkhNBBsUYxpw2g=",
"lastModified": 1701250978,
"narHash": "sha256-ohu3cz4edjpGxs2qUTgbs0WrnewOX4crnUJNEB6Jox4=",
"owner": "nixos",
"repo": "nixos-hardware",
"rev": "c3abafb01cd7045dba522af29b625bd1e170c2fb",
"rev": "8772491ed75f150f02552c60694e1beff9f46013",
"type": "github"
},
"original": {
@ -59,11 +59,11 @@
]
},
"locked": {
"lastModified": 1700900274,
"narHash": "sha256-KWoKDP5I1viHR4bG3ENnJ7H1DD16tXWH4ROvS0IfXw8=",
"lastModified": 1701433070,
"narHash": "sha256-Gf9JStfENaUQ7YWFz3V7x/srIwr4nlnVteqaAxtwpgM=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "a462e7315deaa8194b0821f726709bb7e51a850c",
"rev": "4a8545f5e737a6338814a4676dc8e18c7f43fc57",
"type": "github"
},
"original": {
@ -83,11 +83,11 @@
"xdph": "xdph"
},
"locked": {
"lastModified": 1700967537,
"narHash": "sha256-TzyP5xNGF+rCj2ko+E+VOpQTtzlQ4TfDLuObEPbRX6g=",
"lastModified": 1701451430,
"narHash": "sha256-uVrtDJUb5+WylStcz2M8Awx1MFNFzpGZwklaPtXv20Y=",
"owner": "hyprwm",
"repo": "Hyprland",
"rev": "cd96ceecc551c25631783499bd92c6662c5d3616",
"rev": "6e8b9ef7d8aa53247d5122b6641b9afa0df798df",
"type": "github"
},
"original": {
@ -142,11 +142,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1700794826,
"narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=",
"lastModified": 1701253981,
"narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8",
"rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58",
"type": "github"
},
"original": {
@ -173,11 +173,11 @@
},
"nur": {
"locked": {
"lastModified": 1700999123,
"narHash": "sha256-cHUigiOX70G8tZ6Utdl7IkYZ879GDeUkdoI9urX2WcM=",
"lastModified": 1701470031,
"narHash": "sha256-FTiAgPcK72g3S08CuE5CiFVwrkQ00uQhCpxVGUTVX8k=",
"owner": "nix-community",
"repo": "nur",
"rev": "95f618e3eaf6156578985fb5d14da500b811c52e",
"rev": "9593bb9bb0b60b8e9023587386bd32743072ac68",
"type": "github"
},
"original": {
@ -208,11 +208,11 @@
]
},
"locked": {
"lastModified": 1700967639,
"narHash": "sha256-uuUwD/O1QcVk+TWPZFwl4ioUkC8iACj0jEXSyE/wGPI=",
"lastModified": 1701127353,
"narHash": "sha256-qVNX0wOl0b7+I35aRu78xUphOyELh+mtUp1KBx89K1Q=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "4be58d802693d7def8622ff34d36714f8db40371",
"rev": "b1edbf5c0464b4cced90a3ba6f999e671f0af631",
"type": "github"
},
"original": {
@ -240,18 +240,18 @@
"flake": false,
"locked": {
"host": "gitlab.freedesktop.org",
"lastModified": 1700734054,
"narHash": "sha256-SBu1y01WjCSrcCKvgfCDDckrZjU/OmCJT8Xc+hPow7E=",
"lastModified": 1701368958,
"narHash": "sha256-7kvyoA91etzVEl9mkA/EJfB6z/PltxX7Xc4gcr7/xlo=",
"owner": "wlroots",
"repo": "wlroots",
"rev": "2eb225236eb72f27beec921e9f37ddf58e874fba",
"rev": "5d639394f3e83b01596dcd166a44a9a1a2583350",
"type": "gitlab"
},
"original": {
"host": "gitlab.freedesktop.org",
"owner": "wlroots",
"repo": "wlroots",
"rev": "2eb225236eb72f27beec921e9f37ddf58e874fba",
"rev": "5d639394f3e83b01596dcd166a44a9a1a2583350",
"type": "gitlab"
}
},

View File

@ -1,108 +1,108 @@
#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
URL_BASE="https://www.radiorecord.ru/api"
MPV_PID_FILE="/tmp/mpv_radio_pid"
RADIO_ID_FILE="/tmp/radio_id"
STATIONS="[]"
PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 )
RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 )
RADIO_URL=""
INFO='{"id":null,"artist":null,"song":null,"image600":null}'
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]'
}
get_song() {
echo $(curl -s "$URL_BASE/station/history/?id=$RADIO_ID" | jq '.result.history[0] | ({id, artist, song, image600})')
}
update() {
PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 )
RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 )
PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 ))
}
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')
if [ "$PAUSED" = 0 ]; then
kill -9 $PID
fi
mpv "$RADIO_URL" & echo $! > "$MPV_PID_FILE"
echo $RADIO_ID > "$RADIO_ID_FILE"
}
toggle() {
if [ "$PAUSED" = 1 ]; then
echo $RADIO_ID $PID
start
else
kill -9 "$PID"
rm -f $MPV_PID_FILE
fi
}
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}')
}
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})')
last_time_info=0
last_time=0
while true; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
delta_i=$((current_time - last_time_info))
if [[ $delta -gt 1000 ]]; then
PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 )
RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 )
PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 ))
NEW_STATUS=$(status)
if [[ "$NEW_STATUS" != "$STATUS" ]]; then
STATUS=$NEW_STATUS
echo $STATUS
fi
last_time=$current_time
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')\"}"
else
INFO=$(echo "$INFO" "$(get_song)" | jq -s ' reduce .[] as $item ( {}; . + (
reduce ($item | to_entries[]) as $entry ( {}; if $entry.value != null then .[$entry.key] = $entry.value else . end
)) )')
fi
last_time_info=$current_time
fi
done
}
# Main script
case "$1" in
"start")
RADIO_ID=$2
start
;;
"toggle")
toggle
;;
*)
status_loop
;;
esac
#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
URL_BASE="https://www.radiorecord.ru/api"
MPV_PID_FILE="/tmp/mpv_radio_pid"
RADIO_ID_FILE="/tmp/radio_id"
STATIONS="[]"
PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 )
RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 )
RADIO_URL=""
INFO='{"id":null,"artist":null,"song":null,"image600":null}'
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]'
}
get_song() {
echo $(curl -s "$URL_BASE/station/history/?id=$RADIO_ID" | jq '.result.history[0] | ({id, artist, song, image600})')
}
update() {
PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 )
RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 )
PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 ))
}
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')
if [ "$PAUSED" = 0 ]; then
kill -9 $PID
fi
mpv "$RADIO_URL" & echo $! > "$MPV_PID_FILE"
echo $RADIO_ID > "$RADIO_ID_FILE"
}
toggle() {
if [ "$PAUSED" = 1 ]; then
echo $RADIO_ID $PID
start
else
kill -9 "$PID"
rm -f $MPV_PID_FILE
fi
}
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}')
}
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})')
last_time_info=0
last_time=0
while true; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
delta_i=$((current_time - last_time_info))
if [[ $delta -gt 1000 ]]; then
PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 )
RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 )
PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 ))
NEW_STATUS=$(status)
if [[ "$NEW_STATUS" != "$STATUS" ]]; then
STATUS=$NEW_STATUS
echo $STATUS
fi
last_time=$current_time
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')\"}"
else
INFO=$(echo "$INFO" "$(get_song)" | jq -s ' reduce .[] as $item ( {}; . + (
reduce ($item | to_entries[]) as $entry ( {}; if $entry.value != null then .[$entry.key] = $entry.value else . end
)) )')
fi
last_time_info=$current_time
fi
done
}
# Main script
case "$1" in
"start")
RADIO_ID=$2
start
;;
"toggle")
toggle
;;
*)
status_loop
;;
esac