Skip to content

Instantly share code, notes, and snippets.

@ispedals
Created May 20, 2013 22:04
Show Gist options
  • Save ispedals/5615964 to your computer and use it in GitHub Desktop.
Save ispedals/5615964 to your computer and use it in GitHub Desktop.
Converts Timed Text subtitles to SRT format
#!perl
use v5.16;
use warnings;
use Subtitles::SRT::File;
use HTML::Entities;
use XML::Simple;
my $srt=Subtitles::SRT::File->new;
my $xml=XMLin shift;
for(@{$xml->{text}}) {
my $start = $_->{start};
my $end = $start + $_->{dur};
my $text = $_->{content};
$text =~ s/amp;//g; #patterns like <&#ddd> are encoded <&amp;ddd> so just remove amp;
$text = decode_entities $text;
$srt->add_subtitle({start => $start, end =>$end, text => $text});
}
print $srt->to_string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment