scripts

random scripts
git clone https://git.parazyd.org/scripts
Log | Files | Refs

cuesplit.sh (1110B)


      1 #!/bin/sh
      2 #dependencies: cuetools, shntool, flac
      3 
      4 if [ $# -ne 2 ] || [ "$1" = "-h" ]
      5 then
      6 	printf "Usage: %s image cue\n" "$0"
      7 	exit 1
      8 fi
      9 
     10 MUSIC_DIR="$HOME/Data/Music"
     11 ARTIST="$(tr -d '\r' < "$2" | grep -F PERFORMER | head -n 1 | sed -e 's#.*"\(.*\)"#\1#' -e 's#/#_#g')"
     12 ALBUM="$(tr -d '\r' < "$2" | grep -F TITLE | head -n 1 | sed  -e 's#.*"\(.*\)"#\1#' -e 's#/#_#g')"
     13 DATE="$(tr -d '\r' < "$2" | grep -F 'REM DATE' | head -n 1 | cut -d ' ' -f 3)"
     14 
     15 split()
     16 {
     17 	mkdir -p split
     18 	shnsplit -d split -f "$2" -o "flac flac -V -8 -o %f -" "$1" -t "%n - %t"
     19 	rm -- split/00*pregap*
     20 }
     21 
     22 tag()
     23 {
     24 	cuetag.sh "$1" split/*.flac
     25 	# add the date tag since cuetag can't do it
     26 	if [ -n "$DATE" ]
     27 	then
     28 		metaflac --set-tag="date=$DATE" split/*.flac
     29 	fi
     30 	printf 'Calculating replay gain values...'
     31 	metaflac --add-replay-gain split/*.flac
     32 }
     33 
     34 movedir()
     35 {
     36 	printf 'Move split/ to "%s/%s/(%s) %s"? y/n' "$MUSIC_DIR" "$ARTIST" "$DATE" "$ALBUM"
     37 	read -r CHOICE
     38 	if [ "$CHOICE" = "y" ]
     39 	then
     40 		mkdir -p -- "$MUSIC_DIR/$ARTIST/($DATE) $ALBUM"
     41 		mv -T -- split "$MUSIC_DIR/$ARTIST/($DATE) $ALBUM"
     42 	fi
     43 }
     44 
     45 split "$1" "$2"
     46 tag "$2"
     47 movedir