Files
arr-scripts/readarr/combine.bash
catduckgnaf 0a9a8545be Adding Script to Combine MP3 Post Download to M4B
This "should" work. It is a new script that will be designed for audiobooks. I included ffmpeg in the build itself, verse a docker mod.  The goal of this script is to recreate what calibre-server does for metadata, Assuming this PR is approved (and I may need some help) I want to add tone and metadata. This is a good first step by combining multiple mp3s and even m4bs into one clean file.
2023-12-08 14:46:21 -05:00

48 lines
1.3 KiB
Bash

#!/usr/bin/env bash
scriptVersion=1.0
rootFolderPath="$(dirname "$readarr_author_path")"
scriptName="M4bCombine"
log() {
m_time=$(date "+%F %T")
echo "$m_time :: $scriptName :: $scriptVersion :: $1" >> "/config/logs/$scriptName-$(date +"%Y_%m_%d_%I_%M_%p").txt"
}
# Combine M4b Files
combineM4bFiles() {
log "Combining M4b files using FFmpeg..."
# Determine the M4b files path based on the context
if [ -z "$readarr_author_path" ]; then
# Extended script context
m4bFiles="$readarr_artist_path/*.mp3 $readarr_artist_path/*.m4b"
outputFolder="$readarr_artist_path/"
else
# Readarr context
m4bFiles="$1/*.mp3 $1/*.m4b"
outputFolder="$1/"
fi
# Extract author and book information
author=$(basename "$(dirname "$readarr_author_path")")
book=$(basename "$readarr_author_path")
# Create the output file path
outputFile="${outputFolder}${author}_${book}_combined.m4b"
# FFmpeg command to concatenate M4b files
ffmpeg -i "concat:$m4bFiles" -vn -b:a 128k -f m4b "$outputFile" 2>&1
if [ $? -eq 0 ]; then
log "M4b files combined successfully. Output: $outputFile"
else
log "Error combining M4b files with FFmpeg."
fi
}
# Call the function to combine M4b files
combineM4bFiles "$readarr_artist_path"
exit 0