Last active
October 24, 2024 15:36
-
-
Save ohac/000ea4aef51c9f8dd980fbbbecfe4e57 to your computer and use it in GitHub Desktop.
Nostr status update script
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
#!/bin/bash | |
# description: Nostr status update script | |
# audacious - Song Change plugin | |
# /path/to/nostr_status.sh "%T" "%a" "%l" | |
if [ -z "$3" ]; then | |
echo "usage: ./nostr-status.sh title artist length_ms" | |
exit | |
fi | |
relays="wss://relay.damus.io wss://nos.lol wss://yabu.me wss://relay-jp.nostr.wirednet.jp" | |
PATH=$HOME/go/bin:$PATH | |
projdir=$HOME/.config/nostr-status | |
mkdir -p $projdir | |
nsechexfn=$projdir/nsechex.txt | |
if [ ! -e $nsechexfn ]; then | |
echo "edit $nsechexfn first" | |
exit | |
fi | |
title="$1" | |
artist="$2" | |
length="$(($3/1000))" | |
algiadir=$HOME/.config/algia | |
algiafn=$algiadir/config.json | |
algiafn2=$algiadir/config-status.json | |
algiaacountopt="" | |
if [ ! -e $algiafn ]; then | |
echo "skip algia" | |
else | |
if [ ! -e $algiafn2 ]; then | |
echo "use algia config.json" | |
else | |
echo "use algia config-status.json" | |
algiaacountopt="-a status" | |
fi | |
poststr1="$title - $artist #nowplaying" | |
algia $algiaacountopt post "$poststr1" \ | |
>> $projdir/algialog1 2>> $projdir/algialog2 | |
fi | |
nsechex=$(cat $nsechexfn) | |
poststr2="$title - $artist" | |
spotify="spotify:search:$(echo -n $poststr2 | tr "@#\\\\\$!%&'()" '..........' | sed 's/ /%20/g')" | |
expiration=$(($(date +%s)+$length)) | |
if [ $expiration -le 60 ]; then | |
expiration=60 | |
fi | |
nak event -k 30315 -c "$poststr2" \ | |
-t "d=music" -t "expiration=$expiration" -t "r=$spotify" \ | |
--sec $nsechex $relays >> $projdir/naklog1 2>> $projdir/naklog2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment