61 lines
1.6 KiB
Bash
61 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
set -x
|
|
set -eufo pipefail
|
|
|
|
# CONSTANTS
|
|
declare -r m4b-tool="nix run github:sandreas/m4b-tool#m4b-tool-libfdk -- "
|
|
declare -r script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# VARS
|
|
LEADING_ZEROES=2
|
|
MAIN_SRC="${SRC:${script_dir}/src}"
|
|
MAIN_OUT="${OUT:${script_dir}/out}"
|
|
|
|
# FUNCTIONS
|
|
parse-vars() {
|
|
# TODO implement parsing the directory structure of the passed directory, to fill in missing vars and return them
|
|
# Series structure: ${SRC}/<author>/<series>/Book <part> - <year> - <book> {<narrator>}/
|
|
# Standalone structure: ${SRC}/<author>/<year> - <book> {<narrator>}/
|
|
# Return the <part> wihh leading zeros based on the LEADING_ZEROES variable
|
|
}
|
|
|
|
get-book-directories() {
|
|
# TODO implemet getting the book directoris based on the ${SRC} path
|
|
# find the directories that contains the books files and return them as an array
|
|
# Example book directory:
|
|
# /path/to/src/Author/Series/Book Part - Year - Book {Narrator}/
|
|
# /path/to/src/Author/Year - Book {Narrator}/
|
|
}
|
|
|
|
m4b-merge() {
|
|
local output_file="${1}"
|
|
local source_dir="${2}"
|
|
local author="${3}"
|
|
local narrator="${4}"
|
|
local title="${5}"
|
|
local year="${6}"
|
|
local series="${7}"
|
|
local series_index=${8}
|
|
|
|
mkdir -p "$(dirname "${output_file}")"
|
|
"${m4b-tool}" \
|
|
merge \
|
|
-v \
|
|
--jobs=6 \
|
|
--audio-samplerate=44100 \
|
|
--audio-quality=100 \
|
|
--writer="${author}" \
|
|
--artist="${narrator}" \
|
|
--title="${title}" \
|
|
--year="${year}" \
|
|
--album="${series}" \
|
|
--album-sort="${series_index}" \
|
|
--output-file="${output_file}/" \
|
|
-- "${source_dir}"
|
|
}
|
|
|
|
main() {
|
|
|
|
}
|
|
|
|
main "$@"
|