From c7956ae9b228054d57897ea338ad4154cc0b7221 Mon Sep 17 00:00:00 2001 From: Caine Date: Sun, 15 Feb 2026 09:41:49 +0000 Subject: Initial commit: susan automation scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Overnight transcoding, music discovery/import, system health reports, stats page generator, and bookmark management. Secrets stored in /etc/automation/ — not in repo. --- transcode_album.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 transcode_album.sh (limited to 'transcode_album.sh') diff --git a/transcode_album.sh b/transcode_album.sh new file mode 100755 index 0000000..d1ad1aa --- /dev/null +++ b/transcode_album.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# Transcode FLAC album to Opus, preserving metadata +# Usage: ./transcode_album.sh [--delete-source] +# +# Converts all FLAC files to Opus 128kbps (transparent quality, ~10x smaller) +# Preserves all metadata tags and album art + +set -e + +SOURCE_DIR="$1" +DELETE_SOURCE=false +BITRATE="128k" +GROUP="mediaserver" + +if [[ "$2" == "--delete-source" ]]; then + DELETE_SOURCE=true +fi + +if [[ -z "$SOURCE_DIR" ]] || [[ ! -d "$SOURCE_DIR" ]]; then + echo "Usage: $0 [--delete-source]" + exit 1 +fi + +# Count FLAC files +flac_count=$(find "$SOURCE_DIR" -maxdepth 1 -iname "*.flac" | wc -l) +if [[ $flac_count -eq 0 ]]; then + echo "No FLAC files found in $SOURCE_DIR" + exit 0 +fi + +echo "Transcoding $flac_count FLAC files to Opus ($BITRATE)..." +echo "Source: $SOURCE_DIR" + +converted=0 +failed=0 + +# Process each FLAC file +find "$SOURCE_DIR" -maxdepth 1 -iname "*.flac" | while read -r flac_file; do + filename=$(basename "$flac_file") + opus_file="${flac_file%.flac}.opus" + opus_file="${opus_file%.FLAC}.opus" + + echo " Converting: $filename" + + if ffmpeg -hide_banner -loglevel warning -i "$flac_file" \ + -c:a libopus -b:a "$BITRATE" -vbr on \ + -map_metadata 0 \ + -y "$opus_file" 2>&1; then + + # Preserve original timestamp + touch -r "$flac_file" "$opus_file" + + # Fix permissions + chgrp "$GROUP" "$opus_file" 2>/dev/null || true + chmod 664 "$opus_file" 2>/dev/null || true + + if $DELETE_SOURCE; then + rm "$flac_file" + echo " ✓ Converted and removed FLAC" + else + echo " ✓ Converted (FLAC kept)" + fi + ((converted++)) || true + else + echo " ✗ Failed to convert" + ((failed++)) || true + fi +done + +# Also convert any MP3s that are suspiciously large (>15MB per file avg) +# Actually, skip this - MP3s are already compressed + +# Handle cover art - keep it +# ffmpeg should copy embedded art automatically for opus + +echo "" +echo "Done! Converted $converted files." +if $DELETE_SOURCE; then + # Calculate space saved + echo "FLAC files deleted to save space." +fi -- cgit v1.2.3