Changeset ba06c7f


Ignore:
Timestamp:
Sep 27, 2008, 5:00:41 AM (16 years ago)
Author:
root <root>
Branches:
master, debian, mac, no-cups, nodebathena, web
Children:
f3974e2
Parents:
283d671f
git-author:
root <root> (09/27/08 05:00:41)
git-committer:
root <root> (09/27/08 05:00:41)
Message:

Use mplayer for all audio playing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gutenbach/debian/lib/sipbmp3-filter

    r5e66bb4 rba06c7f  
    22# Play the data on STDIN as an audio file
    33#
    4 # $Id: sipbmp3-filter,v 1.15 2007-12-22 04:20:29 jhawk Exp $
     4# $Id: sipbmp3-filter,v 1.16 2008-09-27 09:00:41 root Exp $
    55# $Source: /tmp/tmp.UFBNno9997/RCS/sipbmp3-filter,v $
    66#
     
    1616use Getopt::Std;
    1717
    18 # Get the MP3Info module from this directory, because I suck.
    19 unshift(@INC, "/usr/local/bin");
    20 require MP3::Info;
    21 import MP3::Info;
    22 &use_winamp_genres();
     18use Image::ExifTool qw(ImageInfo);
     19use File::Spec::Functions;
     20use LWP::UserAgent;
     21use Data::Dumper;
     22
     23my $ua = new LWP::UserAgent;
     24
     25close(STDERR);
     26open(STDERR, ">>", "/tmp/sipbmp3.log") or warn "Couldn't open log: $!";
     27
     28$ENV{"TERM"}="vt100";
    2329
    2430print STDERR "STDERR FROM SPOOL FILTER\n";
     
    2733$< = $>;
    2834
    29 # Attach necessary lockers
    30 system("/bin/athena/attach -h -n -q infoagents sipb outland ' .
    31     'consult 2>&1 > /dev/null");
    32 
    3335# Select the correct output device and set the volume
    34 system("/usr/local/bin/audio_setdevice -out headphones 100 ' .
    35     '2>&1 </dev/null > /dev/null");
     36#system("amixer -q set Headphone 100\% unmute");
    3637
    3738# The command line we get from lpd is (no spaces between options and args):
     
    6364# Status messages at start of playback
    6465open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c sipb-auto -i ' .
    65   'sipbmp3@xcb -s "SIPB LPR music spooler"');
     66  'sipbmp3@zsr -s "SIPB LPR music spooler"');
    6667print(ZEPHYR "User $opts{'n'} on host $opts{'H'} is playing:\n");
    6768
    6869# So, the file we're currently processing is "-d/-e".
    69 # Do some magic to make sure it's an MP3, and get the important bits
    70 # to zephyr out.
    71 open(DATAFILE, "$opts{'d'}/$opts{'e'}");
    72 sysread(DATAFILE, $magic, 3);
    73 close(DATAFILE);
    74 
    75 # MPEG header is beshort &0xffe0
    76 # meditate upon the header:
    77 ($magic0, $magic1, @magic2) = unpack("C3", $magic);
    78 if ((($magic0 & 0xff) == 0xff) &&
    79     (($magic1 & 0xe0) == 0xe0)) {
    80   # MPEG audio file, we like it
    81   # Fall through
    82 } elsif ($magic eq "ID3") {
    83   # ID3 v2 does sketchy things with "garbage" beginning with ID3 at file start.
    84   # MPEG audio file with ID3 tag, we like it
    85   # Fall through
    86 } elsif ($magic eq "EXT") {
    87   # This is an external stream reference (a jered-special)
    88   &play_external_reference(\%opts, $magic);
    89   exit 0;
    90 } elsif ($magic eq "htt") {
    91   # This is an external stream reference (a jered-special)
    92   &play_external_reference(\%opts, $magic);
    93   exit 0;
    94 } elsif ($magic eq "Ogg") {
    95   # Ogg-Vorbis audio file
    96   &play_ogg_audio(\%opts);
    97   exit 0;
    98 } elsif ($magic0 == 0x52 && $magic1 == 0x49) {
    99   &play_wav_audio(\%opts);
    100   exit 0;
    101 } else {
    102     # add more cases later, whine for now
    103     printf(ZEPHYR "I don't think this is an MPEG audio file... %02x %02x\n",
    104            $magic0, $magic1);
    105     print ZEPHYR "I'm going to try playing it as one anyway.\n";
    106 }
    107 # Default
    108 &play_mpeg_audio(\%opts);
    109 
     70
     71# Read the metadata information from the file.
     72my ($filepath) = catfile($opts{'d'}, $opts{'e'});
     73my ($fileinfo) = ImageInfo($filepath);
     74my ($magic) = $fileinfo->{FileType};
     75
     76if ($magic) {
     77    printf(ZEPHYR "A file of type %s.", $magic);
     78    foreach my $key (sort keys %$fileinfo) {
     79        printf(ZEPHYR "%s: %s\n", $key, $fileinfo->{$key});
     80    }
     81}
     82elsif (-T $filepath) {
     83    $filepath = resolve_external_reference($filepath, \%opts);
     84}
     85close(ZEPHYR);
     86play_mplayer_audio($filepath, \%opts);
    11087
    11188# Play an external stream reference
    112 sub play_external_reference {
     89sub resolve_external_reference {
    11390    # Retrieve those command line opts.
    114     my %opts = %{shift(@_)};
    115     my $magic = shift(@_);
    116 
    117     # External references are *not* playlists; they only support
    118     # a single URL in order to be fair.  A reference is structured as
    119     # follows:
    120     #
    121     # EXT <format>\n
    122     # <URI>[ <user:pass>]\n
    123     # Descriptive text of the file that will be\n
    124     # played; this may span multiple lines until the\n
    125     # EOF
    126     #
    127     # Where <URI> is a valid URI for the stream, and <format> is a
    128     # recognized format name (currently 'MP3' or 'OGG' or 'SHOUTCAST').
    129     # <user:pass> is an optional user and password pair for HTTP Basic Auth.
     91    my ($filepath, $opts) = @_;
     92
    13093    my $format, $uri, $userpass;
    13194
    132     if ("$magic" eq "EXT") {
    133       if (<STDIN> =~ /^EXT (.*)$/) {
    134         # Found the header
    135         $format = $1;
    136       } else {
    137         print ZEPHYR "Couldn't read EXT header\n";
    138         close(ZEPHYR);
    139       }
    140  
    141       if (<STDIN> =~ /^(\S*)\s*(.*)$/) {
    142         # Found the URI (and optionally user:pass)
    143         $uri = $1;
    144         if ($2) {
    145         $userpass = $2;
    146         }
    147       } else {
     95    if (<STDIN> =~ /^(\S+)/) {
     96        $uri=$1;
     97
     98        my $response = $ua->head($uri);
     99       
     100        $contenttype=($response->content_type() or "unknown");
     101       
     102        if ($contenttype eq "audio/mpeg") { $format="MP3" }
     103        elsif ($contenttype eq "application/x-ogg") { $format="OGG" }
     104        elsif ($contenttype eq "application/ogg") { $format="OGG" }
     105        elsif ($contenttype eq "audio/x-scpls") { $format="SHOUTCAST" }
     106        else {
     107            print ZEPHYR
     108                "Unknown Content-Type $contenttype for URI $uri\n";
     109            close(ZEPHYR);
     110        }
     111    } else {
    148112        print ZEPHYR "Couldn't read URI for external reference\n";
    149113        close(ZEPHYR);
    150       }
    151   } elsif ("$magic" eq "htt") {
    152       if (<STDIN> =~ /^(\S*)\s*(.*)$/) {
    153           $uri=$1;
    154           my $pid = open(W3M, "-|");
    155           unless (defined $pid) {
    156               print ZEPHYR "Couldn't fork: $!\n";
    157               close(ZEPHYR);
    158               die;
    159           }
    160 
    161           if ($pid) { #parent
    162               $contenttype="unknown";
    163               while (<W3M>) {
    164                   if ($_ =~ /^Content-Type:\s(\S*)/) {
    165                       $contenttype=$1;
    166                   }
    167               }
    168               if ($contenttype eq "audio/mpeg") { $format="MP3" }
    169               elsif ($contenttype eq "application/x-ogg") { $format="OGG" }
    170               elsif ($contenttype eq "application/ogg") { $format="OGG" }
    171               elsif ($contenttype eq "audio/x-scpls") { $format="SHOUTCAST" }
    172               else {
    173                   print ZEPHYR
    174                       "Unknown Content-Type $contenttype for URI $uri\n";
    175                   close(ZEPHYR);
    176               }
    177               close(W3M) || print ZEPHYR "w3m exited $?\n";
    178           }
    179           else { # child
    180               exec("/mit/sipb/bin/w3m", "-dump_head", $uri)
    181                   || die "Couldn't exec";
    182           }
    183       } else {
    184         print ZEPHYR "Couldn't read URI for external reference\n";
    185         close(ZEPHYR);
    186     }
    187   } else {
    188       print ZEPHYR "Unknown syntax in play_external_reference(): $magic\n";
    189       close(ZEPHYR);
    190   }
    191 
    192     # Echo the rest to the zephyr
    193     while (<STDIN>) {
    194       print ZEPHYR $_;
    195     }
    196     print ZEPHYR "\n";
    197 
    198     # Play the thing the right way
    199     if (($format eq "MP3") ||
    200         ($format eq "mp3")) {
    201       print ZEPHYR "MP3 audio stream...\n";
    202       close(ZEPHYR);
    203       &play_mpeg_stream($uri, $userpass);
    204     }
    205     elsif ($format eq "SHOUTCAST") {
     114        return $filepath;
     115    }
     116
     117    if ($format eq "SHOUTCAST") {
    206118        print ZEPHYR "Shoutcast playlist...\n";
    207119        #Don't close ZEPHYR yet, will print the name of the stream if available
    208         $uri = &get_shoutcast($uri);
    209         close(ZEPHYR);
    210         &play_mpeg_stream($uri, undef);
    211     }   
    212     elsif (($format eq "OGG") ||
    213              ($format eq "ogg")) {
    214       print ZEPHYR "OggVorbis stream...\n";
    215       close(ZEPHYR);
    216       &play_ogg_stream($uri, $userpass);
     120        return &get_shoutcast($uri);
     121    } elsif ($format eq "MP3") {
     122    } elsif ($format eq "OGG") {
    217123    } else {
    218124      print ZEPHYR "Unrecognized stream format: $format\n";
    219       close(ZEPHYR);
    220     }
     125    }
     126    return $uri;
    221127}
    222128
     
    226132  my $uri = shift(@_);
    227133 
    228   # grab the shoutcast .pls file
    229   my $pid = open(W3M, "-|");
    230   unless (defined $pid) {
    231       print ZEPHYR "Couldn't fork: $!\n";
    232       close(ZEPHYR);
    233       die;
    234   }
    235   if (!$pid) { # child
    236       exec("/mit/sipb/bin/w3m","-dump_source",$uri) || die "Couldn't fork";
    237   }
    238   while (<W3M>) {
     134  my $response = $ua->get($uri);
     135
     136  foreach (split("\n", $response->content())) {
    239137      if (/^File\d+=(\S+)/) {
    240138          push(@uris, $1);
     
    244142      }
    245143  }
    246   close(W3M);
    247144 
    248145  # choose a random server
     
    253150}
    254151
    255 # Play an MPEG audio stream
    256 # play_mpeg_stream(URI, userpass)
    257 sub play_mpeg_stream {
    258   my $uri = shift(@_);
    259   my $userpass = shift(@_);
    260 
    261   # Add the user:pass argument if is was given to us
    262   my $up = '';
    263   if ($userpass) {
    264     $up = '-u ' . $userpass;
    265   }
    266 
    267   system("ps ax | grep ogg123 | awk '{print $2}' | xargs kill -9");
    268   system("ps ax | grep mpg123 | awk '{print $2}' | xargs kill -9");
    269   system("chmod a+rw /dev/audio");
    270 
    271   # Prepare to write status:
    272   open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c sipb-auto -i ' .
    273        'sipbmp3@xcb -s "SIPB LPR music spooler"');
    274      
    275   # fork for mpg123
    276   my $pid = open(MP3STATUS, "-|");
    277   unless (defined $pid) {
    278       print ZEPHYR "Couldn't fork: $!\n";
    279       close(ZEPHYR);
    280       return;
    281   }
    282  
    283   if ($pid) { #parent
    284       # Check if there were any errors
    285       if ($_ = <MP3STATUS>) {
    286           print ZEPHYR "Playback completed with the following errors:\n";
    287           print ZEPHYR $_;
    288           while (<MP3STATUS>) {
    289               print ZEPHYR $_;
    290           }
    291       } else {
    292           print ZEPHYR "Playback completed successfully.\n";
    293       }
    294       close(MP3STATUS) || print ZEPHYR "mpg123 exited $?\n";
    295      
    296       close(ZEPHYR);
    297   }
     152sub play_mplayer_audio {
     153    my ($filepath, $opts) = @_;
     154
     155    # Prepare to write status:
     156    open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c sipb-auto -i ' .
     157         'sipbmp3@zsr -s "SIPB LPR music spooler"');
     158   
     159    # fork for mpg123
     160    my $pid = open(MP3STATUS, "-|");
     161    unless (defined $pid) {
     162        print ZEPHYR "Couldn't fork: $!\n";
     163        close(ZEPHYR);
     164        return;
     165    }
     166   
     167    if ($pid) { #parent
     168        # Check if there were any errors
     169        if ($_ = <MP3STATUS>) {
     170            print ZEPHYR "Playback completed with the following errors:\n";
     171            print ZEPHYR $_;
     172            while (<MP3STATUS>) {
     173                print ZEPHYR $_;
     174            }
     175        } else {
     176            print ZEPHYR "Playback completed successfully.\n";
     177        }
     178        close(MP3STATUS) || print ZEPHYR "mplayer exited $?\n";
     179       
     180        close(ZEPHYR);
     181    }
    298182  else { # child
    299183      # redirect STDERR to STDOUT
    300184      open STDERR, '>&STDOUT';
    301 
    302       # disabling the buffer seems to improve streaming performances
    303       # (files don't get cut in the middle) - perhaps mpg123 fails to
    304       # wait for OS TCP buffer to be filled. -- jtwang 22 Oct 2003
    305       #exec("/mit/infoagents/bin/mpg123", "-b16384", "-q", $up, $uri ||
    306       #   die "Couldn't exec";
    307       exec("/mit/infoagents/bin/mpg123", "-q", $up, $uri) ||
     185      # make sure that mplayer doesn't try to intepret the file as keyboard input
     186      close(STDIN);
     187      open(STDIN, "/dev/null");
     188      #print STDERR Dumper([qw|/usr/bin/mplayer -nolirc -ao alsa -quiet|, $filepath]);
     189      exec(qw|/usr/bin/mplayer -nolirc -ao alsa -quiet|, $filepath) ||
    308190          die "Couldn't exec";
    309191  }
     
    322204
    323205
    324 # Play an MPEG audio file
    325 sub play_mpeg_audio {
    326     # Retrieve those command line opts.
    327     my %opts = %{shift(@_)};
    328 
    329     my %MPEGModes = ( 0 => "stereo",
    330                       1 => "joint-stereo",
    331                       2 => "dual-channel",
    332                       3 => "single-channel");
    333 
    334     # If it's an MP3 file, try to extract useful data
    335     my $tag = get_mp3tag("$opts{'d'}/$opts{'e'}");
    336     if (!$tag) {
    337         print ZEPHYR "No ID3 tag found\n";
    338         my @fnamearray = split /,/, $opts{'J'};
    339         foreach $fname (@fnamearray) {
    340             print ZEPHYR "Filename: $fname\n";
    341         }
    342 #           print ZEPHYR "Filename: $opts{'J'}\n\n";
    343     } else {
    344       print ZEPHYR "Title          : $tag->{TITLE}\n";
    345       print ZEPHYR "Artist         : $tag->{ARTIST}\n";
    346       print ZEPHYR "Album          : $tag->{ALBUM}\n";
    347       if ($tag->{TRACKNUM} =~ /(.*)\/.*/) {
    348           $tag->{TRACKNUM} = $1;
    349       }
    350       if ($tag->{TRACKNUM}) {
    351           print ZEPHYR "Track #        : $tag->{TRACKNUM}\n";
    352       }
    353       if ($tag->{YEAR}) {
    354         print ZEPHYR "Year           : $tag->{YEAR}\n";
    355       }
    356       if ($tag->{GENRE}) {
    357         # iTunes (?) does something weird with genres, leaving them
    358         # as the string "(##)" where ## is the genre type. Let's deal
    359         # with this.
    360         if ($tag->{GENRE} =~ /^\((\d*)\)$/) {
    361           $tag->{GENRE} = $MP3::Info::mp3_genres[$1];
    362         }
    363         if ($tag->{GENRE} =~ /^(\d*)$/) {
    364           $tag->{GENRE} = $MP3::Info::mp3_genres[$1];
    365         }
    366         print ZEPHYR "Genre          : $tag->{GENRE}\n";
    367       }
    368       if (ref $tag->{COMMENT} eq 'ARRAY') {
    369         foreach $index (0 .. $#{$tag->{COMMENT}}) {
    370           if ($comment = filter_comment(@{$tag->{COMMENT}}[$index])) {
    371             print ZEPHYR "Comment        : $comment\n";
    372           }
    373         }
    374       } elsif ($tag->{COMMENT}) {
    375         if ($comment = filter_comment($tag->{COMMENT})) {
    376           print ZEPHYR "Comment        : $comment\n";
    377         }
    378       }
    379 
    380       # Maybe get some extended ID3v2 info?
    381       my $v2tag = get_mp3tag("$opts{'d'}/$opts{'e'}", 2, 1);
    382       %lessinfo = %$v2tag;
    383       foreach $dtag (keys %MP3::Info::v2_to_v1_names) {
    384         delete $lessinfo{$dtag};
    385       }
    386       delete $lessinfo{'GENRE'};
    387       # Delete annoying useless crap
    388       my @bad_tags = ('GEO', 'GEOB', # General encapsulated object
    389                       'PIC', 'APIC', # Attached picture.
    390                       );
    391       foreach $dtag (@bad_tags) {
    392           delete $lessinfo{$dtag};
    393       }
    394       while (($key,$val) = each %lessinfo) {
    395         printf ZEPHYR "%-15s: %s\n", $MP3::Info::v2_tag_names{$key}, $val;
    396       }
    397       print ZEPHYR "\n";
    398     }
    399 
    400     my $info = get_mp3info("$opts{'d'}/$opts{'e'}");
    401     if (!$info) {
    402         print ZEPHYR "No MPEG header found\n";
    403     } else {
    404         print ZEPHYR "MPEG $info->{VERSION} layer $info->{LAYER}, ";
    405         if ($info->{VBR}) {
    406             print ZEPHYR "VBR ";
    407         }
    408         print ZEPHYR "$info->{BITRATE} kbit/s, $info->{FREQUENCY} kHz ";
    409         print ZEPHYR $MPEGModes{$info->{STEREO}};
    410         print ZEPHYR "\n\n";
    411         printf ZEPHYR "Track length: %d:%02ds\n", $info->{MM}, $info->{SS};
    412     }
    413     close(ZEPHYR);
    414 
    415     # Play the file
    416     # mpg123 is a crock.  If you don't give it -q, it needs to be on a pty
    417     # or it SEGVs. Really.
    418 
    419     system("chmod a+rw /dev/audio");
    420     system("ps ax | grep ogg123 | awk '{print $2}' | xargs kill -9");
    421     system("ps ax | grep mpg123 | awk '{print $2}' | xargs kill -9");
    422     system("/mit/infoagents/bin/mpg123 -b 16384 -q - >/tmp/mpg123.out 2>&1");
    423 
    424     # Done. Status:
    425     open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c sipb-auto -i ' .
    426          'sipbmp3@xcb -s "SIPB LPR music spooler"');
    427 
    428     # Check if there were any errors
    429     open(MP3STATUS, "/tmp/mpg123.out");
    430     if ($_ = <MP3STATUS>) {
    431         print ZEPHYR "Playback completed with the following errors:\n";
    432         print ZEPHYR $_;
    433         while (<MP3STATUS>) {
    434             print ZEPHYR $_;
    435         }
    436     } else {
    437         print ZEPHYR "Playback completed successfully.\n";
    438         # Repeat tag data for those playing at home
    439         if (!$tag) {
    440           print ZEPHYR "No ID3 tag found\n";
    441           print ZEPHYR "Filename: $opts{'J'}\n\n";
    442         } else {
    443           print ZEPHYR "Title          : $tag->{TITLE}\n";
    444           print ZEPHYR "Artist         : $tag->{ARTIST}\n";
    445           print ZEPHYR "Album          : $tag->{ALBUM}\n";
    446           if ($tag->{TRACKNUM} =~ /(.*)\/.*/) {
    447               $tag->{TRACKNUM} = $1;
    448           }
    449           if ($tag->{TRACKNUM}) {
    450               print ZEPHYR "Track #        : $tag->{TRACKNUM}\n";
    451           }
    452           if ($tag->{YEAR}) {
    453             print ZEPHYR "Year           : $tag->{YEAR}\n";
    454           }
    455           if ($tag->{GENRE}) {
    456               print ZEPHYR "Genre          : $tag->{GENRE}\n";
    457           }
    458           if (ref $tag->{COMMENT} eq 'ARRAY') {
    459             foreach $index (0 .. $#{$tag->{COMMENT}}) {
    460               if ($comment = filter_comment(@{$tag->{COMMENT}}[$index])) {
    461                 print ZEPHYR "Comment        : $comment\n";
    462               }
    463             }
    464           } elsif ($tag->{COMMENT}) {
    465             if ($comment = filter_comment($tag->{COMMENT})) {
    466               print ZEPHYR "Comment        : $comment\n";
    467             }
    468           }
    469 
    470           # others
    471           while (($key,$val) = each %lessinfo) {
    472             printf ZEPHYR "%-15s: %s\n", $MP3::Info::v2_tag_names{$key}, $val;
    473           }
    474         }
    475     }
    476     close(MP3STATUS);
    477     unlink(MP3STATUS);
    478 
    479     close(ZEPHYR);
    480 }
    481 
    482 # Play an OggVorbis audio stream (doesn't support auth!)
    483 # play_ogg_stream(URI)
    484 #  Mostly copied from play_ogg_audio
    485 sub play_ogg_stream {
    486   my $uri = shift(@_);
    487 
    488   system("chmod a+rw /dev/audio");
    489   system("ps -aef | grep ogg123 | awk '{print $2}' | xargs kill -9");
    490   system("ps -aef | grep mpg123 | awk '{print $2}' | xargs kill -9");
    491 
    492   # Prepare to write status:
    493   open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c sipb-auto -i sipbmp3@xcb -s "SIPB LPR music spooler"');
    494   system("/mit/sipb/bin/ogg123 -b 256 -dau -q -f - $uri 2> /tmp/ogg123.out | audioplay");
    495 
    496   # Check if there were any errors
    497   open(OGGSTATUS, "/tmp/ogg123.out");
    498   if ($_ = <OGGSTATUS>) {
    499     print ZEPHYR "Playback completed with the following errors:\n";
    500     print ZEPHYR $_;
    501     while (<OGGSTATUS>) {
    502       print ZEPHYR $_;
    503     }
    504   } else {
    505     print ZEPHYR "Playback completed successfully.\n";
    506     # Repeat tag data for those playing at home
    507     if (!$ogginfo{'title'}) {
    508       print ZEPHYR "No ogginfo data found\n";
    509       print ZEPHYR "Filename: $opts{'J'}\n\n";
    510     } else {
    511       print ZEPHYR "Title          : $ogginfo{'title'}\n";
    512       print ZEPHYR "Artist         : $ogginfo{'artist'}\n";
    513       print ZEPHYR "Album          : $ogginfo{'album'}\n";
    514       print ZEPHYR "Track #        : $ogginfo{'tracknumber'}\n";
    515 
    516       # others
    517       while (($key,$val) = each %lessinfo) {
    518         printf ZEPHYR "%-15s: %s\n", $key, $val;
    519       }
    520     }
    521   }
    522 
    523   close(OGGSTATUS);
    524   unlink(OGGSTATUS);
    525 
    526   close(ZEPHYR);
    527 }
    528 
    529 # Play an OggVorbis audio file
    530 sub play_ogg_audio {
    531   # Retrieve those command line opts.
    532   my %opts = %{shift(@_)};
    533 
    534   # Get ogginfo stuff
    535   open(OGGINFO, "/mit/sipb/bin/ogginfo $opts{'d'}/$opts{'e'}|");
    536   while (<OGGINFO>) {
    537     if (/(.*)=(.*)/) {
    538       $ogginfo{lc("$1")} = $2;
    539     }
    540   }
    541   close(OGGINFO);
    542 
    543   # If there's no title, print the filename
    544   if (!$ogginfo{'title'}) {
    545     print ZEPHYR "No ogginfo data found\n";
    546     print ZEPHYR "Filename: $opts{'J'}\n";
    547   } else {
    548     print ZEPHYR "Title          : $ogginfo{'title'}\n";
    549     print ZEPHYR "Artist         : $ogginfo{'artist'}\n";
    550     print ZEPHYR "Album          : $ogginfo{'album'}\n";
    551     print ZEPHYR "Track #        : $ogginfo{'tracknumber'}\n";
    552 
    553     # others
    554     %lessinfo = %ogginfo;
    555     delete $lessinfo{'filename'};
    556     delete $lessinfo{'title'};
    557     delete $lessinfo{'artist'};
    558     delete $lessinfo{'album'};
    559     delete $lessinfo{'tracknumber'};
    560     delete $lessinfo{'header_integrity'};
    561     delete $lessinfo{'stream_integrity'};
    562     delete $lessinfo{'file_truncated'};
    563     delete $lessinfo{'version'};
    564     delete $lessinfo{'channels'};
    565     delete $lessinfo{'bitrate_upper'};
    566     delete $lessinfo{'bitrate_nominal'};
    567     delete $lessinfo{'bitrate_lower'};
    568     delete $lessinfo{'bitrate_average'};
    569     delete $lessinfo{'length'};
    570     delete $lessinfo{'playtime'};
    571     delete $lessinfo{'kbps'};
    572     delete $lessinfo{'time'};
    573     delete $lessinfo{'rg_radio'};
    574     delete $lessinfo{'rg_audiophile'};
    575     delete $lessinfo{'rg_peak'};
    576     delete $lessinfo{'replaygain_album_peak'};
    577     delete $lessinfo{'replaygain_track_peak'};
    578     delete $lessinfo{'replaygain_album_gain'};
    579     delete $lessinfo{'replaygain_track_gain'};
    580 
    581     while (($key,$val) = each %lessinfo) {
    582       printf ZEPHYR "%-15s: %s\n", $key, $val;
    583     }
    584   }
    585 
    586   printf ZEPHYR "\nOgg Vorbis, average %.1f kbit/s, %d channels\n\n",
    587     $ogginfo{'bitrate_average'}/1024, $ogginfo{'channels'};
    588   print ZEPHYR "Track length: $ogginfo{'playtime'}s\n";
    589   close(ZEPHYR);
    590 
    591   # Play the file
    592 
    593   system("chmod a+rw /dev/audio");
    594   system("ps -aef | grep ogg123 | awk '{print $2}' | xargs kill -9");
    595   system("ps -aef | grep mpg123 | awk '{print $2}' | xargs kill -9");
    596   system("/mit/sipb/bin/ogg123 -b 40000 -dau -q -f - - 2> /tmp/ogg123.out | audioplay");
    597 
    598   # Done. Status:
    599   open(ZEPHYR, '|/usr/athena/bin/zwrite -d -n -c sipb-auto -i sipbmp3@xcb -s "SIPB LPR music spooler"');
    600 
    601   # Check if there were any errors
    602   open(OGGSTATUS, "/tmp/ogg123.out");
    603   if ($_ = <OGGSTATUS>) {
    604     print ZEPHYR "Playback completed with the following errors:\n";
    605     print ZEPHYR $_;
    606     while (<OGGSTATUS>) {
    607       print ZEPHYR $_;
    608     }
    609   } else {
    610     print ZEPHYR "Playback completed successfully.\n";
    611     # Repeat tag data for those playing at home
    612     if (!$ogginfo{'title'}) {
    613       print ZEPHYR "No ogginfo data found\n";
    614       print ZEPHYR "Filename: $opts{'J'}\n\n";
    615     } else {
    616       print ZEPHYR "Title          : $ogginfo{'title'}\n";
    617       print ZEPHYR "Artist         : $ogginfo{'artist'}\n";
    618       print ZEPHYR "Album          : $ogginfo{'album'}\n";
    619       print ZEPHYR "Track #        : $ogginfo{'tracknumber'}\n";
    620 
    621       # others
    622       while (($key,$val) = each %lessinfo) {
    623         printf ZEPHYR "%-15s: %s\n", $key, $val;
    624       }
    625     }
    626   }
    627 
    628   close(OGGSTATUS);
    629   unlink(OGGSTATUS);
    630 
    631   close(ZEPHYR);
    632 }
    633 
    634 # Play a WAV audio file
    635 sub play_wav_audio {
    636   # Retrieve those command line opts.
    637   my %opts = %{shift(@_)};
    638 
    639   print ZEPHYR "No info\n";
    640   print ZEPHYR "Filename: $opts{'J'}\n";
    641   close(ZEPHYR);
    642 
    643   # Play the file
    644 
    645   system("chmod a+rw /dev/audio");
    646   system("ps -aef | grep audioplay | awk '{print $2}' | xargs kill -9");
    647   system("/usr/bin/audioplay $opts{'J'}");
    648 }
Note: See TracChangeset for help on using the changeset viewer.