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
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
3 changed files with 15 additions and 15 deletions

View File

@ -3,7 +3,7 @@
config = lib.mkIf (config.homecfg.make.gui) {
home.packages = with pkgs; [
custom.vosk.base
jq
jaq
(python3.withPackages (ps: with ps; [ translatepy ]))
];
@ -46,13 +46,13 @@
export VOSK_MODEL=$MODEL
case $TRANS in
"None")
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' 2>/dev/null
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jaq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' 2>/dev/null
;;
"None-prog")
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty, .partial // empty | select(length > 0)' 2>/dev/null
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jaq --unbuffered -r '.alternatives[0].text // empty, .partial // empty | select(length > 0)' 2>/dev/null
;;
*)
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' | python ~/.config/script/transcript-translate.py $TRANS
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jaq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' | python ~/.config/script/transcript-translate.py $TRANS
;;
esac
'';

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

View File

@ -7,7 +7,7 @@ let
pkgs.writeShellScriptBin "waybar-${name}" ''
set -euo pipefail
${pre}
${pkgs.jq}/bin/jq -cn \
${pkgs.jaq}/bin/jaq -cn \
--arg text "${text}" \
--arg tooltip "${tooltip}" \
--arg alt "${alt}" \
@ -19,7 +19,7 @@ let
in {
config = lib.mkIf (config.homecfg.wm == "Wayland") {
home.packages = [ pkgs.custom.amdgpu_top pkgs.jq ];
home.packages = [ pkgs.custom.amdgpu_top pkgs.jaq ];
programs.waybar = {
enable = true;
@ -204,7 +204,7 @@ in {
"exec" = jsonOutput "gpu" {
tooltip = "...";
percentage = ''
$(amdgpu_top -J -n 1 | jq -r '.devices[0].GRBM2."Command Processor - Graphics".value')'';
$(amdgpu_top -J -n 1 | jaq -r '.devices[0].GRBM2."Command Processor - Graphics".value')'';
};
"return-type" = "json";
"interval" = 5;