Commits

Xu Xiaodong  committed 448c0d0

minor update

  • Participants
  • Parent commits df6b30b

Comments (0)

Files changed (1)

 #!/usr/bin/env perl
 #
-# name:      lastplay, remember last play position of mplayer
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2010 Mar 20
-# modified:  2011 Apr 13
+# name     : lastplay, remember last play position of mplayer
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2010 Mar 20
+# modified : 2012 May 11
 #
 
 use strict;
 use warnings;
+use Date::Calc qw(Time_to_Date);
 
-use Date::Calc qw/Time_to_Date/;
-
+# Main program
 my $movie = shift;
 
 if ( defined $movie ) {
-    call( $movie, $$, 'mtime' );
+  call( $movie, $$, "mtime" );
 }
 else {
-    usage();
+  usage();
 }
 
+# Read time
 sub _read {
-    my ($file) = @_;
+  my ($file) = @_;
 
-    open my ($in_fh), '<', $file or die "Can't read $file: $!\n";
-
-    return readline $in_fh;
-
-    close $in_fh;
+  open my ($in_fh), "<", $file
+    or die "Can't read $file: $!\n";
+  return readline $in_fh;
+  close $in_fh;
 }
 
+# Write time
 sub _write {
-    my ( $infile, $outfile ) = @_;
-    local $/ = q{
-    my @secs;
+  my ( $infile, $outfile ) = @_;
+  local $/ = q{
+  my @secs;
 
-    open my ($in_fh), '<', $infile or die "Can't read $infile: $!\n";
+  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;
 
-    while (<$in_fh>) { push @secs, $1 if /A:\s*(\d+)/ }
+  unlink $infile;
 
-    close $in_fh;
+  my $sec = pop @secs;
+  my $time = join ":", ( Time_to_Date($sec) )[ 3 .. 5 ];
 
-    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;
+  open my ($out_fh), ">", $outfile
+    or die "Can't write $outfile: $!\n";
+  print $out_fh $time;
+  close $out_fh;
 }
 
+# Call MPlayer
 sub call {
-    my ( $movie, $mplayer_out, $time_out ) = @_;
+  my ( $movie, $mplayer_out, $time_out ) = @_;
 
-    if ( -e $time_out and -s $time_out ) {
-        my $time = _read($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";
+  }
 
-        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 );
-    }
+  if ( -e $mplayer_out and -s $mplayer_out ) {
+    _write( $mplayer_out, $time_out );
+  }
 }
 
+# Usage
 sub usage { print "Usage: $0 <movie file>\n" }
 
-# vim: ai:et:ts=4:sw=4:tw=78:ft=perl
+# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=perl