move screenshots to s/shot/time path
[HTML5TV.git] / bin / mplayer.pl
index 837d23a..3fceaff 100755 (executable)
@@ -123,6 +123,10 @@ sub repl {
 
 our @subtitles;
 
+sub slide_jpg {
+       sprintf "%s/s/%d/%03d.jpg", $media_dir, @_;
+}
+
 sub html5tv {
 
        if ( ! $prop->{width} || ! $prop->{height} ) {
@@ -174,7 +178,7 @@ sub html5tv {
                                id => "chapter$1",
                                title => $s->[2],
                                description => $s->[2],
-                               src => sprintf('%s/s/%dx%d/p%03d.jpg', $media_dir, $prop->{width} / $slide_factor, $prop->{height} / $slide_factor, $1),
+                               src => slide_jpg( 4 => $1 ),
                                href => '',
                        },
                };
@@ -183,10 +187,11 @@ sub html5tv {
        }
 
        foreach ( 0 .. $#slide_t ) {
+               my $nr = $_ + 1;
                push @{ $sync->{htmlEvents}->{'#slide'} }, {
                        startTime => $slide_t[$_],
                        endTime   => $slide_t[$_ + 1] || $prop->{length},
-                       html      => sprintf( '<img src=%s/s/1/p%03d.jpg>', $media_dir, $_ + 1 ),
+                       html      => '<img src=' . slide_jpg( 1 => $_ + 1 ) . '>',
                };
        }
 
@@ -197,28 +202,38 @@ sub html5tv {
                my $w = $prop->{width}  / $factor;
                my $h = $prop->{height} / $factor;
 
-               my $path = "$media_dir/s/$factor";
+               my $path = "$media_dir/s";
+               if ( ! -d $path ) {
+                       warn "create slides imaes in $path";
+                       mkdir $path;
+               }
+
+               $path .= '/' . $factor;
 
                if ( ! -d $path ) {
                        mkdir $path;
                        warn "created $path\n";
 
-                       foreach my $hires ( @slides_hires ) {
+               }
 
-                               my $file = $hires;
-                               $file =~ s{^.+/(p\d+\.\w)}{$path/$1};
+               foreach my $hires ( @slides_hires ) {
 
-                               my $im = Imager->new( file => $hires );
-                               $im->scale( xpixels => $w, ypixels => $h, type => 'min' )->write( file => $file );
-                               warn "resized $file ", -s $file, " bytes\n";
-                       }
+                       my $nr = $1 if $hires =~ m{^.+(\d+)\.\w+$} || warn "can't find number in $hires";
+                       next unless $nr;
+                       my $file = slide_jpg( $factor => $nr );
+                       warn "slide $hires -> $file\n";
+                       next if -e $file;
+
+                       my $im = Imager->new( file => $hires );
+                       $im->scale( xpixels => $w, ypixels => $h, type => 'min' )->write( file => $file );
+                       warn "resized $file ", -s $file, " bytes\n";
                }
 
        }
 
        my ( $slide_width, $slide_height );
 
-       my $im = Imager->new( file => "$media_dir/s/1/p001.jpg" )
+       my $im = Imager->new( file => slide_jpg( 1 => 1 ) )
                        || Imager->new( file => "shot0001.png" ) # from mplayer [s]
                        ;
 
@@ -240,7 +255,7 @@ sub html5tv {
                },
        };
 
-       $html5tv->{video_tags} =
+       $html5tv->{html}->{video_tags} =
                join("\n",
                        map {
                                my $s = $_;
@@ -287,7 +302,7 @@ sub html5tv {
 
        warn "last customEvent $index\n";
 
-       $html5tv->{subtitles_table}
+       $html5tv->{html}->{subtitles_table}
                = qq|<table id="subtitles">|
                . join("\n",
                        map { qq|
@@ -302,10 +317,10 @@ sub html5tv {
                . qq|</table><a href="$media_dir/video.srt">download subtitles</a>|
                ;
 
-       my $hcalendar = '<div style="color: red">Create <tt>hcalendar.html</tt> to fill this space</div>';
-       my $hcal_path = '$media_dir/hcalendar.html';
+       my $hCalendar = '<div style="color: red">Create <tt>hCalendar.html</tt> to fill this space</div>';
+       my $hcal_path = '$media_dir/hCalendar.html';
        if ( -e $hcal_path ) {
-               $html5tv->{hcalendar} = read_file $hcal_path;
+               $html5tv->{hCalendar} = read_file $hcal_path;
                my $tree = HTML::TreeBuilder->new;
                $tree->parse_file($hcal_path);
                if ( my $vevent = $tree->look_down( class => 'vevent' ) ) {
@@ -593,6 +608,23 @@ while ( my $events = epoll_wait($epfd, 10, 1000) ) { # Max 10 events returned, 1
                                                        $subtitles[ $#subtitles ]->[1] = $pos;
                                                }
                                        }
+                               } elsif ( $line =~ m{(shot\d+.png)} ) {
+                                       my $shot = $1;
+                                       my $t = time_pos;
+                                       warn "shot $t $shot\n";
+                                       my $dir = "$media_dir/s/shot";
+                                       if ( ! -e $dir ) {
+                                               mkdir $dir;
+                                               warn "created $dir\n";
+                                       }
+                                       rename $1, "$dir/$t.png";
+
+                                       my $hires = "media_dir/s/hires";
+                                       mkdir $hires unless -e $hires;
+                                       my $max_slide = scalar( glob("$hires/*") ) || 0;
+                                       symlink "$dir/$t.png", "$hires/s$max_slide.png";
+                                       push @subtitles, [ $t, $t, "[$max_slide] video time $t slide $max_slide" ];
+                                       warn "created slide $max_slide at $t from $shot\n";
                                }
 
                                $line = '';