dotfiles

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.margiolis.net/dotfiles.git
Log | Files | Refs | README | LICENSE

ausplit (1471B)


      1 #!/bin/sh
      2 
      3 # ffmpeg and my `tag` script required.
      4 main()
      5 {
      6 	test ${#} -ne 2 && usage
      7 
      8 	auin="${1}"
      9 	local tfile="${2}"
     10 	total="$(wc -l < "${tfile}")"
     11 	# The extension must exist in `tag`.
     12 	ext="${1#*.}"
     13 
     14 	xread "Album/book title: " album
     15 	xread "Artist/author: " author
     16 	xread "Publication year: " year
     17 
     18 	namefmt="$(fmt_name "${album}")"
     19 	mkdir -p "${namefmt}" || exit 1
     20 
     21 	while read -r line; do
     22 		end="$(echo "${line}" | cut -d' ' -f1)"
     23 		test -n "${start}" && split_file
     24 		title="$(echo "${line}" | cut -d' ' -f 2-)"
     25 		titlefmt="$(fmt_name "${title}")"
     26 		track="$((track+1))"
     27 		start="${end}"
     28 	done < "${tfile}"
     29 
     30 	# The last track must be done outside the loop.
     31 	split_file
     32 }
     33 
     34 usage()
     35 {
     36 	echo "usage: ${0##*/} audio timecode_file" 1>&2 && exit 1
     37 }
     38 
     39 xread()
     40 {
     41 	printf "%s" "${1}" && read -r ${2}
     42 }
     43 
     44 fmt_name()
     45 {
     46 	echo "${1}" | iconv -cf UTF-8 -t ASCII//TRANSLIT |
     47 	tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' |
     48 	sed "s/-\+/-/g;s/\(^-\|-\$\)//g"
     49 }
     50 
     51 split_file()
     52 {
     53 	echo "From ${start} to ${end}; ${track} ${title}"
     54 	echo "Splitting \"${title}\"..."
     55 	ofile="${namefmt}/$(printf "%.2d" "${track}")-${titlefmt}.${ext}"
     56 	ffmpeg \
     57 		-nostdin -y -loglevel -8 \
     58 		-i "${auin}" \
     59 		-ss "${start}" \
     60 		`test ${track} -eq ${total} || echo "-to ${end}"` \
     61 		-vn -c copy \
     62 		"${ofile}" &&
     63 	echo "Tagging \"${title}\"..." &&
     64 	tag \
     65 		-a "${author}" \
     66 		-A "${album}" \
     67 		-t "${title}" \
     68 		-n "${track}" \
     69 		-N "${total}" \
     70 		-d "${year}" \
     71 		"${ofile}"
     72 }
     73 
     74 main "${@}"