summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2009-06-17 16:52:54 (GMT)
committerJames Meyer <james.meyer@operamail.com>2009-06-17 16:52:54 (GMT)
commitbc2a5f737e0f0402b31ab0a5a59ee11a204f48c6 (patch)
tree23d6feed4a2e00603e72a1060c05976ba7722c57 /abs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl
parent57e9c8d25f393eefa467cdd61de9d0f58aafabd5 (diff)
parentdd91ca69386ad656407707148bb9242cf861b0a1 (diff)
downloadlinhes_pkgbuild-bc2a5f737e0f0402b31ab0a5a59ee11a204f48c6.zip
linhes_pkgbuild-bc2a5f737e0f0402b31ab0a5a59ee11a204f48c6.tar.gz
linhes_pkgbuild-bc2a5f737e0f0402b31ab0a5a59ee11a204f48c6.tar.bz2
Merge branch 'HEAD' of ssh://jams@knoppmyth.net/mount/repository/LinHES-PKGBUILD
Diffstat (limited to 'abs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl')
-rwxr-xr-xabs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl110
1 files changed, 110 insertions, 0 deletions
diff --git a/abs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl b/abs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl
new file mode 100755
index 0000000..583786d
--- /dev/null
+++ b/abs/core-testing/mplayer-wrapper/bin/mplayer-wrapper.pl
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+use Shell;
+use strict;
+use POSIX qw(floor);
+
+# Written by Bob Igo from the MythTV Store at http://MythiC.TV
+# including some original code and contributions from Nick C.
+# and graysky.
+# Email: bob@stormlogic.com
+#
+# If you run into problems with this script, please send me email
+
+# PURPOSE:
+# --------------------------
+# This is a wrapper script that tries to find the best parameters
+# for calling an underlying video player. The outer layer determines
+# the best playback parameters, while the inner layer picks the best
+# player to call.
+
+# RATIONALE:
+# --------------------------
+# Default video playback options are not optimal on all hardware or
+# for all video types. In addition, common video players do not
+# offer to bookmark video so that you can resume where you left off.
+# Both of these problems can be addressed by this wrapper.
+
+# PARAMETERS:
+# --------------------------
+# The same parameters you'd use for mplayer, some of which may be
+# translated automatically for use with smplayer.
+
+# FILES:
+# --------------------------
+# $mediafile, the file to play
+
+sub run () {
+ my $mediafile = @ARGV[$#ARGV];
+ my $player = &pick_player();
+
+ my $player_parameters = join(' ',
+ &translate_parameters($player,@ARGV[0..$#ARGV-1]),
+ &dynamic_parameters($mediafile));
+ &player($player,$player_parameters,$mediafile);
+}
+
+&run();
+
+# Translates any parameters into ones that will be compatible with the given player.
+sub translate_parameters() {
+ my($player,@parameters)=@_;
+
+ if ($player eq "smplayer") {
+ # Stupidly, smplayer uses a different set of command-line parameters than generic
+ # mplayer, so we need to translate mplayer-centric ones into the few that are
+ # available in smplayer-ese.
+ my %smplayer_parameter_translation_array = (
+ "-fs" => "-fullscreen",
+ "-zoom" => " "
+ );
+
+ sub translate() {
+ my($flag)=@_;
+ return $smplayer_parameter_translation_array{$flag};
+ }
+
+ return map(&translate($_), @parameters);
+ } else {
+ return @parameters;
+ }
+}
+
+# Returns an array of dynamic parameters based in part on the media.
+sub dynamic_parameters () {
+ my($mediafile)=@_;
+ return(); # ??? empty for now; further development required
+}
+
+# Find the best player for use on this system. The script prefers smplayer,
+# which has built-in bookmarking, falling back to mplayer-resumer.pl, which
+# implements bookmarking as an mplayer wrapper, if smplayer cannot be found.
+# Finally, if no bookmarking players can be found, a barebones mplayer is used.
+sub pick_player () {
+ my @possible_players = ("smplayer", "mplayer-resumer.pl", "mplayer");
+ my $command;
+ my $candidate_player;
+ foreach (@possible_players) {
+ $candidate_player = $_;
+ $command = "which $candidate_player |";
+ open(SHELL, $command);
+ if (<SHELL>) {
+ #print "player $candidate_player : $_\n";
+ return $candidate_player;
+ }
+ close(SHELL);
+ }
+}
+
+# Calls player
+sub player () {
+ my($player,$parameters,$mediafile)=@_;
+ my $command = "$player $parameters \"$mediafile\" 2>&1 2>/dev/null |";
+
+ #print "DEBUG: command is:\n$command\n";
+ open(SHELL, $command);
+ while (<SHELL>) {
+ print $_;
+ }
+ close(SHELL);
+}