Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Bash / PowerShell – Rip Sermon Audio From CD

Posted on January 1, 2019April 9, 2023 By David Kittell

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.

Related

Code Mac OS X Shell Mac OSX PowerShell UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

CSharp – Random Password Generator

Posted on May 7, 2014April 9, 2019

Sometimes it’s helpful to simply have a random password. In this small group of code you can define what parameters to use, I have taken the liberty to remove some of the characters that are usually mistaken for a different character like an upper case I and the number 1….

Read More

PowerShell – Get/Set Windows Date/Time from NTP

Posted on December 3, 2015February 12, 2016

Sometimes w32Time is not available or practical so we get this PowerShell script to pull NTP date/time and set the Windows Date/Time GitHub: https://gist.github.com/dkittell/56f957c850f1064cbea0 Reference: chrisjwarwick.wordpress.com Originally Posted on December 3, 2015Last Updated on February 12, 2016 All information on this site is shared with the intention to help. Before…

Read More

Validate Links

Posted on August 15, 2013October 26, 2015

Example

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes