Slicing an MP3 Based on Marks in the Metadata

Notes: Installing ExifTool – You need sudo yum install perl-ExtUtils-MakeMaker before the Install instructions work for http://www.sno.phy.queensu.ca/~phil/exiftool/install.html

I first decided to use exiftool to find the data I needed:

exiftool -UserDefinedText -a filename.mp3 [where -UserDefinedText is the specific metat field and -a shows all of the fields]

User Defined Text               : (DDJ/VER) 0100
User Defined Text               : (DDJ/MK01) 885324
User Defined Text               : (DDJ/MK02) 1956684

exiftool -UserDefinedText -a filename.mp3 | grep -oP ‘\d+\D+\K\d+’

Extracts the data, uses grep to pull both numbers.

Since I want them separate I add a second grep (might be a better way).

exiftool -UserDefinedText -a $file | grep MK01 | grep -oP ‘\d+\D+\K\d+

Here’s the script test file

#!/bin/bash -x

file=’/home/jimusik/mp3/06152014094419_DN-700R1.mp3′

mk1=`/usr/local/bin/exiftool -UserDefinedText -a $file | grep MK01 | grep -oP ‘\d+\D+\K\d+’`

mk2=`/usr/local/bin/exiftool -UserDefinedText -a $file | grep MK02 | grep -oP ‘\d+\D+\K\d+’`

/* calculate start */

totsecs1=`echo $mk1 / 900.037 | bc`

min1=`echo $totsecs1 / 60 | bc`

sec1=`echo “$totsecs1 – ($min1 * 60)” | bc`

totsecs1=`echo “scale=2; $mk1 / 900.037” | bc`

hund1=`echo “$totsecs1 – ($min1 * 60) – $sec1” | bc`

hun1=`echo “scale=0; $hund1 * 100/1” | bc`

start=`echo $min1″.”$sec1″.”$hun1`

/* calculate end */

totsecs2=`echo $mk2 / 900.037 | bc`

min2=`echo $totsecs2 / 60 | bc`

sec2=`echo “$totsecs2 – ($min2 * 60)” | bc`

totsecs2=`echo “scale=2; $mk2 / 900.037” | bc`

hund2=`echo “$totsecs2 – ($min2 * 60) – $sec2” | bc`

hun2=`echo “scale=0; $hund2 * 100/1” | bc`

end=`echo $min2″.”$sec2″.”$hun2`

echo $start” “$end

/* Split the file */

 

mp3splt $file $start $endmp3