Chinaunix首页 | 论坛 | 博客
  • 博客访问: 710629
  • 博文数量: 235
  • 博客积分: 4309
  • 博客等级: 中校
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-17 11:25
个人简介

If you don\\\\\\\\\\\\\\\'t wanna do it, you find an EXCUSE; if you do, you\\\\\\\\\\\\\\\'ll find a WAY :-)

文章分类

全部博文(235)

文章存档

2014年(3)

2013年(2)

2012年(31)

2011年(199)

分类: LINUX

2011-10-05 07:58:38

  1. #!/usr/bin/env perl
    # # name: lastplay, remember last play position of mplayer # author: Xu Xiaodong # license: GPL # created: 2010 Mar 20 # modified: 2011 Apr 13 # 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 \n" } # vim: ai:et:ts=4:sw=4:tw=78:ft=perl
阅读(1063) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~