2020-05-27 13:22:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-04-30 18:35:10 +00:00
|
|
|
# Requires ffmpeg
|
2020-05-27 13:22:40 +00:00
|
|
|
|
|
|
|
[ ! -f "$2" ] && printf "The first file should be the audio, the second should be the timecodes.\\n" && exit
|
|
|
|
|
|
|
|
echo "Enter the album/book title:"; read -r booktitle
|
|
|
|
echo "Enter the artist/author:"; read -r author
|
|
|
|
echo "Enter the publication year:"; read -r year
|
|
|
|
|
|
|
|
inputaudio="$1"
|
2022-07-21 18:33:35 +00:00
|
|
|
ext="${1##*.}"
|
2020-05-27 13:22:40 +00:00
|
|
|
|
|
|
|
# Get a safe file name from the book.
|
|
|
|
escbook="$(echo "$booktitle" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
|
|
|
|
|
2022-04-30 18:35:10 +00:00
|
|
|
! mkdir -p "$escbook" &&
|
|
|
|
echo "Do you have write access in this directory?" &&
|
|
|
|
exit 1
|
2020-05-27 13:22:40 +00:00
|
|
|
|
|
|
|
# Get the total number of tracks from the number of lines.
|
|
|
|
total="$(wc -l < "$2")"
|
|
|
|
|
2022-04-30 18:35:10 +00:00
|
|
|
cmd="ffmpeg -i \"$inputaudio\" -nostdin -y"
|
|
|
|
|
2020-05-27 13:22:40 +00:00
|
|
|
while read -r x;
|
|
|
|
do
|
2022-04-30 18:35:10 +00:00
|
|
|
end="$(echo "$x" | cut -d' ' -f1)"
|
|
|
|
file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext"
|
|
|
|
if [ -n "$start" ]; then
|
|
|
|
cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -metadata total=\"$total\" -ss \"$start\" -to \"$end\" -vn -c:a copy \"$file\" "
|
|
|
|
fi
|
|
|
|
title="$(echo "$x" | cut -d' ' -f2-)"
|
|
|
|
esctitle="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
|
|
|
|
track="$((track+1))"
|
|
|
|
start="$end"
|
2020-05-27 13:22:40 +00:00
|
|
|
done < "$2"
|
2022-04-30 18:35:10 +00:00
|
|
|
|
|
|
|
# Last track must be added out of the loop.
|
2020-05-29 17:37:15 +00:00
|
|
|
file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext"
|
2022-04-30 18:35:10 +00:00
|
|
|
cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -ss \"$start\" -vn -c copy \"$file\""
|
|
|
|
|
|
|
|
eval "$cmd"
|