Bash / PowerShell – Rip Sermon Audio From CD

| | | | |

To expand on an earlier post “MacPorts / HomeBrew – Rip CD tracks from terminal” I have worked on two scripts; one for Mac and one for PC.

Both scripts (Bash and PowerShell) will run similar with predefined values that you’ll need to update for your own purposes (look at the highlighted lines).

First script is a Bash script specific for Mac OSX

#!/bin/sh

#  Sermon.sh
#
#
#  Created by David Kittell on 12/30/18.
#

# Install HomeBrew
#/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# Install HomeBrew Packages
#brew install cdparanoia lame sox
#sudo port install cdparanoia lame sox

# Variables - Start
SermonDate=$1
if [ -z $SermonDate ]; then
  dateFile=`date +%Y_%m_%d`
  dateTitle=$(echo $dateFile | sed "s|_|-|g")
else
  dateFile=$(echo $SermonDate | sed "s|-|_|g")
  dateTitle=$SermonDate
fi

artist=$2
if [ -z $artist ]; then
  artist="Greg Capsel"
fi

SermonsPath="/Users/dkittell/Desktop/Sermons"
album="Millington Church of God"
genre="Sermon"
trackimage="$SermonsPath/sermon.jpg"
comment="http://www.millingtonchurchofgod.com"
# Variables - Stop

# Display Output
echo "Extraction of audio from CD starting for $dateTitle"

# Extract Audio From CD
cdparanoia -B

# Eject CD
drutil eject

# Convert Wav To MP3
lame -b 64 track01.cdda.wav -o "Sermon_$dateFile.mp3" --ty "$year" --tl "$album" --ta "$artist" --tc "$comment" --tg "$genre" --tt "$dateTitle" --ti "$trackimage"

# Remove The Wav File
rm track01.cdda.wav
# Run for current date
sh Sermon.sh

# Run for specific date
sh Sermon.sh 2018-12-25

# Run for specific date and Artist/Speaker
sh Sermon.sh 2018-12-25 "Greg Capsel"

Second script is a PowerShell script specific for a Windows based computer

param
(
  [datetime]$year = (Get-Date).year,
  [datetime]$SermonDate = (Get-Date),
  [string]$artist = "Greg Capsel"
)
$SermonDate

#choco uninstall eac -y
#choco install eac -y
#choco install cdex -y
#choco install lame -y

$dateFile = $SermonDate.ToString("yyyy_MM_dd")
$dateTitle = $SermonDate.ToString("yyyy-MM-dd")

$DesktopPath = [Environment]::GetFolderPath("Desktop")
$EACPath = "C:\Program Files (x86)\Exact Audio Copy"
#$CDEXPath = "C:\Program Files (x86)\CDex\"
$LAMEPath = "C:\ProgramData\chocolatey\lib\lame\tools\"

$album = "Millington Church of God"
$genre = "Sermon"
$trackimage = "$DesktopPath\Sermons\sermon.jpg"
$comment = "http://www.millingtonchurchofgod.com"

Set-Location "$EACPath"
.\EAC.exe

#cd "$CDEXPath"
#.\CDex.exe

function Pause ()
{
  # Check if running Powershell ISE
  if ($psISE)
  {
    Add-Type -AssemblyName System.Windows.Forms
    $message = "Press the WAV button on the left side of EAC`n`nPlease click the OK button to continue"
    [System.Windows.Forms.MessageBox]::Show("$message")
  }
  else
  {
    $message = "Press the WAV button on the left side of EAC`n`nPlease any key to continue"
    Write-Host "$message" -ForegroundColor Yellow
    $x = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  }
}

Pause

Get-Process EAC | ForEach-Object { $_.CloseMainWindow() | Out-Null } | Stop-Process –force

Set-Location $LAMEPath

.\lame.exe -b 64 """$DesktopPath\Sermons\*.wav""" -o """$DesktopPath\Sermons\Sermon_$(echo $dateFile).mp3""" --ty $year --tl "$album" --ta "$artist" --tc "$comment" --tg $genre --tt $dateTitle --ti $trackimage

Set-Location "$DesktopPath\Sermons"

try {
  $Diskmaster = New-Object -ComObject IMAPI2.MsftDiscMaster2
  $DiskRecorder = New-Object -ComObject IMAPI2.MsftDiscRecorder2
  $DiskRecorder.InitializeDiscRecorder($DiskMaster)
  $DiskRecorder.EjectMedia()
} catch {
  Write-Error "Failed to operate the disk. Details : $_"
}

rm *.wav
# Run for current date
.\Sermon.ps1

# Run for specific date
.\Sermon.ps1 -SermonDate 2018-12-25

# Run for specific date and Artist/Speaker
.\Sermon.ps1 -SermonDate 2018-12-25 -artist "Greg Capsel"

Originally Posted on January 1, 2019
Last Updated on April 9, 2023
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.