summaryrefslogtreecommitdiff
path: root/transcode_album.sh
diff options
context:
space:
mode:
authorCaine <susan@tomflux.xyz>2026-02-15 09:41:49 +0000
committerCaine <susan@tomflux.xyz>2026-02-15 09:41:49 +0000
commitc7956ae9b228054d57897ea338ad4154cc0b7221 (patch)
treea1f517ea452dddf34468c01c85871358e8b7295e /transcode_album.sh
Initial commit: susan automation scriptsHEADmaster
Overnight transcoding, music discovery/import, system health reports, stats page generator, and bookmark management. Secrets stored in /etc/automation/ — not in repo.
Diffstat (limited to 'transcode_album.sh')
-rwxr-xr-xtranscode_album.sh81
1 files changed, 81 insertions, 0 deletions
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 <source_dir> [--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 <source_directory> [--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