Skip to content

Commit

Permalink
More robustness (#7)
Browse files Browse the repository at this point in the history
- Check for running recording
- Handle reconnects better (try for 5min, time out after 10sec)
  • Loading branch information
rmens authored Jul 7, 2024
1 parent edd5217 commit ca0df8e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion audiologger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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

0 comments on commit ca0df8e

Please sign in to comment.