Instantly share code, notes, and snippets.

Embed
What would you like to do?
Workflow for the encoding of AudioCDs
#!/usr/bin/env bash
# This script is published under
#
# The MIT License (MIT)
#
# Copyright (c) 2016 Lukas Kallies
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
musicdir=${1-"~/Music/read_audiocd"}
export PATH="/bin:/usr/bin"
export LC_ALL=C
WAITSECONDS=${WAITSECONDS-15}
# FILETYPE, man(1) abcde:
# "vorbis" (or "ogg"), "mp3", "flac", "spx", "mpc", "m4a", "wav" or "opus"
FILETYPE=${FILETYPE-"mp3"}
# Number of encoders, man(1) abcde
# Start [number] encoder processes at once. Useful for SMP systems.
ENCODERS=${ENCODERS-4}
# Other abcde options
ABCDEOPTIONS=${ABCDEOPTIONS-"-p"}
cd ${musicdir}
# read data from sr0 device
#gvfs-info -f cdda://sr0
# check if fssize of disk in sr0 is greater 0
#test ${fssize} -gt 0 && echo ok
# iterate endless
# check if there is a cd every $WAITSECONDS
# if yes, use abcde for encoding and eject (-x) disk afterwards
while [ true ]; do
fssize=0
while [ ${fssize} -eq 0 ]; do
fssize=$(gvfs-info -f cdda://sr0 -a filesystem::size || echo 0)
sleep ${WAITSECONDS}; echo waiting
done
abcde -o ${FILETYPE} -j ${ENCODERS} ${ABCDEOPTIONS} -x -N
# use eject for debugging (so we don't have to do real encoding)
#eject
# if there is no cddb info move the created folder so next cd will not overwrite content
test -e Unknown_Artist-Unknown_Album && mv Unknown_Artist-Unknown_Album{,$(date +%Y%m%d%H%M)}
done
exit 0
@kallies

This comment has been minimized.

Owner

kallies commented Aug 13, 2016

Read Audio-CD (bash, Gnome Virtual File System, abcde)

My father in law bought a new car. Because the vendor doesn't ship an audio CD drive anymore but an usb interface he asked us to encode "some" of his favorite CDs so he can listen to them. Encoding one CD took some time and I had to start the encoding process manually. So I wrote a simple (really simple, no command line options, no interrupt criteria and so one) to automate this process:

  1. open CD drive
  2. start script
  3. put in audio CD
  4. close CD drive
  5. wait until CD drive opens again
  6. continue with the third step

As soon as all CDs are encoded, hit ^C (CTRL+C) and close the CD tray.

Developed and tested on

  • Debian GNU/Linux 8.5 (jessie)
  • Gnome 3.14
  • bash 4.3.30
  • abcde 2.6

Limitations

Known limitations are:

  • Works only in Gnome
  • Doesn't work when screen is locked or inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment