Difference between revisions of "Audiograb script"

From Maze's wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
<pre>
 
<pre>
#!/bin/sh
+
#!/bin/bash
cdinfo=`cd-discid /dev/cdrom1`
+
cdinfo=`cd-discid /dev/sr0`
cddbcdsummary=`cddbcmd -m http cddb query $cdinfo`
+
discid=`echo "${cdinfo}" | cut -d\  -f 1`
nofcddbcdsummaries=`echo "$cddbcdsummary" | wc -l`
+
noftracks=`echo "${cdinfo}" | cut -d\  -f 2`
 +
cdinfocddb=`echo ${cdinfo} | sed 's/ /+/g'`
 +
cddbcdsummaries=`wget "http://freedb.freedb.org/~cddb/cddb.cgi?cmd=cddb+query+${cdinfocddb}&hello=maze+ma-ze.nl+grab.sh+1.0&proto=6" -O - -q | tail -n +2 | head -n -1`
 +
nofcddbcdsummaries=`echo "${cddbcdsummaries}" | wc -l`
 
chosensummary=1
 
chosensummary=1
[ "$nofcddbcdsummaries" -ne "1" ] && echo "$cddbcdsummary" | nl && read -p "Select correct CD [1]:" chosensummarycustom
+
[ "${nofcddbcdsummaries}" -ne "1" ] && echo "${cddbcdsummaries}" | nl && read -p "Select correct CD [1]:" chosensummarycustom
[ "$chosensummarycustom" != "" ] && chosensummary=$chosensummarycustom
+
[ "${chosensummarycustom}" != "" ] && chosensummary=${chosensummarycustom}
cddbcdsummary=`echo "$cddbcdsummary" | head -n $chosensummary | tail -n 1 | cut -d\  -f -2`
+
cddbcdsummary=`echo "${cddbcdsummaries}" | head -n ${chosensummary} | tail -n 1 | cut -d\  -f -2 | sed 's/ /+/g'`
cddbcdfullinfo=`cddbcmd -m http cddb read $cddbcdsummary`
+
cddbcdfullinfo=`wget "http://freedb.freedb.org/~cddb/cddb.cgi?cmd=cddb+read+${cddbcdsummary}&hello=maze+ma-ze.nl+grab.sh+1.0&proto=6" -O - -q`
noftracks=`echo "$cddbcdfullinfo" | grep 'TTITLE' | cut -d= -f 1 | sort -u | wc -l`
+
[ "${noftracks}" -lt "10" ] && noftrackslz=0
[ "$noftracks" -lt "10" ] && noftrackslz=0
+
artistname=`echo "${cddbcdfullinfo}" | grep 'DTITLE' | tr -d "\r" | tr -d "\n" | sed 's/DTITLE=//g' | cut -d/ -f 1 | sed 's/^\ *//' | sed 's/\ *$//'`
artistname=`echo "$cddbcdfullinfo" | grep 'DTITLE' | tr -d "\n" | sed 's/DTITLE=//g' | cut -d/ -f 1 | sed 's/^\ *//' | sed 's/\ *$//'`
+
albumname=`echo "${cddbcdfullinfo}" | grep 'DTITLE' | tr -d "\r" | tr -d "\n" | sed 's/DTITLE=//g' | cut -d/ -f 2- | sed 's/^\ *//' | sed 's/\ *$//'`
albumname=`echo "$cddbcdfullinfo" | grep 'DTITLE' | tr -d "\n" | sed 's/DTITLE=//g' | cut -d/ -f 2- | sed 's/^\ *//' | sed 's/\ *$//'`
 
  
read -p "Enter Artist [$artistname]:" artistnamecustom
+
read -p "Enter Artist [${artistname}]:" artistnamecustom
[ "$artistnamecustom" != "" ] && artistname=$artistnamecustom
+
[ "${artistnamecustom}" != "" ] && artistname=${artistnamecustom}
read -p "Enter Albumname [$albumname]:" albumnamecustom
+
read -p "Enter Albumname [${albumname}]:" albumnamecustom
[ "$albumnamecustom" != "" ] && albumname=$albumnamecustom
+
[ "${albumnamecustom}" != "" ] && albumname=${albumnamecustom}
read -p "Enter Genre [$genre]:" genrecustom
+
read -p "Enter Genre [${genre}]:" genrecustom
[ "$genrecustom" != "" ] && genre=$genrecustom
+
[ "${genrecustom}" != "" ] && genre=${genrecustom}
read -p "Enter Year [$year]:" yearcustom
+
read -p "Enter Year [${year}]:" yearcustom
[ "$yearcustom" != "" ] && year=$yearcustom
+
[ "${yearcustom}" != "" ] && year=${yearcustom}
mkdir -p "$artistname"/"$albumname"
+
mkdir -p "${artistname}"/"${albumname}"
  
 
track=0
 
track=0
while [ "$track" -lt "$noftracks" ]
+
while [ "${track}" -lt "${noftracks}" ]
 
do
 
do
  actualtrack=$(($track+1))
 
 
   leadingzero=""
 
   leadingzero=""
   [ "$actualtrack" -lt "10" ] && leadingzero=0
+
   [ "${track}" -lt "9" ] && leadingzero=0
   trackname=`echo "$cddbcdfullinfo" | grep 'TTITLE'$track'=' | tr -d "\n" | sed 's/TTITLE[0-9]*=//' | sed 's/^\ *//' | sed 's/\ *$//'`
+
   trackname=`echo "${cddbcdfullinfo}" | grep 'TTITLE'${track}'=' | tr -d "\r" | tr -d "\n" | sed 's/TTITLE[0-9]*=//' | sed 's/^\ *//' | sed 's/\ *$//'`
   read -p "Enter title for track $leadingzero$actualtrack [$trackname]:" tracknamecustom
+
   read -p "Enter title for track $leadingzero$(($track+1)) [${trackname}]:" tracknamecustom
   [ "$tracknamecustom" != "" ] && trackname=$tracknamecustom
+
   [ "${tracknamecustom}" != "" ] && trackname=${tracknamecustom}
   trackfilename=`echo "$trackname" | sed 's/\//_/g'`
+
  tracks[${track}]=${trackname}
   icedax -q -D /dev/cdrom1 -O wav -t $actualtrack - | lame --preset standard --quiet --tt "$trackname" --tg "$genre" --ta "$artistname" --tl "$albumname" --ty "$year" --tn "$leadingzero$actualtrack/$noftrackslz$noftracks" --id3v2-only - "$artistname/$albumname/$leadingzero$actualtrack-$trackfilename.mp3"
+
  track=$((${track}+1))
   track=$(($track+1))
+
done
 +
 
 +
track=0
 +
while [ "${track}" -lt "${#tracks[@]}" ]
 +
do
 +
  leadingzero=""
 +
  [ "${track}" -lt "9" ] && leadingzero=0
 +
   trackfilename=`echo "${tracks[$track]}" | sed 's/\//_/g'`
 +
   icedax -q -D /dev/sr0 -O wav -t $((${track}+1)) - | oggenc -q 5 -Q -t "${tracks[$track]}" -G "${genre}" -a "${artistname}" -l "${albumname}" -d "${year}" -N "${leadingzero}$((${track}+1))/${noftrackslz}${noftracks}" -o "$artistname/$albumname/$leadingzero$(($track+1))-$trackfilename.ogg" -
 +
   track=$((${track}+1))
 
done
 
done
 
</pre>
 
</pre>

Latest revision as of 06:48, 11 September 2012

For this audiograb script to run you need some packages to be installed:

  • cd-discid
  • icedax
  • vorbis-tools
#!/bin/bash
cdinfo=`cd-discid /dev/sr0`
discid=`echo "${cdinfo}" | cut -d\  -f 1`
noftracks=`echo "${cdinfo}" | cut -d\  -f 2`
cdinfocddb=`echo ${cdinfo} | sed 's/ /+/g'`
cddbcdsummaries=`wget "http://freedb.freedb.org/~cddb/cddb.cgi?cmd=cddb+query+${cdinfocddb}&hello=maze+ma-ze.nl+grab.sh+1.0&proto=6" -O - -q | tail -n +2 | head -n -1`
nofcddbcdsummaries=`echo "${cddbcdsummaries}" | wc -l`
chosensummary=1
[ "${nofcddbcdsummaries}" -ne "1" ] && echo "${cddbcdsummaries}" | nl && read -p "Select correct CD [1]:" chosensummarycustom
[ "${chosensummarycustom}" != "" ] && chosensummary=${chosensummarycustom}
cddbcdsummary=`echo "${cddbcdsummaries}" | head -n ${chosensummary} | tail -n 1 | cut -d\  -f -2 | sed 's/ /+/g'`
cddbcdfullinfo=`wget "http://freedb.freedb.org/~cddb/cddb.cgi?cmd=cddb+read+${cddbcdsummary}&hello=maze+ma-ze.nl+grab.sh+1.0&proto=6" -O - -q`
[ "${noftracks}" -lt "10" ] && noftrackslz=0
artistname=`echo "${cddbcdfullinfo}" | grep 'DTITLE' | tr -d "\r" | tr -d "\n" | sed 's/DTITLE=//g' | cut -d/ -f 1 | sed 's/^\ *//' | sed 's/\ *$//'`
albumname=`echo "${cddbcdfullinfo}" | grep 'DTITLE' | tr -d "\r" | tr -d "\n" | sed 's/DTITLE=//g' | cut -d/ -f 2- | sed 's/^\ *//' | sed 's/\ *$//'`

read -p "Enter Artist [${artistname}]:" artistnamecustom
[ "${artistnamecustom}" != "" ] && artistname=${artistnamecustom}
read -p "Enter Albumname [${albumname}]:" albumnamecustom
[ "${albumnamecustom}" != "" ] && albumname=${albumnamecustom}
read -p "Enter Genre [${genre}]:" genrecustom
[ "${genrecustom}" != "" ] && genre=${genrecustom}
read -p "Enter Year [${year}]:" yearcustom
[ "${yearcustom}" != "" ] && year=${yearcustom}
mkdir -p "${artistname}"/"${albumname}"

track=0
while [ "${track}" -lt "${noftracks}" ]
do
  leadingzero=""
  [ "${track}" -lt "9" ] && leadingzero=0
  trackname=`echo "${cddbcdfullinfo}" | grep 'TTITLE'${track}'=' | tr -d "\r" | tr -d "\n" | sed 's/TTITLE[0-9]*=//' | sed 's/^\ *//' | sed 's/\ *$//'`
  read -p "Enter title for track $leadingzero$(($track+1)) [${trackname}]:" tracknamecustom
  [ "${tracknamecustom}" != "" ] && trackname=${tracknamecustom}
  tracks[${track}]=${trackname}
  track=$((${track}+1))
done

track=0
while [ "${track}" -lt "${#tracks[@]}" ]
do
  leadingzero=""
  [ "${track}" -lt "9" ] && leadingzero=0
  trackfilename=`echo "${tracks[$track]}" | sed 's/\//_/g'`
  icedax -q -D /dev/sr0 -O wav -t $((${track}+1)) - | oggenc -q 5 -Q -t "${tracks[$track]}" -G "${genre}" -a "${artistname}" -l "${albumname}" -d "${year}" -N "${leadingzero}$((${track}+1))/${noftrackslz}${noftracks}" -o "$artistname/$albumname/$leadingzero$(($track+1))-$trackfilename.ogg" -
  track=$((${track}+1))
done