jump to current position in subtitle.srt.yaml
[HTML5TV.git] / bin / mplayer.pl
index e5d4289..7f476dd 100755 (executable)
@@ -30,7 +30,7 @@ if ( ! $movie && -e 'media/_editing' ) {
        warn "using media/_editing -> $movie\n";
 } elsif ( -d $movie && $movie =~ m{media/} ) {
        $movie .= '/video.ogv';
-} elsif ( -f $movie && $movie =~ m{\.og[vg]$}i ) {
+} elsif ( -f $movie && $movie =~ m{\.og[vg]\b}i ) {
        my $movie_master = $movie;
        $movie = base_dir($movie) . '/video.ogv';
        unlink $movie;
@@ -557,7 +557,14 @@ sub load_subtitles {
 sub edit_subtitles {
        print $to_mplayer qq|pause\n|;
        focus_term;
-       system( qq|vi "$subtitles.yaml"| ) == 0 and load_subtitles;
+       my $line = 1;
+       open( my $fh, '<', "$subtitles.yaml" ) || die $1;
+       while(<$fh>) {
+               last if /^-\s([\d\.]+)/ && $1 > $pos;
+               $line++;
+       }
+       close($fh);
+       system( qq|vi +$line "$subtitles.yaml"| ) == 0 and load_subtitles;
        focus_mplayer;
 }
 
@@ -757,7 +764,16 @@ sub from_mplayer {
 
 }
 
-push @to_mplayer, "get_property $_\n" foreach grep { ! $prop->{$_} } ( qw/metadata video_codec video_bitrate width height fps length/ );
+my @mplayer_prop = ( qw/metadata video_codec video_bitrate width height fps/ );
+warn "XXX $movie\n";
+if ( my $l = `oggLength $movie` ) {
+       $l = $l / 1000;
+       $prop->{length} = $l;
+       warn "$movie length ", fmt_mmss( $l );
+}
+push @mplayer_prop, 'length' unless $prop->{length};
+
+push @to_mplayer, "get_property $_\n" foreach grep { ! $prop->{$_} } @mplayer_prop;
 
 my $t = time;
 my $line;