Xu Xiaodong avatar Xu Xiaodong committed 4a1a4bb

initial commit

Comments (0)

Files changed (2)

+Remember last play position of MPlayer.
+
+** Dependencies **
+
++ [Perl][p]
++ [MPlayer][m]
+
+[p]: http://www.perl.org/
+[m]: http://www.mplayerhq.hu/
+#!/usr/bin/env perl
+#
+# name:      lastplay, remember last play position of MPlayer
+# author:    Xu Xiaodong <xxdlhy@gmail.com>, 2009
+# license:   GPL
+# modified:  12/04/11 12:03:03
+#
+
+use strict;
+use warnings;
+
+use Date::Calc qw/Time_to_Date/;
+
+my $movie = shift;
+
+if ( defined $movie ) {
+    call( $movie, $$, 'mtime' );
+}
+else {
+    usage();
+}
+
+sub _read {
+    my ($file) = @_;
+
+    open my ($in_fh), '<', $file or die "Can't read $file: $!\n";
+
+    return readline $in_fh;
+
+    close $in_fh;
+}
+
+sub _write {
+    my ( $infile, $outfile ) = @_;
+    local $/ = q{
+    my @secs;
+
+    open my ($in_fh), '<', $infile or die "Can't read $infile: $!\n";
+
+    while (<$in_fh>) { push @secs, $1 if /A:\s*(\d+)/ }
+
+    close $in_fh;
+
+    unlink $infile;
+
+    my $sec = pop @secs;
+    my $time = join ":", ( Time_to_Date($sec) )[ 3 .. 5 ];
+
+    open my ($out_fh), '>', $outfile or die "Can't write $outfile: $!\n";
+
+    print $out_fh $time;
+
+    close $out_fh;
+}
+
+sub call {
+    my ( $movie, $mplayer_out, $time_out ) = @_;
+
+    if ( -e $time_out and -s $time_out ) {
+        my $time = _read($time_out);
+
+        system "mplayer -ss $time \Q$movie\E > $mplayer_out";
+    }
+    else {
+        system "mplayer \Q$movie\E > $mplayer_out";
+    }
+
+    if ( -e $mplayer_out and -s $mplayer_out ) {
+        _write( $mplayer_out, $time_out );
+    }
+}
+
+sub usage { print "Usage: $0 <movie file>\n" }
+
+# vim: ai:et:ts=4:sw=4:tw=78:ft=perl
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.