dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

asplit (1679B)


      1 #!/bin/sh
      2 
      3 [ -z $1 ] || [ "$1" = "-h" ] && echo "usage: asplit <input file>
      4 
      5 Takes a TSV format as stdin:
      6 starttime	endtime	title	author	track	album	comment
      7 
      8 Leave track as '-', if it is N/A" && exit 1
      9 
     10 arith(){
     11 	printf '%s\n' "$*" | bc
     12 }
     13 
     14 # status bar at the bottom of the screen (like apt)
     15 status_init(){
     16 	printf '\n'
     17 	tput sc
     18 	printf '\033[0;%dr' $(calc "$(tput lines) - 1")
     19 	tput rc
     20 	tput cuu 1
     21 }
     22 
     23 status_write(){
     24 	status_write_colour="$1"
     25 	status_write_format="$2"
     26 	shift 2
     27 
     28 	tput sc
     29 	tput cup $(tput lines) 0
     30 	tput setaf "$status_write_colour"
     31 	tput rev
     32 	tput el
     33 	printf " $status_write_format " "$@"
     34 	tput cup $(tput lines) $(tput cols)
     35 	tput sgr0
     36 	tput rc
     37 }
     38 
     39 status_deinit(){
     40 	tput sc
     41 	printf '\033[0;%dr' $(tput lines)
     42 	tput cup $(tput lines) 0
     43 	tput el
     44 	tput rc
     45 	printf '\n'
     46 }
     47 
     48 trap 'status_deinit' 2 # SIGINT
     49 
     50 get(){
     51 	echo "$line" | awk -v "n=$1" -F"	" '{print $n}' | sed 's/\\n/\n/g;s/\\t/\t/g'
     52 }
     53 
     54 format=${1##*.}
     55 
     56 status_init
     57 while IFS= read -r line
     58 do
     59 	status_write 28 "Splitting %s..." "$(get 3)"
     60 	get 5 | grep '[0-9]' >/dev/null && 
     61 		ffmpeg -y -nostdin -i "$1" \
     62 			-ss "$(get 1)" -to "$(get 2)" \
     63 			-map_metadata -1 -c copy \
     64 			-metadata "title=$(get 3)" \
     65 			-metadata "artist=$(get 4)" \
     66 			-metadata "track=$(get 5)" \
     67 			-metadata "album=$(get 6)" \
     68 			-metadata "comment=$(get 7)" \
     69 			"$(get 5).-.$(get 3 | tr '/ 	' '_..').$format" || 
     70 		ffmpeg -y -nostdin -i "$1" \
     71 			-ss "$(get 1)" -to "$(get 2)" \
     72 			-map_metadata -1 -c copy \
     73 			-metadata "title=$(get 3)" \
     74 			-metadata "artist=$(get 4)" \
     75 			-metadata "album=$(get 6)" \
     76 			-metadata "comment=$(get 7)" \
     77 			"$(get 3 | tr '/ 	' '_..').$format"
     78 	status_write 238 "Waiting..."
     79 done
     80 
     81 status_deinit