collect video:file.ogv files from subtitles
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 11 Oct 2009 19:46:30 +0000 (21:46 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 11 Oct 2009 19:46:30 +0000 (21:46 +0200)
bin/mplayer.pl
www/tv.html

index 1cde29a..c282bec 100755 (executable)
@@ -95,20 +95,33 @@ sub html5tv {
 
        my @slide_t;
 
+       my @videos;
+
        foreach my $s ( @subtitles ) {
                push @{ $sync->{htmlEvents}->{'#subtitle'} }, {
                        startTime => $s->[0],
-                       endTime => $s->[1],
-                       html => $s->[2],
+                       endTime   => $s->[1],
+                       html      => $s->[2],
                };
+
+               if ( $s->[2] =~ m{video:(.+)} ) {
+                       my $video = $1;
+                       my $path = "www/media/$video";
+                       if ( ! -e $path ) {
+                               warn "MISSING $path: $!\n";
+                       } else {
+                               push @videos, $video;
+                       }
+               }
+
                next unless $s->[2] =~ m{\[(\d+)\]};
 
                my $res = ( $prop->{width} / 4 ) . 'x' . ( $prop->{height} / 4 );
 
                push @{ $sync->{customEvents} }, {
                        startTime => $s->[0],
-                       endTime => $s->[1],
-                       action => 'chapterChange',
+                       endTime   => $s->[1],
+                       action    => 'chapterChange',
                        args => {
                                carousel => 'theCarousel',
                                id => "chapter$1",
@@ -156,12 +169,31 @@ sub html5tv {
                }
        }
 
+       $html5tv->{video_tags} =
+               join("\n",
+                       map {
+                               qq|
+                                       <div id="$_">
+                                               <video controls="controls" width="$html5tv->{slide}->{width}px" height="$html5tv->{slide}->{height}px">
+                                               <source src="media/$_" />
+                                               </video>
+                                       </div>
+                               |
+                       } @videos
+               )
+       ;
+
        warn "html5tv ", dump $html5tv;
 
        my $sync_path = 'www/media/video.js';
        write_file $sync_path, "var html5tv = " . to_json($html5tv) . " ;\n";
        warn "sync $sync_path ", -s $sync_path, " bytes\n";
 
+       my $html = read_file 'www/tv.html';
+       $html =~ s|{([^}]+)}|my $n = $1; $n =~ s(\.)(}->{)g; eval "\$html5tv->{$n}"|egs ||
+               warn "no interpolation in template!";
+
+       write_file 'www/media.html', $html;
 
 }
 
index 763c84c..1596917 100644 (file)
@@ -54,6 +54,8 @@
        </ul>\r
 </div> <!-- carouselContainer -->\r
 \r
+{video_tags}\r
+\r
 <p>This web interface is based on BBC R&amp;D TV\r
 <a href="http://www.bbc.co.uk/blogs/rad/2009/08/html5.html">HTML 5 and timed media</a> from the RAD blog</p>\r
 \r