Created
May 20, 2013 22:04
-
-
Save ispedals/5615964 to your computer and use it in GitHub Desktop.
Converts Timed Text subtitles to SRT format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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 <&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