scripts

Random scripts
git clone git://git.margiolis.net/scripts.git
Log | Files | Refs | README | LICENSE

ausplit (1425B)


      1 #!/bin/sh
      2 
      3 # ffmpeg and my `tag` script required.
      4 main()
      5 {
      6 	test ${#} -ne 2 && usage
      7 
      8 	local tfile="${2}"
      9 
     10 	auin="${1}"
     11 	total="$(wc -l < "${tfile}" | awk '{print $1}')"
     12 	ext="${1#*.}"
     13 
     14 	read -erp "Album/book title: " album
     15 	read -erp "Artist/author: " author
     16 	read -erp "Publication year: " year
     17 
     18 	albumdir="$(fmt_name "${album}")"
     19 	mkdir -p "${albumdir}" || 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' ' -f2-)"
     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
     37 	exit 1
     38 }
     39 
     40 fmt_name()
     41 {
     42 	echo "${1}" | iconv -cf UTF-8 -t ASCII//TRANSLIT |
     43 	tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' |
     44 	sed "s/-\+/-/g;s/\(^-\|-\$\)//g"
     45 }
     46 
     47 split_file()
     48 {
     49 	echo "From ${start} to ${end}; ${track} ${title}"
     50 	echo "Splitting \"${title}\"..."
     51 	ofile="${albumdir}/$(printf "%.2d" "${track}")-${titlefmt}.${ext}"
     52 	ffmpeg \
     53 		-nostdin -y -loglevel -8 \
     54 		-i "${auin}" \
     55 		-ss "${start}" \
     56 		`test ${track} -eq ${total} || echo "-to ${end}"` \
     57 		-vn -c copy \
     58 		-map 0 \
     59 		-metadata title="${title}" \
     60 		-metadata album="${album}" \
     61 		-metadata artist="${author}" \
     62 		-metadata track="${track}/${total}" \
     63 		-metadata date="${date}" \
     64 		"${ofile}"
     65 }
     66 
     67 main "${@}"