albumsplit (1885B)
1 #!/bin/sh 2 3 # Requires ffmpeg (audio splitting) and my `tag` wrapper script. 4 [ ! -f "$2" ] && printf "The first file should be the audio, the second should be the timecodes.\\n" && exit 5 echo "Enter the album/book title:"; read -r albumtitle 6 echo "Enter the artist/author:"; read -r author 7 echo "Enter the publication year:"; read -r year 8 9 inputaudio="$1" 10 11 # Get a safe file name from the book. 12 escbook="$(echo "$albumtitle" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" 13 mkdir -p "$escbook" || echo "Do you have write access in this directory?" && exit 1 14 15 # As long as the extension is in the tag script, it'll work. 16 ext="mp3" 17 #ext="${1#*.}" 18 19 # Get the total number of tracks from the number of lines. 20 total="$(wc -l < "$2")" 21 while read -r x; do 22 end="$(echo "$x" | cut -d' ' -f1)" 23 [ -n "$start" ] && 24 echo "From $start to $end; $track $title" 25 file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" 26 [ -n "$start" ] && echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -to "$end" -vn "$file" && 27 echo "Tagging \"$title\"..." && tag -a "$author" -A "$albumtitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file" 28 title="$(echo "$x" | cut -d' ' -f 2-)" 29 esctitle="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" 30 track="$((track+1))" 31 start="$end" 32 done < "$2" 33 34 # The last track must be done outside the loop. 35 echo "From $start to the end: $title" 36 file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" 37 echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -vn "$file" && 38 echo "Tagging \"$title\"..." && tag -a "$author" -A "$albumtitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file"