rename to _editing
[HTML5TV.git] / bin / mplayer.pl
index cf6ddc0..de4e1fa 100755 (executable)
@@ -17,27 +17,30 @@ my $movie = shift @ARGV;
 
 sub base_dir { $1 if $_[0] =~ m{^(.+)/[^/]+$} }
 
-if ( ! $movie && -e 'media/editing' ) {
-       $movie = readlink 'media/editing';
+if ( ! $movie && -e 'media/_editing' ) {
+       $movie = 'media/' . readlink('media/_editing') . '/video.ogv';
+       warn "using media/_editing -> $movie\n";
 } elsif ( -d $movie && $movie =~ m{media/} ) {
        $movie .= '/video.ogv';
 } elsif ( -f $movie && $movie !~ m{video\.ogv} ) {
        my $movie_master = $movie;
-       my $movie = base_dir($movie) . '/video.ogv';
-       symlink $movie_master, $movie;
-       warn "symlink $movie_master <- $movie\n";
+       my $to = $movie = base_dir($movie) . '/video.ogv';
+       $to =~ s{media/}{};
+       symlink $movie_master, $to;
+       warn "symlink $to -> $movie\n";
 } elsif ( -f $movie ) {
        warn "using video $movie";
 } else {
        die "Usage: $0 media/conference-Title_of_talk[/video.ogv'\n";
 }
 
-my $media_dir = base_dir($movie);
+my $media_part = my $media_dir = base_dir($movie);
+$media_part =~ s{media/}{};
 
-unlink 'media/editing';
-symlink $movie, 'media/editing';
+unlink 'media/_editing';
+symlink $media_part, 'media/_editing';
 
-warn "# media_dir $media_dir\n";
+warn "# media_part $media_part\n";
 
 my $edl = "/dev/shm/edl";
 my $subtitles = $movie;
@@ -67,10 +70,13 @@ epoll_ctl($epfd, EPOLL_CTL_ADD, fileno STDIN         , EPOLLIN  ) >= 0 || die $!
 epoll_ctl($epfd, EPOLL_CTL_ADD, fileno $from_mplayer , EPOLLIN  ) >= 0 || die $!;
 #epoll_ctl($epfd, EPOLL_CTL_ADD, fileno $to_mplayer   , EPOLLOUT ) >= 0 || die $!;
 
+sub load_subtitles;
+
 sub load_movie {
        warn "$movie ", -s $movie, " bytes $edl\n";
        print $to_mplayer qq|loadfile "$movie"\n|;
        print $to_mplayer "get_property $_\n" foreach ( qw/metadata video_codec video_bitrate width height fps length/ );
+       load_subtitles;
 }
 
 
@@ -313,7 +319,7 @@ sub html5tv {
 
        warn "# html5tv ", dump $html5tv;
 
-       my $sync_path = '$media_dir/video.js';
+       my $sync_path = "$media_dir/video.js";
        write_file $sync_path, "var html5tv = " . to_json($html5tv) . " ;\n";
        warn "sync $sync_path ", -s $sync_path, " bytes\n";
 
@@ -321,13 +327,15 @@ sub html5tv {
        $html =~ s|{([^}]+)}|my $n = $1; $n =~ s(\.)(}->{)g; eval "\$html5tv->{$n}"|egs ||
                warn "no interpolation in template!";
 
-       write_file '$media_dir.html', $html;
+       write_file "www/editing.html", $html;
+       $html =~ s{media/editing}{media/$media_part}gs;
+       write_file "www/$media_part.html", $html;
 
        my $carousel_width = $prop->{width} + $slide_width - 80;
        $carousel_width -= $carousel_width % ( $slide_width + 6 ); # round to full slide
        my $carousel_height =   $slide_height + 2;
 
-       write_file '$media_dir/video.css', qq|
+       write_file "$media_dir/video.css", qq|
 
 .jcarousel-skin-ie7 .jcarousel-container-horizontal,
 .jcarousel-skin-ie7 .jcarousel-clip-horizontal {
@@ -441,13 +449,15 @@ sub save_subtitles {
 }
 
 sub load_subtitles {
+       if ( ! -e "$subtitles.yaml" ) {
+               warn "no subtitles $subtitles to load\n";
+               return;
+       }
        @subtitles = YAML::LoadFile "$subtitles.yaml";
        warn "subtitles ", dump @subtitles;
        save_subtitles;
 }
 
-load_subtitles if -e "$subtitles.yaml";
-
 sub edit_subtitles {
        print $to_mplayer qq|pause\n|;
        focus_term;