Mat's Playground

cd.makeOgg

Description

This script rips all tracks from an audio CD into the current directory. It encodes them to ogg files on-the-fly, so it's slighty faster than first creating wav files and encoding those.

By default, it will use the CD from /dev/cdrom. If you want to rip from another device, you need to change the line set device "..." at the top of the script.

Before ripping, the script will create a file called "index". This file is used by the music.* scripts for batch-tagging of the files. Have a look there for a description of the format.

Don't expect any CDDB magic here, the 5 minutes this script needs for ripping an average CD should suffice to fill that file by hand.. :)

Required programs

Download

Source code

Hide line numbers Expand lines
  1#!/bin/sh
  2# the next line restarts using tclsh \
  3exec tclsh "$0" "$@"
  4
  5
  6#
  7# needed programs:
  8#  cdparanoia
  9#  cdp
 10#  oggenc
 11#
 12
 13
 14#
 15# read from which device
 16#
 17set device "/dev/cdrom"
 18
 19
 20# when did we start?
 21#
 22set started [clock seconds]
 23
 24
 25#
 26# how many tracks to extract?
 27#
 28set lines [exec cdp -c $device table]
 29set lines [split $lines \n]
 30
 31# first 5 lines are not relevant
 32set lines [lreplace $lines 0 4]
 33
 34set processTracks {}
 35foreach line $lines {
 36    # remove all asterisks from line
 37    regsub -all {\*} $line "" line
 38
 39    # remove all whitespaces
 40    set line [string trim $line]
 41
 42    set nr    [lindex [split $line] 0]
 43    set title [string range $line end-9 end] ;# this is only the last part of the title
 44
 45    if {[string is integer $nr] && $title != "DATA TRACK"} then {
 46        if {$nr < 10} then {set nr "0$nr"}
 47        lappend processTracks $nr
 48    }
 49
 50    unset line nr title
 51}
 52unset lines
 53
 54#
 55# creating index document
 56#
 57
 58if {![file exists index]} then {
 59    puts "Creating index document.."
 60    set fd [open index w+]
 61    puts $fd "Artist: "
 62    puts $fd "Title:  "
 63    puts $fd "Genre:  "
 64    puts $fd "Year:   "
 65    puts $fd ""
 66
 67    foreach nr $processTracks {
 68        puts $fd "$nr: "
 69        unset nr
 70    }
 71    close $fd
 72    unset fd
 73}
 74
 75
 76
 77#
 78# now extract the tracks
 79#
 80foreach nr $processTracks {
 81    set nr_begin [clock seconds]
 82
 83    puts "Extracting track $nr.."
 84
 85    # - is the file argument and means stdout
 86    exec cdparanoia -d $device --quiet $nr - | oggenc --quiet --quality 6 --output=track$nr.cdda.ogg -
 87
 88    unset nr nr_begin
 89}
 90
 91unset processTracks
 92
 93
 94
 95#
 96# how long did it take?
 97#
 98set duration [expr [clock seconds] - $started]
 99
100set mm [expr $duration / 60]
101set ss [expr $duration % 60]
102
103if {$mm < 10} then {set mm "0$mm"}
104if {$ss < 10} then {set ss "0$ss"}
105
106puts "Time elapsed: $mm:$ss"
107unset started duration mm ss
108
109
110exit