Last active
January 2, 2022 00:05
-
-
Save keithkim/7c9ac8b7cd291bbcdb1a61ad29691048 to your computer and use it in GitHub Desktop.
simple script to automate merging converted mp3 files into single mp3 and add cover image
This file contains 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
#!/usr/bin/bash | |
# Keith Kim, 2021-06 | |
# This is to automate 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