Compare commits
5 Commits
9a64735f3c
...
main
Author | SHA1 | Date | |
---|---|---|---|
d3132b0ca3
|
|||
b9f7855afc
|
|||
eaa9059fb5
|
|||
bb1eaa30ad
|
|||
7728ebfb16
|
@ -1,23 +1,26 @@
|
||||
#!/bin/bash
|
||||
set -uexo pipefail
|
||||
set -ueo pipefail
|
||||
|
||||
# Define PID file location
|
||||
PID_FILE="/tmp/yt-dlp-ntfy.pid"
|
||||
|
||||
# Check if the script is already running
|
||||
if [ -e "$PID_FILE" ] && kill -0 $(cat "$PID_FILE"); then
|
||||
echo "Script is already running. Exiting."
|
||||
if [ -e "$PID_FILE" ] && kill -0 $(cat "$PID_FILE") &>/dev/null; then
|
||||
echo "Script is already running as PID $(cat $PID_FILE). Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Store the PID of the current process
|
||||
echo $$ > "$PID_FILE"
|
||||
echo "Running as PID $(cat $PID_FILE)"
|
||||
|
||||
# Define ntfy server and channel
|
||||
NTFY_SERVER="https://notify.kucharczyk.xyz"
|
||||
CHANNEL="clipboard"
|
||||
ACCESS_TOKEN="$NTFY_ACCESS_TOKEN"
|
||||
|
||||
echo "Monitoring channel $CHANNEL of server $NTFY_SERVER"
|
||||
|
||||
# Run the script in an infinite loop to listen for new messages
|
||||
while true; do
|
||||
while read -r message; do
|
||||
@ -29,8 +32,6 @@ while true; do
|
||||
echo "Downloading video from $video_url"
|
||||
yt-dlp "$video_url"
|
||||
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" -d "Finished downloading." "$NTFY_SERVER/$CHANNEL"
|
||||
else
|
||||
echo "Received non-URL message: $video_url"
|
||||
fi
|
||||
done
|
||||
|
||||
@ -40,5 +41,5 @@ while true; do
|
||||
done < <(curl --no-buffer -s -H "Authorization: Bearer $ACCESS_TOKEN" "$NTFY_SERVER/$CHANNEL/json")
|
||||
|
||||
# Cleanup PID file on script exit
|
||||
trap "rm -f $PID_FILE" EXIT
|
||||
trap 'rm -f $PID_FILE' EXIT
|
||||
|
||||
|
Reference in New Issue
Block a user