From 0a9a8545bef41ac0e19445d3f0ce4eca9e97c9f5 Mon Sep 17 00:00:00 2001 From: catduckgnaf Date: Fri, 8 Dec 2023 14:46:21 -0500 Subject: [PATCH] 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. --- readarr/AutoConfig.bash | 11 ++++++++++ readarr/combine.bash | 47 +++++++++++++++++++++++++++++++++++++++++ readarr/setup.bash | 7 +++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 readarr/combine.bash diff --git a/readarr/AutoConfig.bash b/readarr/AutoConfig.bash index da43ec1..fb439e7 100644 --- a/readarr/AutoConfig.bash +++ b/readarr/AutoConfig.bash @@ -103,6 +103,17 @@ else updateArr=$(curl -s "$arrUrl/api/v1/notification?" -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${arrApiKey}" --data-raw '{"onGrab":false,"onReleaseImport":true,"onUpgrade":true,"onRename":false,"onAuthorDelete":true,"onBookDelete":true,"onBookFileDelete":false,"onBookFileDeleteForUpgrade":false,"onHealthIssue":false,"onDownloadFailure":false,"onImportFailure":false,"onBookRetag":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnReleaseImport":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnAuthorDelete":true,"supportsOnBookDelete":true,"supportsOnBookFileDelete":true,"supportsOnBookFileDeleteForUpgrade":true,"supportsOnHealthIssue":true,"includeHealthWarnings":false,"supportsOnDownloadFailure":false,"supportsOnImportFailure":false,"supportsOnBookRetag":true,"supportsOnApplicationUpdate":true,"name":"PlexNotify.bash","fields":[{"name":"path","value":"/config/extended/PlexNotify.bash"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"https://wiki.servarr.com/readarr/supported#customscript","message":{"message":"Testing will execute the script with the EventType set to Test, ensure your script handles this correctly","type":"warning"},"tags":[]}') log "Complete" fi +if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "combine.bash" | read; then + log "combine.bash already added to $arrAppName custom scripts" +else + log "Adding combine.bash to $arrAppName custom scripts" + # Send a command to check file path, to prevent error with adding... + updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2FPlexNotify.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}") + + # Add combine.bash + updateArr=$(curl -s "$arrUrl/api/v1/notification?" -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${arrApiKey}" --data-raw '{"onGrab":false,"onReleaseImport":true,"onUpgrade":true,"onRename":true,"onAuthorDelete":false,"onBookDelete":false,"onBookFileDelete":false,"onBookFileDeleteForUpgrade":false,"onHealthIssue":false,"onDownloadFailure":false,"onImportFailure":false,"onBookRetag":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnReleaseImport":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnAuthorDelete":true,"supportsOnBookDelete":true,"supportsOnBookFileDelete":true,"supportsOnBookFileDeleteForUpgrade":true,"supportsOnHealthIssue":true,"includeHealthWarnings":false,"supportsOnDownloadFailure":false,"supportsOnImportFailure":false,"supportsOnBookRetag":true,"supportsOnApplicationUpdate":false,"name":"combine.bash","fields":[{"name":"path","value":"/config/extended/combine.bash"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"https://wiki.servarr.com/readarr/supported#customscript","message":{"message":"Testing will execute the script with the EventType set to Test, ensure your script handles this correctly","type":"warning"},"tags":[]}') + log "Complete" +fi log "Script sleeping for (infinity)..." sleep infinity diff --git a/readarr/combine.bash b/readarr/combine.bash new file mode 100644 index 0000000..85e62ac --- /dev/null +++ b/readarr/combine.bash @@ -0,0 +1,47 @@ +#!/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 diff --git a/readarr/setup.bash b/readarr/setup.bash index 9698498..7d3e2ea 100644 --- a/readarr/setup.bash +++ b/readarr/setup.bash @@ -2,7 +2,8 @@ echo "************ install and update packages ************" apk add -U --update --no-cache \ jq \ - py3-pip + py3-pip \ + ffmpeg echo "************ install python packages ************" pip install --upgrade --no-cache-dir -U yq @@ -24,6 +25,10 @@ echo "Download PlexNotify script..." curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/readarr/PlexNotify.bash -o /config/extended/PlexNotify.bash echo "Done" +echo "Download combine script..." +curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/readarr/combine.bash -o /config/extended/combine.bash +echo "Done" + echo "Download AutoConfig config..." curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/readarr/AutoConfig.json -o /config/extended/AutoConfig.json echo "Done"