#!/usr/bin/env perl # mplayer.wrapper - Wrapper that runs main "mplayer" executable # License: BSD-style (for this file only) # Revision: 110816 #--------------------------------------------------------------------- # module setup #--------------------------------------------------------------------- require 5.8.1; use strict; use Carp; use warnings; # Trap warnings $SIG {__WARN__} = sub { die @_; }; #--------------------------------------------------------------------- # basic constants #--------------------------------------------------------------------- use constant ZERO => 0; # Zero use constant ONE => 1; # One use constant FALSE => 0; # Boolean FALSE use constant TRUE => 1; # Boolean TRUE #--------------------------------------------------------------------- # program parameters #--------------------------------------------------------------------- # Absolute path for "aoss" program my $PROG_AOSS = '__META_BINDIR__/aoss'; # Absolute path for "flac123" program my $PROG_FLAC123 = '__META_BINDIR__/flac123'; #--------------------------------------------------------------------- # main routine #--------------------------------------------------------------------- sub Main { my $NOTDEF; #--------------------------------------------------------------------- # Work-around for an "mplayer" ".flac" problem. if (scalar (@ARGV) == ONE) # Exactly one argument? { # Yes my $arg = $ARGV [ZERO]; # Argument # Up to late 2010, "mplayer" didn't work with short ".flac" files. # This wrapper was originally designed to divert short ".flac" files # to "flac123". # As of late 2010, "flac" support was broken almost completely. Ac- # cordingly, this code was modified so that *all* ".flac" files were # diverted to "flac123". # As of late 2011, "flac" support was working again, so ".flac" diver- # sion was dropped. $NOTDEF = << 'END'; # See the preceding comments # Is it a ".flac" file? if ($arg =~ m@\.flac\z@i) { # Yes # Get the file's size my $size = (stat $arg) [7]; # Is it a short ".flac" file? if (defined ($size) && ($size < 500000)) { # Yes - Use "flac123" instead exec $PROG_AOSS, $PROG_FLAC123, @ARGV; } # Yes - Use "flac123" instead exec $PROG_AOSS, $PROG_FLAC123, @ARGV; } END } #--------------------------------------------------------------------- # Work-around for an "mplayer" ".mp4" problem. $NOTDEF = << 'END'; # Not presently neededd for (@ARGV) { last if $_ eq '-demuxer'; next unless m@\.mp4\z@i; unshift (@ARGV, qw (-demuxer mov)); last; } END #--------------------------------------------------------------------- # Wrap it up. unshift (@ARGV, '__META_PREFIX__/bin/mplayer.bin'); exec $PROG_AOSS, @ARGV; } #--------------------------------------------------------------------- # main program #--------------------------------------------------------------------- &Main(); # Call the main routine exit ONE; # Should't be reached