This script takes MP3 files downloaded from Libro.fm and concatenates them into one MP3 file with generated chapters. It utilizes various command-line tools such as ffmpeg
, ffprobe
, and mkvmerge
.
Make sure the following dependencies are installed:
- ffmpeg
- ffprobe
- mkvmerge
If any of these dependencies are missing, the script will not work correctly.
python main.py [-d|--dir <directory>]
-d|--dir
: Specify the directory where the MP3 files you wish to concatenate are located. The directory name should be the same as the title of the audiobook as in the MP3 files. (default: current directory)
python main.py -d /path/to/audiobook
- Check dependencies: Ensures that the required dependencies are installed.
- Parse command-line arguments: The script accepts an optional directory argument to specify the location of the MP3 files.
- Change to the specified directory: Sets the working directory to the provided directory.
- Get book title and output paths: Determines the book title based on the directory name and sets the output path for the concatenated audio file.
- Count tracks: Retrieves the number of MP3 tracks in the directory.
- Construct the initial command: Creates the initial command for
mkvmerge
to merge the tracks. - Add tracks to the command: Appends all tracks to the command.
- Append sections: Generates section information for chapter creation.
- Finalize the command: Adds chapter generation options and append sections to the command.
- Execute the command: Runs the
mkvmerge
command to concatenate the tracks. - Extract cover image: Extracts the cover image from the first track if present.
- Prompt for artist name: Asks the user to enter the album artist name.
- Convert to MP3: Converts the concatenated audio file to MP3 format, adding metadata and cover image if available.
- Clean up: Removes the intermediate
.mka
file.
Note: The script assumes that the MP3 files in the directory follow the naming convention "<book_title> - Track 001.mp3"
, "Track 002.mp3"
, and so on.