Created
May 24, 2023 01:17
-
-
Save ianfoo/506f0b8de51533169ad1f7039d85adc6 to your computer and use it in GitHub Desktop.
xbar action to show current playing selection on JEMP radio, with help from https://github.com/ianfoo/ph and jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PATH=$HOME/bin:/opt/homebrew/bin:$PATH | |
output_vars () { | |
ph --format json | jq -r '"TITLE=\"\(.title)\"\nARTIST=\"\(.artist)\"\nDATE=\"\(.performance_time)\""' | |
} | |
eval $(output_vars) | |
OUTPUT="$TITLE" | |
if [[ -n $ARTIST ]]; then | |
OUTPUT="$OUTPUT • $ARTIST" | |
fi | |
if [[ $DATE != "0001-01-01T00:00:00Z" ]]; then | |
# BSD `date` does not understand "Z" as a time zone, so replace | |
# it with an explicit timezone offset. | |
reformatted_date=$(echo "$DATE" | sed 's/Z$/+0000/') | |
# Note that this invocation of `date` is for BSD date, | |
# not GNU date, which will use different command line flags. | |
date_only=$(date -jf "%Y-%m-%dT%H:%M:%S%z" "$reformatted_date" "+%Y-%m-%d") | |
OUTPUT="$OUTPUT • $date_only" | |
fi | |
echo "$OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment