Skip to content

Instantly share code, notes, and snippets.

@ispedals
Created May 20, 2013 18:06
Show Gist options
  • Save ispedals/5614045 to your computer and use it in GitHub Desktop.
Save ispedals/5614045 to your computer and use it in GitHub Desktop.
Marks a subtitle file using pseduo-bookmarks generated from timestamped screenshots for further review
#!perl
use v5.12;
use warnings;
use Subtitles::ASS::File;
use Subtitles::SRT::File;
use Subtitles::Time;
use List::Util 'first';
use utf8::all;
use autodie;
my @times;
for(<*.png>) {
/(\d\d_\d\d_\d\d)/;
my $name=$1;
$name=~s/_/:/g;
push @times, $name;
}
die 'Did not find any times' unless @times>0
my $file=Subtitles::SRT::File->create_from_file($ARGV[0]);
my @lines = $file->get_subtitles;
for(@times){
my $time = Subtitles::Time->create_from_timestamp($_);
my $line = first {$time->seconds < $_->start->seconds} @lines;
warn "Got undefined line with time $_->to_timestamp" and next unless $line;
my $text=$line->get_text;
next if $text =~ /^###/;
$text="###$text";
$line->set_text($text);
}
print Subtitles::SRT::File->create_from_subtitle($file)->to_string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment