Index: gutenbach/debian/lib/README
===================================================================
--- gutenbach/debian/lib/README	(revision e5529cd368222ebd66d9ea94c39a52988ef9d657)
+++ gutenbach/debian/lib/README	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -1,18 +1,18 @@
-sipbmp3
+gutenbach
     The SIPB MP3 Music Spooler
 
 We would love you forever if you took this README/INSTALL document and made
 a Debian package out of it.  That would be uber-awesome.  But otherwise, we're
-assuming that you just want to get sipbmp3 up and running on your own
+assuming that you just want to get gutenbach up and running on your own
 system.  Well, maybe we shouldn't assume that.
 
 
-What does sipbmp3 do?
+What does gutenbach do?
 ---------------------
 
-sipbmp3 is a music spooler.  As it turns out, streaming music is a hard
+gutenbach is a music spooler.  As it turns out, streaming music is a hard
 problem, with lots of proprietary protocols, client and server software.
 All of these jiggety bits are kind of a pain to get working correctly,
-so, we built sipbmp3 on top of... a printer system.  It's very simple:
+so, we built gutenbach on top of... a printer system.  It's very simple:
 you print an mp3 file to a special "printer", and it gets played on
 whatever speakers you're hooked up to.
@@ -27,5 +27,5 @@
 
 
-Installing sipbmp3
+Installing gutenbach
 ------------------
 
@@ -33,5 +33,5 @@
 1. Configuring your sound
 
-If you're installing sipbmp3 on a server environment, it's highly likely
+If you're installing gutenbach on a server environment, it's highly likely
 that you have a bare bones audio setup and everything is muted.  Make sure
 your sound works!  One common problem is that the daemon user (the user which
@@ -48,5 +48,5 @@
 2. Install some prerequisite software
 
-On a vanilla Ubuntu server install, sipbmp3 will also need the following
+On a vanilla Ubuntu server install, gutenbach will also need the following
 packages to work properly:
 
@@ -57,21 +57,21 @@
 
 
-3. Setup sipbmp3
-
-The Git repository for sipbmp3 is located in:
-
-    /afs/sipb/project/sipbmp3/sipbmp3.git
-
-Place this in /root/sipbmp3; the remctl scripts will assume that the
+3. Setup gutenbach
+
+The Git repository for gutenbach is located in:
+
+    /afs/sipb/project/sipbmp3/gutenbach.git
+
+Place this in /root/gutenbach; the remctl scripts will assume that the
 scripts can be found in this location.
 
 
-4. Configure sipbmp3
-
-sipbmp3 will send zephyrs during playback start and end.  Since you don't
+4. Configure gutenbach
+
+gutenbach will send zephyrs during playback start and end.  Since you don't
 want to be spamming sipb-auto (which is the default zephyr class these
 are sent to), you should create a configuration file:
 
-    /etc/sipbmp3-filter-config.pl
+    /etc/gutenbach-filter-config.pl
 
 That looks like:
@@ -84,26 +84,26 @@
 
 
-5. Configure sipbmp3 init scripts
-
-sipbmp3 will attempt to drop some information into /var/run/sipbmp3, which
+5. Configure gutenbach init scripts
+
+gutenbach will attempt to drop some information into /var/run/gutenbach, which
 needs to exist and you can't simply mkdir since /var/run on Ubuntu is
-a tempfs. Thus, add the following lines to a new file, /etc/init.d/sipbmp3:
+a tempfs. Thus, add the following lines to a new file, /etc/init.d/gutenbach:
 
 #!/bin/sh
-mkdir /var/run/sipbmp3
-touch /var/run/sipbmp3/status
-chmod 0777 /var/run/sipbmp3/status
+mkdir /var/run/gutenbach
+touch /var/run/gutenbach/status
+chmod 0777 /var/run/gutenbach/status
 
 You should also run these commands yourself. :-)
 
-XXX: Note from jhamrick: I would recomment actually setting this up as a nice startup script, with a switch case for {start|stop|restart} (where with stop you just remove the directory, and with restart you remove the directory and then recreate it).  Also, sipbmp3 won't actually run on startup unless there are scripts in the /etc/rc*.d directory, so we need to do:
-
-> ln -s ../init.d/sipbmp3 /etc/rc2.d/S61sipbmp3
-> ln -s ../init.d/sipbmp3 /etc/rc3.d/S61sipbmp3
-> ln -s ../init.d/sipbmp3 /etc/rc4.d/S61sipbmp3
-> ln -s ../init.d/sipbmp3 /etc/rc5.d/S61sipbmp3
-> ln -s ../init.d/sipbmp3 /etc/rc0.d/K39sipbmp3
-> ln -s ../init.d/sipbmp3 /etc/rc1.d/K39sipbmp3
-> ln -s ../init.d/sipbmp3 /etc/rc6.d/K39sipbmp3
+XXX: Note from jhamrick: I would recomment actually setting this up as a nice startup script, with a switch case for {start|stop|restart} (where with stop you just remove the directory, and with restart you remove the directory and then recreate it).  Also, gutenbach won't actually run on startup unless there are scripts in the /etc/rc*.d directory, so we need to do:
+
+> ln -s ../init.d/gutenbach /etc/rc2.d/S61gutenbach
+> ln -s ../init.d/gutenbach /etc/rc3.d/S61gutenbach
+> ln -s ../init.d/gutenbach /etc/rc4.d/S61gutenbach
+> ln -s ../init.d/gutenbach /etc/rc5.d/S61gutenbach
+> ln -s ../init.d/gutenbach /etc/rc0.d/K39gutenbach
+> ln -s ../init.d/gutenbach /etc/rc1.d/K39gutenbach
+> ln -s ../init.d/gutenbach /etc/rc6.d/K39gutenbach
 
 XXX: We need better permissions for status. Also, quentin wants to put this
@@ -116,8 +116,8 @@
 running a printer! The magic lines are:
 
-    :if=|/path/to/sipbmp3-filter
+    :if=|/path/to/gutenbach-filter
     :lp=/dev/null
 
-Which mean that we pipe the mp3 files through sipbmp3-filter (which does
+Which mean that we pipe the mp3 files through gutenbach-filter (which does
 the actual playing), and then dump the rest of the output into /dev/null,
 since we don't actually care about it.
@@ -129,5 +129,5 @@
   :cm=Human Readable Printer Name
   :lp=/dev/null
-  :if=|/path/to/sipbmp3-filter
+  :if=|/path/to/gutenbach-filter
   :sd=/var/spool/lpd/printername
   :ml=0:mx=0:sh:sf
@@ -148,6 +148,6 @@
 in the future.
 
-WARNING: On a cluster machine, get_hesiod_pcap will clobber sipbmp3
-because it sets all:all=someotherprinter, making lpr not see sipbmp3.
+WARNING: On a cluster machine, get_hesiod_pcap will clobber gutenbach
+because it sets all:all=someotherprinter, making lpr not see gutenbach.
 There are two ways of fixing this:
 
@@ -190,5 +190,5 @@
 properly, so removing the REJECT line is a must!
 
-XXXXXX: sipbmp3 accepts no responsibility for social faux pas that may
+XXXXXX: gutenbach accepts no responsibility for social faux pas that may
 be committed with this system.  It is consider good etiquette, however,
 to clear the status file if you're on zsr.
@@ -206,5 +206,5 @@
 7. Test, round one
 
-The first test you should do to make sure sipbmp3 is configured properly is
+The first test you should do to make sure gutenbach is configured properly is
 to attempt to play an mp3 file locally, via lpr.  The command you should use
 is:
@@ -258,5 +258,5 @@
 further:
 
-    * Check the zephyr logs of the class sipbmp3 was configured to
+    * Check the zephyr logs of the class gutenbach was configured to
       send messages to:
 
@@ -269,6 +269,6 @@
           *software* volume.
 
-        - If you see a blank zephyr, that means that sipbmp3-filter died
-          trying to get a handle to /var/run/sipbmp3/status and failing.
+        - If you see a blank zephyr, that means that gutenbach-filter died
+          trying to get a handle to /var/run/gutenbach/status and failing.
           Check if you created the file correctly, and that daemon has
           permissions to write to it. If you rebooted recently, check if
@@ -281,7 +281,7 @@
           exiftools is not installed.
 
-    * Otherwise, double check the userland code in sipbmp3-filter. XXX: There
+    * Otherwise, double check the userland code in gutenbach-filter. XXX: There
       are some edge-cases that don't give nice error messages, for example
-      the failed write to /var/run/sipbmp3/status
+      the failed write to /var/run/gutenbach/status
 
 
@@ -292,5 +292,5 @@
 In order to do this, you will need to ask IS&T for a Moira pcap entry
 request.  Send mail to hesreq@mit.edu, specifying that you are setting
-up a sipbmp3 clone, that you want a Moira pcap entry, the printer name
+up a gutenbach clone, that you want a Moira pcap entry, the printer name
 and server name of your queue, and that you want hwtype=LOCAL,ka=1. It wouldn't
 hurt to also tell them where your print queue is, and a contact list.
@@ -326,5 +326,5 @@
 Finally, edit /etc/printcap and give it information about the Kerberos:
 
-sipbmp3: server
+gutenbach: server
     :cm=SIPB MP3 Spooler
     ...
@@ -351,13 +351,13 @@
 You will probably need to apt-get install remctl-server. Then, replace
 the /etc/remctl/conf.d directory with a Git checkout of
-/afs/sipb/project/sipbmp3/sipbmp3-remctl.git.
+/afs/sipb/project/sipbmp3/gutenbach-remctl.git.
 
 Please note that remctl will NOT work without a keytab setup.
 
 
-X. Deploying sipbmp3web
+X. Deploying gutenbachweb
 ------------------------
 
-sipbmp3 web provides a nice and user-friendly interface for some common
+gutenbach web provides a nice and user-friendly interface for some common
 tasks. XXX: It is currently not portable beyond zsr. Stay tuned!
 
@@ -367,3 +367,3 @@
 If things are broken on a reboot, make sure you're running:
 
-    /etc/init.d/{sipbmp3,zhm,debatehna-lprng}
+    /etc/init.d/{gutenbach,zhm,debatehna-lprng}
Index: gutenbach/debian/lib/cd-cddb-get
===================================================================
--- gutenbach/debian/lib/cd-cddb-get	(revision 737d88b72f5b19b99c413cd8889622f0a1fb2574)
+++ gutenbach/debian/lib/cd-cddb-get	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -3,5 +3,5 @@
 
 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
-MYUSER="sipbmp3"
+MYUSER="gutenbach"
 MYHOST="zsr.mit.edu"
 
@@ -13,7 +13,7 @@
 TRACKS="$2"
 
-mkdir -p /var/cache/sipbmp3
+mkdir -p /var/cache/gutenbach
 
-CACHEFILE="/var/cache/sipbmp3/$ID"
+CACHEFILE="/var/cache/gutenbach/$ID"
 
 if [ ! -e "$CACHEFILE" ]; then
Index: gutenbach/debian/lib/cd-play
===================================================================
--- gutenbach/debian/lib/cd-play	(revision 737d88b72f5b19b99c413cd8889622f0a1fb2574)
+++ gutenbach/debian/lib/cd-play	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -18,5 +18,5 @@
     fi
 
-    echo "cdda://$(($T - 1))" | mit-lpr -Psipbmp3@localhost -J "Track $T$DESC";
+    echo "cdda://$(($T - 1))" | mit-lpr -Pgutenbach@localhost -J "Track $T$DESC";
     echo "Queued Track $T$DESC";
 }
Index: gutenbach/debian/lib/gutenbach-filter
===================================================================
--- gutenbach/debian/lib/gutenbach-filter	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
+++ gutenbach/debian/lib/gutenbach-filter	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -0,0 +1,335 @@
+#!/usr/athena/bin/perl
+# Play the data on STDIN as an audio file
+#
+# $Id: gutenbach-filter,v 1.26 2009/02/20 00:27:17 geofft Exp root $
+# $Source: /usr/local/bin/RCS/gutenbach-filter,v $
+#
+# TODO
+# ----
+# Make this structured code. It's a mess.
+# Repeat what we just played for EXT files too
+# Support HTTP Auth on ogg streams
+# License, cleanup and package
+#
+# Jered Floyd <jered@mit.edu> takes very little credit for this code
+# apparently neither does Quentin Smith <quentin@mit.edu>
+
+use Image::ExifTool qw(ImageInfo);
+use File::Spec::Functions;
+use File::Temp qw{tempdir};
+use File::Basename qw(basename);
+use LWP::UserAgent;
+use Data::Dumper;
+use IPC::Open2;
+
+my $zephyr_class = "sipb-test";
+my $host = `hostname`;
+my $queue = "gutenbach";
+
+# Configuration
+my $config_file = "/usr/lib/gutenbach/gutenbach-filter-config.pl";
+if (-r $config_file) {
+    # Inline the configuration file
+    local $/;
+    my $fh;
+    open $fh, $config_file;
+    eval <$fh>;
+}
+
+my $ua = new LWP::UserAgent;
+
+close(STDERR);
+open(STDERR, ">>", "/tmp/gutenbach.log") or warn "Couldn't open log: $!";
+
+$ENV{"TERM"}="vt100";
+
+print STDERR "STDERR FROM SPOOL FILTER\n";
+
+# set real uid to be effective uid
+$< = $>;
+
+# Select the correct output device and set the volume
+#system("amixer -q set Headphone 100\% unmute");
+
+# The command line we get from lpd is (no spaces between options and args):
+#  -C lpr -C class
+#  -A LPRng internal identifier
+#  -H originating host
+#  -J lpr -J jobname (default: list of files)
+#  -L lpr -U username
+#  -P logname
+#  -Q queuename (lpr -Q)
+#  -Z random user-specified options
+#  -a printcap af (accounting file name)
+#  -d printcap sd entry (spool dir)
+#  -e print job data file name (currently being processed)
+#  -h print job originiating host (same as -H)
+#  -j job number in spool queue
+#  -k print job control file name
+#  -l printcap pl (page length)
+#  -n user name (same as -L)
+#  -s printcap sf (status file)
+#  -w printcap pw (page width)
+#  -x printcap px (page x dimension)
+#  -y printcap py (page y dimension)
+# accounting file name
+
+printf(STDERR "Got \@ARGV: %s\n", Dumper(\@ARGV));
+
+my %opts;
+
+my @NEWARGV;
+
+foreach my $arg (@ARGV) {
+  if ($arg =~ m/^-([a-zA-Z])(.*)$/) {
+    $opts{$1} = $2;
+  } else {
+    push @NEWARGV, @ARGV;
+  }
+}
+
+@ARGV = @NEWARGV;
+
+printf(STDERR Dumper(\%opts));
+
+# Status messages at start of playback
+open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c '. $zephyr_class .' -i ' .
+  $queue.'@'.$host.' -s "SIPB LPR music spooler"');
+
+# For the Now Playing remctl command
+open(STATUS, '>', '/var/run/gutenbach/status') or die("Can't open status file /var/run/gutenbach/status");
+
+# For the Now Playing local command
+open(CURRENT, '>', '/var/run/gutenbach/current') or die("Can't open status file /var/run/sipbp3/current");
+
+print(ZEPHYR "$opts{'n'}\@$opts{'H'} is playing:\n");
+print(STATUS "User: $opts{'n'}\@$opts{'H'}\n");
+print(CURRENT "$opts{'n'}\@$opts{'H'} is playing:\n");
+
+# SIGHUP handler
+sub clear_status {
+    # Possible race condition if the previous status is still going
+    open(STA, '>', '/var/run/gutenbach/status');
+    close(STA);
+    open(ZEPH, '|/usr/athena/bin/zwrite -d -n -c '. $zephyr_class .' -i '.
+        $queue.'@'.$host.' -s "SIPB LPR music spooler"');
+    print(ZEPH "Playback aborted.\n");
+    close(ZEPH);
+    open(CURRENT, '|/usr/athena/bin/zwrite -d -n -c '. $zephyr_class .' -i '.
+        $queue.'@'.$host.' -s "SIPB LPR music spooler"');
+    close(CURRENT);
+    die;
+}
+$SIG{HUP} = \&clear_status;
+
+# So, the file we're currently processing is "-d/-e".
+
+# Read the metadata information from the file.
+my ($filepath) = catfile($opts{'d'}, $opts{'e'});
+my ($fileinfo) = ImageInfo($filepath);
+my ($magic) = $fileinfo->{FileType};
+
+if ($magic) {
+    printf(ZEPHYR "%s file %s\n", $magic, $opts{'J'});
+    printf(CURRENT "%s file %s\n", $magic, $opts{'J'});
+    printf(STATUS "Filetype: %s\n", $magic);
+    printf(STATUS "Filename: %s\n", $opts{'J'});
+    if (exists $fileinfo->{'Title'}) {
+        printf(ZEPHYR "\@b{%s}\n", $fileinfo->{'Title'}) if exists $fileinfo->{'Title'};
+        printf(CURRENT "\@b{%s}\n", $fileinfo->{'Title'}) if exists $fileinfo->{'Title'};
+        printf(STATUS "Title: %s\n", $fileinfo->{'Title'});
+    }
+    foreach my $key (qw/Artist Album AlbumArtist/) {
+        if (exists $fileinfo->{$key}) {
+            printf(ZEPHYR "%s\n", $fileinfo->{$key}) if exists $fileinfo->{$key};
+            printf(CURRENT "%s\n", $fileinfo->{$key}) if exists $fileinfo->{$key};
+            printf(STATUS "%s: %s\n", $key, $fileinfo->{$key});
+        }
+    }
+    my $tempdir = tempdir();
+    $opts{'J'} =~ s/_mp3/.mp3/; #awful hack -- geofft
+    my $newpath = $tempdir . '/' . basename($opts{'J'});
+    symlink($filepath, $newpath);
+    $filepath = $newpath;
+}
+elsif ($opts{'C'} eq 'Z') {
+    $filepath = resolve_external_reference($filepath, \%opts);
+    if ($filepath =~ m|http://www\.youtube\.com/watch\?v=|) {
+        $pid = open2($out, $in, qw{youtube-dl -g}, $filepath);
+        #$title = <$out>;
+	$title = "";
+        print ZEPHYR "YouTube video $filepath\n$title";
+        print CURRENT "YouTube video $filepath\n$title";
+        print STATUS "YouTube video $filepath\n$title";
+        $filepath = <$out>;
+        chomp $filepath;
+        waitpid $pid, 0;
+    } else {
+        print STDERR "Resolved external reference to $filepath\n";
+        printf(ZEPHYR "%s\n", $filepath);
+        printf(CURRENT "%s\n", $filepath);
+        printf(STATUS "External: %s\n", $filepath);
+    }
+}
+elsif (-T $filepath) {
+    split_playlist($filepath, \%opts);
+    close(ZEPHYR);
+    close(CURRENT);
+    close(STATUS);
+    exit 0;
+}
+
+#printf(STDERR "Job priority %s\n", $opts{'C'}) if $opts{'C'} eq 'Z';
+#printf(ZEPHYR "Job priority %s\n", $opts{'C'}) if ($opts{'C'} && ($opts{'C'} ne 'A'));
+close(ZEPHYR);
+close(CURRENT);
+close(STATUS);
+play_mplayer_audio($filepath, \%opts);
+
+if ($magic) {
+    unlink($newpath);
+    rmdir($tempdir);
+}
+
+# Play an external stream reference
+sub resolve_external_reference {
+    # Retrieve those command line opts.
+    my ($filepath, $opts) = @_;
+
+    my $format, $uri, $userpass;
+
+    if (<STDIN> =~ /^(\S+)/) {
+	$uri=$1;
+
+        if ($uri =~ m|http://www\.youtube\.com/watch\?v=|) {
+            return $uri;
+        }
+
+	my $response = $ua->head($uri);
+	
+	$contenttype=($response->content_type() or "unknown");
+	
+	if ($contenttype eq "audio/mpeg") { $format="MP3" }
+	elsif ($contenttype eq "application/x-ogg") { $format="OGG" }
+	elsif ($contenttype eq "application/ogg") { $format="OGG" }
+	elsif ($contenttype eq "audio/x-scpls") { $format="SHOUTCAST" }
+	else {
+	    print ZEPHYR
+		"Unknown Content-Type $contenttype for URI $uri\n";
+	}
+    } else {
+        print ZEPHYR "Couldn't read URI for external reference\n";
+	return $filepath;
+    }
+
+    if ($format eq "SHOUTCAST") {
+	print ZEPHYR "Shoutcast playlist...\n";
+	#Don't close ZEPHYR yet, will print the name of the stream if available
+	return &get_shoutcast($uri);
+    } elsif ($format eq "MP3") {
+    } elsif ($format eq "OGG") {
+    } else {
+      print ZEPHYR "Unrecognized stream format: $format\n";
+    }
+    return $uri;
+}
+
+sub split_playlist {
+    my ($file, $opts) = @_;
+
+    my $i = 0;
+    
+    while (<STDIN>) {
+	chomp;
+	if (/^([^#]\S+)/) {
+	    printf (STDERR "Found line: %s\n", $_);
+	    open(LPR, "|-", 'mit-lpr', '-P'.$queue.'@localhost', '-CZ', '-J'.$opts->{J});
+	    print LPR $1;
+	    close(LPR);
+	$i++;
+	}
+    }
+    printf(ZEPHYR "Playlist containing %d valid entries, split into separate jobs.\n", $i);
+}
+
+# Process a Shoutcast playlist
+# get_shoutcast(URI)
+sub get_shoutcast {
+  my $uri = shift(@_);
+  
+  my $response = $ua->get($uri);
+
+  foreach (split("\n", $response->content())) {
+      if (/^File\d+=(\S+)/) {
+	  push(@uris, $1);
+      }
+      if (/^Title\d+=(.+)$/) {
+	  push(@titles, $1);
+      }
+  }
+  
+  # choose a random server
+  $server = int(rand scalar(@uris));
+  # print the name of the stream if available
+  print ZEPHYR "$titles[$server]\n";
+  return $uris[$server];
+}
+
+sub play_mplayer_audio {
+    my ($filepath, $opts) = @_;
+
+    # Prepare to write status:
+    open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c '.$zephyr_class.' -i ' .
+	 $queue.'@'.$host.' -s "SIPB LPR music spooler"');
+    
+    # fork for mpg123
+    my $pid = open(MP3STATUS, "-|");
+    unless (defined $pid) {
+	print ZEPHYR "Couldn't fork: $!\n";
+	close(ZEPHYR);
+	return;
+    }
+    
+    if ($pid) { #parent
+	# Check if there were any errors
+	if ($_ = <MP3STATUS>) {
+	    print ZEPHYR "Playback completed with the following errors:\n";
+	    print ZEPHYR $_;
+	    while (<MP3STATUS>) {
+		print ZEPHYR $_;
+	    }
+	} else {
+	    print ZEPHYR "Playback completed successfully.\n";
+	}
+	close(MP3STATUS) || print ZEPHYR "mplayer exited $?\n";
+	
+	close(ZEPHYR);
+        open(STATUS, '>', '/var/run/gutenbach/status');
+        close(STATUS);
+    }
+  else { # child
+      # redirect STDERR to STDOUT
+      open STDERR, '>&STDOUT';
+      # make sure that mplayer doesn't try to intepret the file as keyboard input
+      close(STDIN);
+      open(STDIN, "/dev/null");
+      #print STDERR Dumper([qw|/usr/bin/mplayer -nolirc -ao alsa -quiet|, $filepath]);
+      my @args = (qw|/usr/bin/mplayer -vo fbdev2 -zoom -x 1024 -y 768 -framedrop -nolirc -ao alsa -cache 512 -really-quiet |, $filepath);
+      #print STDERR "About to exec: ", Dumper([@args]);
+      exec(@args) ||
+	  die "Couldn't exec";
+  }
+}
+
+# ID3 comments often have useless crap because tools like iTunes were
+# written by drooling idiots
+sub filter_comment {
+  my $comment = shift(@_);
+
+  if ($comment =~ /^engiTunes_CDDB/) {
+    return undef;
+  }
+  return $comment;
+}
+
+
Index: gutenbach/debian/lib/gutenbach-get-config
===================================================================
--- gutenbach/debian/lib/gutenbach-get-config	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
+++ gutenbach/debian/lib/gutenbach-get-config	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -0,0 +1,33 @@
+#!/usr/athena/bin/perl
+use strict;
+# Get configuration of gutenbach
+
+my $zephyr_class = "sipb-test";
+my $host = `hostname`;
+my $queue = "gutenbach";
+my $mixer = "Headphone";
+my $channel = "Front Left";
+
+# Configuration
+my $config_file = "/usr/lib/gutenbach/gutenbach-filter-config.pl";
+if (-r $config_file) {
+    # Inline the configuration file
+    local $/;
+    my $fh;
+    open $fh, $config_file;
+    eval <$fh>;
+}
+
+my %config = (
+    'zephyr-class' => $zephyr_class,
+    'host' => $host,
+    'queue' => $queue,
+    'mixer' => $mixer,
+    'channel' => $channel,
+);
+
+foreach my $argv (@ARGV)
+{
+    #print $argv . "\n";
+    print $config{$argv};
+}
Index: tenbach/debian/lib/sipbmp3-filter
===================================================================
--- gutenbach/debian/lib/sipbmp3-filter	(revision f1ba9769e59061d2b054b781788b99d17e89d5b3)
+++ 	(revision )
@@ -1,321 +1,0 @@
-#!/usr/athena/bin/perl
-# Play the data on STDIN as an audio file
-#
-# $Id: sipbmp3-filter,v 1.26 2009/02/20 00:27:17 geofft Exp root $
-# $Source: /usr/local/bin/RCS/sipbmp3-filter,v $
-#
-# TODO
-# ----
-# Make this structured code. It's a mess.
-# Repeat what we just played for EXT files too
-# Support HTTP Auth on ogg streams
-# License, cleanup and package
-#
-# Jered Floyd <jered@mit.edu> takes very little credit for this code
-# apparently neither does Quentin Smith <quentin@mit.edu>
-
-use Image::ExifTool qw(ImageInfo);
-use File::Spec::Functions;
-use File::Temp qw{tempdir};
-use File::Basename qw(basename);
-use LWP::UserAgent;
-use Data::Dumper;
-use IPC::Open2;
-
-my $zephyr_class = "sipb-test";
-my $host = `hostname`;
-my $queue = "sipbmp3";
-
-# Configuration
-my $config_file = "/etc/sipbmp3-filter-config.pl";
-if (-r $config_file) {
-    # Inline the configuration file
-    local $/;
-    my $fh;
-    open $fh, $config_file;
-    eval <$fh>;
-}
-
-my $ua = new LWP::UserAgent;
-
-close(STDERR);
-open(STDERR, ">>", "/tmp/sipbmp3.log") or warn "Couldn't open log: $!";
-
-$ENV{"TERM"}="vt100";
-
-print STDERR "STDERR FROM SPOOL FILTER\n";
-
-# set real uid to be effective uid
-$< = $>;
-
-# Select the correct output device and set the volume
-#system("amixer -q set Headphone 100\% unmute");
-
-# The command line we get from lpd is (no spaces between options and args):
-#  -C lpr -C class
-#  -A LPRng internal identifier
-#  -H originating host
-#  -J lpr -J jobname (default: list of files)
-#  -L lpr -U username
-#  -P logname
-#  -Q queuename (lpr -Q)
-#  -Z random user-specified options
-#  -a printcap af (accounting file name)
-#  -d printcap sd entry (spool dir)
-#  -e print job data file name (currently being processed)
-#  -h print job originiating host (same as -H)
-#  -j job number in spool queue
-#  -k print job control file name
-#  -l printcap pl (page length)
-#  -n user name (same as -L)
-#  -s printcap sf (status file)
-#  -w printcap pw (page width)
-#  -x printcap px (page x dimension)
-#  -y printcap py (page y dimension)
-# accounting file name
-
-printf(STDERR "Got \@ARGV: %s\n", Dumper(\@ARGV));
-
-my %opts;
-
-my @NEWARGV;
-
-foreach my $arg (@ARGV) {
-  if ($arg =~ m/^-([a-zA-Z])(.*)$/) {
-    $opts{$1} = $2;
-  } else {
-    push @NEWARGV, @ARGV;
-  }
-}
-
-@ARGV = @NEWARGV;
-
-printf(STDERR Dumper(\%opts));
-
-# Status messages at start of playback
-open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c '. $zephyr_class .' -i ' .
-  $queue.'@'.$host.' -s "SIPB LPR music spooler"');
-
-# For the Now Playing remctl command
-open(STATUS, '>', '/var/run/sipbmp3/status') or die("Can't open status file /var/run/sipbmp3/status");
-
-print(ZEPHYR "$opts{'n'}\@$opts{'H'} is playing:\n");
-print(STATUS "User: $opts{'n'}\@$opts{'H'}\n");
-
-# SIGHUP handler
-sub clear_status {
-    # Possible race condition if the previous status is still going
-    open(STA, '>', '/var/run/sipbmp3/status');
-    close(STA);
-    open(ZEPH, '|/usr/athena/bin/zwrite -d -n -c '. $zephyr_class .' -i '.
-        $queue.'@'.$host.' -s "SIPB LPR music spooler"');
-    print(ZEPH "Playback aborted.\n");
-    close(ZEPH);
-    die;
-}
-$SIG{HUP} = \&clear_status;
-
-# So, the file we're currently processing is "-d/-e".
-
-# Read the metadata information from the file.
-my ($filepath) = catfile($opts{'d'}, $opts{'e'});
-my ($fileinfo) = ImageInfo($filepath);
-my ($magic) = $fileinfo->{FileType};
-
-if ($magic) {
-    printf(ZEPHYR "%s file %s\n", $magic, $opts{'J'});
-    printf(STATUS "Filetype: %s\n", $magic);
-    printf(STATUS "Filename: %s\n", $opts{'J'});
-    if (exists $fileinfo->{'Title'}) {
-        printf(ZEPHYR "\@b{%s}\n", $fileinfo->{'Title'}) if exists $fileinfo->{'Title'};
-        printf(STATUS "Title: %s\n", $fileinfo->{'Title'});
-    }
-    foreach my $key (qw/Artist Album AlbumArtist/) {
-        if (exists $fileinfo->{$key}) {
-            printf(ZEPHYR "%s\n", $fileinfo->{$key}) if exists $fileinfo->{$key};
-            printf(STATUS "%s: %s\n", $key, $fileinfo->{$key});
-        }
-    }
-    my $tempdir = tempdir();
-    $opts{'J'} =~ s/_mp3/.mp3/; #awful hack -- geofft
-    my $newpath = $tempdir . '/' . basename($opts{'J'});
-    symlink($filepath, $newpath);
-    $filepath = $newpath;
-}
-elsif ($opts{'C'} eq 'Z') {
-    $filepath = resolve_external_reference($filepath, \%opts);
-    if ($filepath =~ m|http://www\.youtube\.com/watch\?v=|) {
-        $pid = open2($out, $in, qw{youtube-dl -g}, $filepath);
-        #$title = <$out>;
-	$title = "";
-        print ZEPHYR "YouTube video $filepath\n$title";
-        print STATUS "YouTube video $filepath\n$title";
-        $filepath = <$out>;
-        chomp $filepath;
-        waitpid $pid, 0;
-    } else {
-        print STDERR "Resolved external reference to $filepath\n";
-        printf(ZEPHYR "%s\n", $filepath);
-        printf(STATUS "External: %s\n", $filepath);
-    }
-}
-elsif (-T $filepath) {
-    split_playlist($filepath, \%opts);
-    close(ZEPHYR);
-    close(STATUS);
-    exit 0;
-}
-
-#printf(STDERR "Job priority %s\n", $opts{'C'}) if $opts{'C'} eq 'Z';
-#printf(ZEPHYR "Job priority %s\n", $opts{'C'}) if ($opts{'C'} && ($opts{'C'} ne 'A'));
-close(ZEPHYR);
-close(STATUS);
-play_mplayer_audio($filepath, \%opts);
-
-if ($magic) {
-    unlink($newpath);
-    rmdir($tempdir);
-}
-
-# Play an external stream reference
-sub resolve_external_reference {
-    # Retrieve those command line opts.
-    my ($filepath, $opts) = @_;
-
-    my $format, $uri, $userpass;
-
-    if (<STDIN> =~ /^(\S+)/) {
-	$uri=$1;
-
-        if ($uri =~ m|http://www\.youtube\.com/watch\?v=|) {
-            return $uri;
-        }
-
-	my $response = $ua->head($uri);
-	
-	$contenttype=($response->content_type() or "unknown");
-	
-	if ($contenttype eq "audio/mpeg") { $format="MP3" }
-	elsif ($contenttype eq "application/x-ogg") { $format="OGG" }
-	elsif ($contenttype eq "application/ogg") { $format="OGG" }
-	elsif ($contenttype eq "audio/x-scpls") { $format="SHOUTCAST" }
-	else {
-	    print ZEPHYR
-		"Unknown Content-Type $contenttype for URI $uri\n";
-	}
-    } else {
-        print ZEPHYR "Couldn't read URI for external reference\n";
-	return $filepath;
-    }
-
-    if ($format eq "SHOUTCAST") {
-	print ZEPHYR "Shoutcast playlist...\n";
-	#Don't close ZEPHYR yet, will print the name of the stream if available
-	return &get_shoutcast($uri);
-    } elsif ($format eq "MP3") {
-    } elsif ($format eq "OGG") {
-    } else {
-      print ZEPHYR "Unrecognized stream format: $format\n";
-    }
-    return $uri;
-}
-
-sub split_playlist {
-    my ($file, $opts) = @_;
-
-    my $i = 0;
-    
-    while (<STDIN>) {
-	chomp;
-	if (/^([^#]\S+)/) {
-	    printf (STDERR "Found line: %s\n", $_);
-	    open(LPR, "|-", 'mit-lpr', '-P'.$queue.'@localhost', '-CZ', '-J'.$opts->{J});
-	    print LPR $1;
-	    close(LPR);
-	$i++;
-	}
-    }
-    printf(ZEPHYR "Playlist containing %d valid entries, split into separate jobs.\n", $i);
-}
-
-# Process a Shoutcast playlist
-# get_shoutcast(URI)
-sub get_shoutcast {
-  my $uri = shift(@_);
-  
-  my $response = $ua->get($uri);
-
-  foreach (split("\n", $response->content())) {
-      if (/^File\d+=(\S+)/) {
-	  push(@uris, $1);
-      }
-      if (/^Title\d+=(.+)$/) {
-	  push(@titles, $1);
-      }
-  }
-  
-  # choose a random server
-  $server = int(rand scalar(@uris));
-  # print the name of the stream if available
-  print ZEPHYR "$titles[$server]\n";
-  return $uris[$server];
-}
-
-sub play_mplayer_audio {
-    my ($filepath, $opts) = @_;
-
-    # Prepare to write status:
-    open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c '.$zephyr_class.' -i ' .
-	 $queue.'@'.$host.' -s "SIPB LPR music spooler"');
-    
-    # fork for mpg123
-    my $pid = open(MP3STATUS, "-|");
-    unless (defined $pid) {
-	print ZEPHYR "Couldn't fork: $!\n";
-	close(ZEPHYR);
-	return;
-    }
-    
-    if ($pid) { #parent
-	# Check if there were any errors
-	if ($_ = <MP3STATUS>) {
-	    print ZEPHYR "Playback completed with the following errors:\n";
-	    print ZEPHYR $_;
-	    while (<MP3STATUS>) {
-		print ZEPHYR $_;
-	    }
-	} else {
-	    print ZEPHYR "Playback completed successfully.\n";
-	}
-	close(MP3STATUS) || print ZEPHYR "mplayer exited $?\n";
-	
-	close(ZEPHYR);
-        open(STATUS, '>', '/var/run/sipbmp3/status');
-        close(STATUS);
-    }
-  else { # child
-      # redirect STDERR to STDOUT
-      open STDERR, '>&STDOUT';
-      # make sure that mplayer doesn't try to intepret the file as keyboard input
-      close(STDIN);
-      open(STDIN, "/dev/null");
-      #print STDERR Dumper([qw|/usr/bin/mplayer -nolirc -ao alsa -quiet|, $filepath]);
-      my @args = (qw|/usr/bin/mplayer -vo fbdev2 -zoom -x 1024 -y 768 -framedrop -nolirc -ao alsa -cache 512 -really-quiet |, $filepath);
-      #print STDERR "About to exec: ", Dumper([@args]);
-      exec(@args) ||
-	  die "Couldn't exec";
-  }
-}
-
-# ID3 comments often have useless crap because tools like iTunes were
-# written by drooling idiots
-sub filter_comment {
-  my $comment = shift(@_);
-
-  if ($comment =~ /^engiTunes_CDDB/) {
-    return undef;
-  }
-  return $comment;
-}
-
-
Index: tenbach/debian/lib/sipbmp3-get-config
===================================================================
--- gutenbach/debian/lib/sipbmp3-get-config	(revision 28836c23fd4373bdd7d7706a571d241a0bfc1dba)
+++ 	(revision )
@@ -1,33 +1,0 @@
-#!/usr/athena/bin/perl
-use strict;
-# Get configuration of sipbmp3
-
-my $zephyr_class = "sipb-test";
-my $host = `hostname`;
-my $queue = "sipbmp3";
-my $mixer = "Headphone";
-my $channel = "Front Left";
-
-# Configuration
-my $config_file = "/etc/sipbmp3-filter-config.pl";
-if (-r $config_file) {
-    # Inline the configuration file
-    local $/;
-    my $fh;
-    open $fh, $config_file;
-    eval <$fh>;
-}
-
-my %config = (
-    'zephyr-class' => $zephyr_class,
-    'host' => $host,
-    'queue' => $queue,
-    'mixer' => $mixer,
-    'channel' => $channel,
-);
-
-foreach my $argv (@ARGV)
-{
-    #print $argv . "\n";
-    print $config{$argv};
-}
Index: gutenbach/debian/lib/status-clear
===================================================================
--- gutenbach/debian/lib/status-clear	(revision 737d88b72f5b19b99c413cd8889622f0a1fb2574)
+++ gutenbach/debian/lib/status-clear	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -1,3 +1,3 @@
 #!/bin/sh
 PATH="$(dirname $0):$PATH"
-> /var/run/sipbmp3/status
+> /var/run/gutenbach/status
Index: gutenbach/debian/lib/status-get
===================================================================
--- gutenbach/debian/lib/status-get	(revision 737d88b72f5b19b99c413cd8889622f0a1fb2574)
+++ gutenbach/debian/lib/status-get	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -1,3 +1,3 @@
 #!/bin/sh
 PATH="$(dirname $0):$PATH"
-cat /var/run/sipbmp3/status
+cat /var/run/gutenbach/status
Index: gutenbach/debian/lib/volume-get
===================================================================
--- gutenbach/debian/lib/volume-get	(revision 28836c23fd4373bdd7d7706a571d241a0bfc1dba)
+++ gutenbach/debian/lib/volume-get	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -2,6 +2,6 @@
 PATH="$(dirname $0):$PATH"
 
-mixer=$(sipbmp3-get-config mixer)
-channel=$(sipbmp3-get-config channel)
+mixer=$(gutenbach-get-config mixer)
+channel=$(gutenbach-get-config channel)
 
 amixer get $mixer | grep "$channel" \
Index: gutenbach/debian/lib/volume-is-muted
===================================================================
--- gutenbach/debian/lib/volume-is-muted	(revision 9f0c46e5cd2255b32915690fa0b424c83a59c7f7)
+++ gutenbach/debian/lib/volume-is-muted	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -2,6 +2,6 @@
 PATH="$(dirname $0):$PATH"
 
-mixer=$(sipbmp3-get-config mixer)
-channel=$(sipbmp3-get-config channel)
+mixer=$(gutenbach-get-config mixer)
+channel=$(gutenbach-get-config channel)
 
 volstat=$(amixer get $mixer | grep "$channel" \
Index: gutenbach/debian/lib/volume-mute
===================================================================
--- gutenbach/debian/lib/volume-mute	(revision 0d16875138f1119db363285c4ab6af9cb591d6f4)
+++ gutenbach/debian/lib/volume-mute	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -2,6 +2,6 @@
 PATH="$(dirname $0):$PATH"
 
-mixer=$(sipbmp3-get-config mixer)
-channel=$(sipbmp3-get-config channel)
+mixer=$(gutenbach-get-config mixer)
+channel=$(gutenbach-get-config channel)
 
 amixer set $mixer toggle > /dev/null
Index: gutenbach/debian/lib/volume-set
===================================================================
--- gutenbach/debian/lib/volume-set	(revision 9f0c46e5cd2255b32915690fa0b424c83a59c7f7)
+++ gutenbach/debian/lib/volume-set	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -2,6 +2,6 @@
 PATH="$(dirname $0):$PATH"
 
-mixer=$(sipbmp3-get-config mixer)
-channel="$(sipbmp3-get-config channel)"
+mixer=$(gutenbach-get-config mixer)
+channel="$(gutenbach-get-config channel)"
 
 amixer set $mixer "$2" | grep "$channel" \
Index: gutenbach/debian/lib/volume-show
===================================================================
--- gutenbach/debian/lib/volume-show	(revision 9f0c46e5cd2255b32915690fa0b424c83a59c7f7)
+++ gutenbach/debian/lib/volume-show	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -2,6 +2,6 @@
 PATH="$(dirname $0):$PATH"
 
-mixer=$(sipbmp3-get-config mixer)
-channel=$(sipbmp3-get-config channel)
+mixer=$(gutenbach-get-config mixer)
+channel=$(gutenbach-get-config channel)
 
 amixer get $mixer
Index: gutenbach/debian/lib/volume-zephyr
===================================================================
--- gutenbach/debian/lib/volume-zephyr	(revision 4f58f93950379af8b45dec6b5368f0252b43e5ee)
+++ gutenbach/debian/lib/volume-zephyr	(revision 2e8b5892e5036de1770530513f02275b1daaf234)
@@ -1,11 +1,11 @@
 #!/bin/sh
 PATH="$(dirname $0):$PATH"
-class=$(sipbmp3-get-config zephyr-class)
-host=$(sipbmp3-get-config host)
-queue=$(sipbmp3-get-config queue)
+class=$(gutenbach-get-config zephyr-class)
+host=$(gutenbach-get-config host)
+queue=$(gutenbach-get-config queue)
 instance="$queue-volume@$host"
 
-mixer=$(sipbmp3-get-config mixer)
-channel=$(sipbmp3-get-config channel)
+mixer=$(gutenbach-get-config mixer)
+channel=$(gutenbach-get-config channel)
 
 muted=$(volume-is-muted)
@@ -15,4 +15,4 @@
 fi
 
-start-stop-daemon --stop --oknodo --pidfile /var/run/sipbmp3-zephyr >/dev/null 2>&1
-start-stop-daemon --start --pidfile /var/run/sipbmp3-zephyr --make-pidfile --background --exec /bin/sh -- -c "sleep 10 && zwrite -c $class -i $instance -d -n -m 'volume changed to $(volume-get)$mute_str' > /dev/null" >/dev/null 2>&1
+start-stop-daemon --stop --oknodo --pidfile /usr/lib/gutenbach/gutenbach-zephyr >/dev/null 2>&1
+start-stop-daemon --start --pidfile /usr/lib/gutenbach/gutenbach-zephyr --make-pidfile --background --exec /bin/sh -- -c "sleep 10 && zwrite -c $class -i $instance -d -n -m '$REMOTE_USER set volume $(volume-get)$mute_str' > /dev/null" >/dev/null 2>&1
