#!/usr/bin/perl -w use strict; use CDDB_get; use URI::Escape; =head1 NAME bentrip --- Bennett's ripper =head1 SYNOPSIS bentrip [cddbid [choice]] =head1 DESCRIPTION bentrip rips one CD into the current working subdirectory. The ripping is hardwired, cdparanoia with default options into oggenc --bitrate 160 (parameters, and indeed the idea and the way to do this all shamlessly stolen from Gregory J. Smethells' rip, as found at http://rip.sourceforge.net/). Details hardwired to Bennett's preferences. bentrip, unlike Gregory J. Smethells' rip, is completely and utterly non-interactive; it writes the best it can and fills in defaults for anything it can't find out. Aside from system permission problems and the ilke, it only bombs if CDDB_get::get_discids fails to produce a CDDB id and a count of tracks. If you can guess better than CDDB_get::get_discids (i.e. if there's some other freedb database entry you'd like to force it to use), provide it as a cmdline arg. And if there are multiple entries for the cddbid [look cddbif .freedb shows the choices] and bentrip gets the wrong one, specify which, as an array subscript (i.e. the first choice is 0, second choice is 1, etc.). =cut my $VERSION = "1.6"; my ($id, $total, $toc) = @{&CDDB_get::get_discids()}; die "CDDB_get::get_discids did not acquire cddb id" unless defined $id; die "Unknown number of tracks" unless defined $total; $id = sprintf "%x", $id; $id = shift if @ARGV; my (@recs) = `look $id $ENV{HOME}/.freedb`; my ($cddbid, $artist, $album, $genre, @track); if (@recs) { my $idx = 0; $idx = shift if @ARGV; $_ = $recs[$idx]; chomp; ($cddbid, $artist, $album, $genre, @track) = map { uri_unescape($_) } split /:/; die unless scalar(@track) >= $total; } else { $artist = "unknown artist $id"; $album = "unknown album $id"; $genre = "unknown genre $id"; @track = map { sprintf "track%3d", $_ } 1 .. $total; } my $artist_filename = $artist; $artist_filename =~ y/a-zA-Z0-9_-//cds; $artist_filename = $id unless length $artist_filename; -d $artist_filename or mkdir $artist_filename or die; my $album_filename = $album; $album_filename =~ y/a-zA-Z0-9_-//cds; $album_filename = $id unless length $album_filename; -d "$artist_filename/$album_filename" or mkdir "$artist_filename/$album_filename" or die; my ($year, $mon, $day) = (localtime(time))[5,4,3]; $year += 1900; $mon++; my $date = sprintf("$year-%02.2d-%02.2d", $mon, $day); $| = 1; track: for my $track (1 .. $total) { print "Ripping track $track of $total\n"; my $filename; $filename = $track[$track-1]; $filename =~ y/a-zA-Z0-9_-//cds; $filename = sprintf("$artist_filename/$album_filename/%03d-$filename.ogg", $track); if (-f $filename) { print "No I am not, it is already there\n"; next track; } pipe READER, WRITER or die; my $oggpid = fork; die unless defined $oggpid; if ($oggpid == 0) { close WRITER or die; open STDIN, "<&READER" or die; exec "oggenc", "-", "--bitrate", 160, "-t", $track[$track-1], "-a", $artist, "-l", $album, "-N", $track, "-c", "genre=$genre", "-c", "encode_date=$date", "-c", "cddb_id=$id", "-o", $filename; die "oggenc did not exec"; } my $cdparanoiapid = fork; die unless defined $cdparanoiapid; if ($cdparanoiapid == 0) { close READER or die; open STDOUT, ">&WRITER" or die; exec "cdparanoia", "-d", "/dev/cdrom", "-q", $track, "-"; die "cdparanoia did not exec"; } close READER or die; close WRITER or die; $SIG{INT} = sub { unlink $filename; die "interrupted, cleaned up $filename" }; my $waitpid = waitpid $oggpid, 0; unlink $filename and die "wacko waitpid ogg" unless $waitpid == $oggpid; unlink $filename and die "oggenc roached exit status $?" if $?; $waitpid = waitpid $cdparanoiapid, 0; unlink $filename and die "wacko waitpid cdparanoia" unless $waitpid == $cdparanoiapid; unlink $filename and die "cdparanoia roached exit status $?" if $?; $SIG{INT} = 'DEFAULT'; }