Skip to content

Commit 23f635d

Browse files
Merge pull request #132 from catduckgnaf/main
Adding Script to Combine MP3 Post Download to M4B
2 parents 819549b + 0a9a854 commit 23f635d

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

readarr/AutoConfig.bash

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ else
103103
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":[]}')
104104
log "Complete"
105105
fi
106+
if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "combine.bash" | read; then
107+
log "combine.bash already added to $arrAppName custom scripts"
108+
else
109+
log "Adding combine.bash to $arrAppName custom scripts"
110+
# Send a command to check file path, to prevent error with adding...
111+
updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2FPlexNotify.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}")
112+
113+
# Add combine.bash
114+
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":[]}')
115+
log "Complete"
116+
fi
106117

107118
log "Script sleeping for (infinity)..."
108119
sleep infinity

readarr/combine.bash

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
scriptVersion=1.0
3+
rootFolderPath="$(dirname "$readarr_author_path")"
4+
scriptName="M4bCombine"
5+
6+
7+
log() {
8+
m_time=$(date "+%F %T")
9+
echo "$m_time :: $scriptName :: $scriptVersion :: $1" >> "/config/logs/$scriptName-$(date +"%Y_%m_%d_%I_%M_%p").txt"
10+
}
11+
12+
# Combine M4b Files
13+
combineM4bFiles() {
14+
log "Combining M4b files using FFmpeg..."
15+
16+
# Determine the M4b files path based on the context
17+
if [ -z "$readarr_author_path" ]; then
18+
# Extended script context
19+
m4bFiles="$readarr_artist_path/*.mp3 $readarr_artist_path/*.m4b"
20+
outputFolder="$readarr_artist_path/"
21+
else
22+
# Readarr context
23+
m4bFiles="$1/*.mp3 $1/*.m4b"
24+
outputFolder="$1/"
25+
fi
26+
27+
# Extract author and book information
28+
author=$(basename "$(dirname "$readarr_author_path")")
29+
book=$(basename "$readarr_author_path")
30+
31+
# Create the output file path
32+
outputFile="${outputFolder}${author}_${book}_combined.m4b"
33+
34+
# FFmpeg command to concatenate M4b files
35+
ffmpeg -i "concat:$m4bFiles" -vn -b:a 128k -f m4b "$outputFile" 2>&1
36+
37+
if [ $? -eq 0 ]; then
38+
log "M4b files combined successfully. Output: $outputFile"
39+
else
40+
log "Error combining M4b files with FFmpeg."
41+
fi
42+
}
43+
44+
# Call the function to combine M4b files
45+
combineM4bFiles "$readarr_artist_path"
46+
47+
exit 0

readarr/setup.bash

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
echo "************ install and update packages ************"
33
apk add -U --update --no-cache \
44
jq \
5-
py3-pip
5+
py3-pip \
6+
ffmpeg
67
echo "************ install python packages ************"
78
pip install --upgrade --no-cache-dir -U yq
89

@@ -24,6 +25,10 @@ echo "Download PlexNotify script..."
2425
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/readarr/PlexNotify.bash -o /config/extended/PlexNotify.bash
2526
echo "Done"
2627

28+
echo "Download combine script..."
29+
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/readarr/combine.bash -o /config/extended/combine.bash
30+
echo "Done"
31+
2732
echo "Download AutoConfig config..."
2833
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/readarr/AutoConfig.json -o /config/extended/AutoConfig.json
2934
echo "Done"

0 commit comments

Comments
 (0)