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