From 65b8caf7f9a1da13c46bfb2aa68b174d06408f79 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 30 Apr 2026 11:53:57 +0000 Subject: [PATCH] =?UTF-8?q?Reorder=20audio=20fallback=20chain:=20today=20?= =?UTF-8?q?=E2=86=92=20live=20RTSP=20=E2=86=92=20yesterday=20=E2=86=92=20l?= =?UTF-8?q?ibrary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves live RTSP capture to 2nd position so current ambient sound is preferred over a day-old recording when today's scheduled capture is missing. https://claude.ai/code/session_01DANuzLCLhhQ7Li12RTcswY --- daily_sunrise_video.sh | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/daily_sunrise_video.sh b/daily_sunrise_video.sh index febe5d7..4aaa283 100755 --- a/daily_sunrise_video.sh +++ b/daily_sunrise_video.sh @@ -343,33 +343,14 @@ else if [ -f "$cam_audio" ]; then audio_src="$cam_audio" echo "Audio: camera recording (centred on sunrise)" - else - # Yesterday fallback before library: keeps the clip on-site - yesterday_date=$(date -d "yesterday" +%Y-%m-%d) - yday_audio="${AUDIO_DIR:-$BASE_DIR/audio}/sunrise/$CAM_NAME/$yesterday_date/sunrise-audio.m4a" - [ ! -f "$yday_audio" ] && yday_audio="$BASE_DIR/$CAM_NAME/$yesterday_date/sunrise-audio.m4a" - if [ -f "$yday_audio" ]; then - audio_src="$yday_audio" - echo "Audio: yesterday's recording ($yesterday_date)" - else - library_dir="$SCRIPT_DIR/sunrise-sounds" - if [ -d "$library_dir" ]; then - random_file=$(find "$library_dir" -name "*.mp3" | shuf -n 1 2>/dev/null || true) - if [ -n "$random_file" ]; then - audio_src="$random_file" - echo "Audio: library fallback $(basename "$audio_src")" - fi - fi - fi fi - # Live RTSP as last resort — captures current ambient sound when no - # pre-recorded file is available from today, yesterday, or the library. + # 2nd fallback: live RTSP — captures current ambient sound right now if [ -z "$audio_src" ]; then _rtsp_var="CAM_RTSP_${CAM_NAME}" _rtsp_url="${!_rtsp_var:-}" if [ -n "$_rtsp_url" ]; then temp_live_audio=$(mktemp --suffix=.m4a) - echo "Audio: no saved file found — capturing ${SUNRISE_TARGET_SECS}s live from RTSP..." + echo "Audio: no saved file — capturing ${SUNRISE_TARGET_SECS}s live from RTSP..." if ffmpeg -loglevel warning \ -rtsp_transport tcp \ -i "$_rtsp_url" \ @@ -380,7 +361,28 @@ else echo "Audio: live RTSP captured OK" else rm -f "$temp_live_audio"; temp_live_audio="" - echo "Audio: live RTSP capture failed — continuing silent" + echo "Audio: live RTSP capture failed — trying yesterday" + fi + fi + fi + # 3rd fallback: yesterday's recording + if [ -z "$audio_src" ]; then + yesterday_date=$(date -d "yesterday" +%Y-%m-%d) + yday_audio="${AUDIO_DIR:-$BASE_DIR/audio}/sunrise/$CAM_NAME/$yesterday_date/sunrise-audio.m4a" + [ ! -f "$yday_audio" ] && yday_audio="$BASE_DIR/$CAM_NAME/$yesterday_date/sunrise-audio.m4a" + if [ -f "$yday_audio" ]; then + audio_src="$yday_audio" + echo "Audio: yesterday's recording ($yesterday_date)" + fi + fi + # 4th fallback: library + if [ -z "$audio_src" ]; then + library_dir="$SCRIPT_DIR/sunrise-sounds" + if [ -d "$library_dir" ]; then + random_file=$(find "$library_dir" -name "*.mp3" | shuf -n 1 2>/dev/null || true) + if [ -n "$random_file" ]; then + audio_src="$random_file" + echo "Audio: library fallback $(basename "$audio_src")" fi fi fi