diff --git a/audiologger.sh b/audiologger.sh index 6124405..d2b6c6e 100755 --- a/audiologger.sh +++ b/audiologger.sh @@ -45,6 +45,12 @@ fi # Remove old files based on the KEEP variable find "$RECDIR" -type f -mtime "+$KEEP" -exec rm {} \; || log_message "Failed to remove old files in $RECDIR" +# Check if an ffmpeg process with the specified stream URL and timestamp is already running +if pgrep -af "ffmpeg.*$STREAMURL.*$TIMESTAMP" > /dev/null; then + log_message "An ffmpeg recording process for $TIMESTAMP with $STREAMURL is already running. Exiting." + exit 1 +fi + # Fetch current program name if [ "$PARSE_METADATA" -eq 1 ]; then # Parse metadata using jq @@ -66,4 +72,4 @@ fi echo "$PROGRAM_NAME" > "${RECDIR}/${TIMESTAMP}.meta" || { log_message "Failed to write metadata file"; exit 1; } # Record next hour's stream -ffmpeg -loglevel error -user_agent "ZuidWest Audiologger 3.0" -t 3600 -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -i "$STREAMURL" -c copy -f mp3 -y "${RECDIR}/${TIMESTAMP}.mp3" & disown \ No newline at end of file +ffmpeg -loglevel error -t 3600 -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 300 -reconnect_on_http_error 404 -rw_timeout 10000000 -i "$STREAMURL" -c copy -f mp3 -y "${RECDIR}/${TIMESTAMP}.mp3" & disown