Created
May 15, 2024 21:21
-
-
Save kanjieater/f297b8d84809820c41e928ed81cbe479 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
audiobooks_path="/mnt/a/MusicBee/test" | |
# Loop over each audiobook folder | |
for audiobook_folder in "${audiobooks_path}"/*/ | |
do | |
# Print out the name of the audiobook folder | |
echo "Merging files in ${audiobook_folder}..." | |
# Get the audiobook name | |
audiobook_name="$(basename "${audiobook_folder}")" | |
# Get the list of mp4 files in the audiobook folder | |
mp4_files=$(ls -1v "${audiobook_folder}"*.mp3) | |
# Replace audiobooks_path with "./" in each mp4 file path | |
mp4_files=$(echo "$mp4_files" | sed "s|${audiobook_folder}|./|g") | |
# Wrap each mp4 file path in quotes | |
mp4_files=$(echo "$mp4_files" | awk '{printf "\"%s\" ", $0}') | |
# Run the m4b-tool Docker container to merge the MP4 files | |
docker_cmd="docker run -it --rm -u $(id -u):$(id -g) -v \"${audiobook_folder}\":/mnt sandreas/m4b-tool:latest merge ${mp4_files} --output-file \"./${audiobook_name}.m4b\" --jobs $(nproc --all) --name \"${audiobook_name}\"" | |
echo "$docker_cmd" | |
eval "$docker_cmd" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment