Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple script to automate merging converted mp3 files into single mp3 and add cover image
#!/usr/bin/bash
# Keith Kim, 2021-06
# This is to autoamte merging mp3 files and add cover image for audible audio book files converted to mp3 using AAXtoMP3
OIFS="$IFS"
IFS=$'\n'
for authorpath in `find . -maxdepth 1 -type d -print`
do
if [ "." == "$authorpath" ]; then continue; fi
echo "### ==============================================="
echo "### Author path: $authorpath"
pushd $authorpath > /dev/null
for bookpath in `find . -maxdepth 1 -type d -print`
do
if [ "." == "$bookpath" ]; then continue; fi
echo "### Book path: $bookpath"
pushd "$bookpath" > /dev/null
rm mp3list.lst &> /dev/null
rm merged.mp3 &> /dev/null
path="`pwd`"
author="`echo $authorpath | sed "s/\.\///"`"
book="`echo $bookpath | sed "s/\.\///"`"
echo "### --------------------"
echo "### Author: $author"
echo "### Book: $book"
echo "### --------------------"
for mp3file in $(ls *.mp3)
do
echo "### $mp3file"
echo "file '$path/$mp3file'" >> mp3list.lst
done
ffmpeg -f concat -safe 0 -i mp3list.lst \
-metadata artist="$author" \
-metadata title="$book" \
-c copy $path/merged.mp3
mid3v2 -p cover.jpg merged.mp3
mv merged.mp3 "$author-$book.mp3"
popd > /dev/null
done
popd > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment