Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

pneumatic
Friday, October 7th, 2005 at 10:58:39am UTC 

  1. #!/bin/sh
  2. sum() {
  3.     F=$(($FI+$FL)); FF=$(($F%75)) # frames
  4.     S=$(($SI+$SL)); SS=$(($S%60+$F/75)); [ $SS -ge 60 ] && S=$SS # seconds
  5.     M=$(($MI+$ML)); MM=$(($M+$S/60)) # minutes
  6.     SS="${SS/60/00}"; FF="${FF/75/00}"
  7. }
  8. leadzero() {
  9.     [ ${#MM} -lt 2 ] && MM=0$MM; [ ${#SS} -lt 2 ] && SS=0$SS; [ ${#FF} -lt 2 ] && FF=0$FF
  10. }
  11.  
  12. if [ -z "$1" ]; then
  13.     echo "Usage: $0 <cuesheet.cue>"
  14. else
  15.     sed '/\<REM\> /d; /./!d' "$1" | dos2unix > TMP.CUE # clean comments and blank lines
  16.  
  17.     IDX=$(shntool len "`grep -m 1 FILE TMP.CUE | cut -d'"' -f2`" | tail -n2 | head -n1 |
  18.         sed 's/^[ ]*//; s/ .*//; s/\./:/')
  19.     [ ${#IDX} -lt 9 ] && IDX=0$IDX
  20.  
  21.     # process first two tracks
  22.     grep -B100 "TRACK 02" TMP.CUE | sed '/FILE/d' | head -n-1 > NEW.CUE # start new cue
  23.     sed -n '/TRACK 02/,/TRACK 03/p' TMP.CUE | sed "s/\(.*INDEX 01 \).*/\1$IDX/; /FILE /d" | head -n-1 >> NEW.CUE
  24.  
  25.     # collect some data: 'INDEX 00' of track XX -> I[XX], length of track XX -> L[XX]
  26.     NT=`grep TRACK TMP.CUE | tail -n1 | sed 's:[^0-9]::g'` # number of tracks
  27.  
  28.     C=1
  29.     while [ $C -le $NT ]; do
  30.         CN=$(($C+1))
  31.         # extract range of cuesheet for current track
  32.         sed -n "/TRACK `[ ${#C} -lt 2 ] && echo 0$C || echo $C`/,/TRACK `[ ${#CN} -lt 2 ] && echo 0$CN || echo $CN`/p" \
  33.             TMP.CUE > RANGE
  34.         if grep -q "INDEX 00" RANGE; then
  35.             I[$C]=$(echo `grep "INDEX 00" RANGE | sed 's/.* 00 //; s/:0/:/g; s/^0//'`) # index 00
  36.         fi
  37.         # get length of referenced file
  38.         FILE=`grep -m $C FILE TMP.CUE | tail -n1 | cut -d'"' -f2`
  39.         L[$C]=$(shntool len "$FILE" | tail -n2 | head -n1 | sed 's/^[ ]*//; s/ .*//; s/\./:/; s/:0/:/g')
  40.         C=$CN
  41.     done
  42.  
  43.     # process tracks from No.3
  44.     C=3
  45.     while [ $C -le $NT ]; do
  46.         CP=$(($C-1)); CN=$(($C+1))
  47.         ML=`echo ${IDX/#0} | cut -d: -f1`; SL=`echo ${IDX/#0} | cut -d: -f2`; FL=`echo ${IDX/#0} | cut -d: -f3`
  48.         # if 'INDEX 00' presented, calculate its absolute position
  49.         if [ -n "${I[$C]}" ]; then
  50.             MI=`echo ${I[$C]} | cut -d: -f1`; SI=`echo ${I[$C]} | cut -d: -f2`; FI=`echo ${I[$C]} | cut -d: -f3`
  51.             sum
  52.             leadzero
  53.             IDX0="$MM:$SS:$FF"
  54.         fi
  55.         # calculate abs pos of 'INDEX 01'
  56.         MI=`echo ${L[$CP]} | cut -d: -f1`; SI=`echo ${L[$CP]} | cut -d: -f2`; FI=`echo ${L[$CP]} | cut -d: -f3`
  57.         sum
  58.         IDX="$MM:$SS:$FF"
  59.         leadzero
  60.         IDX1="$MM:$SS:$FF"
  61.         # replace indeces and append modified range to new cue
  62.         sed -n "/TRACK `[ ${#C} -lt 2 ] && echo 0$C || echo $C`/,/TRACK `[ ${#CN} -lt 2 ] && echo 0$CN || echo $CN`/p" \
  63.             TMP.CUE | head -n-1 | sed "s/\(.*INDEX 00 \).*/\1$IDX0/; s/\(.*INDEX 01 \).*/\1$IDX1/; /FILE/d" >> \
  64.             NEW.CUE
  65.         IDX0=""
  66.         C=$CN
  67.     done
  68.  
  69.     # process last track
  70.     ML=`echo ${IDX/#0} | cut -d: -f1`; SL=`echo ${IDX/#0} | cut -d: -f2`; FL=`echo ${IDX/#0} | cut -d: -f3`
  71.     MI=`echo ${L[$NT]} | cut -d: -f1`; SI=`echo ${L[$NT]} | cut -d: -f2`; FI=`echo ${L[$NT]} | cut -d: -f3`
  72.     leadzero
  73.     tail -n1 TMP.CUE | sed "s/\(.*INDEX 01 \).*/\1$MM:$SS:$FF/" >> NEW.CUE # finish new cue
  74.  
  75.     echo FILE "joined.wav" WAVE > joined.cue
  76.     cat NEW.CUE >> joined.cue
  77.  
  78.     rm -f {TMP,NEW}.CUE RANGE # clean junk
  79. fi

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right