6
Nov
by Chris
Here is a translet that will transform Timed Text (TT) Authoring Format 1.0 to SRT.
function T-TtafToSrt{ param ($inxml) BEGIN { . pslib:\xml\invoke-transform.ps1 $xslt = New-Object Xml.Xmldocument $xslt.PSBase.PreserveWhitespace = $true $xslt.LoadXml(@' <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:t="http://www.w3.org/2006/10/ttaf1"
xmlns="http://www.w3.org/2006/10/ttaf1"
xmlns:ttp="http://www.w3.org/2006/10/ttaf1#parameter"
xmlns:tts="http://www.w3.org/2006/10/ttaf1#style"
xmlns:ttm="http://www.w3.org/2006/10/ttaf1#metadata"
version="1.0">
<xsl:output indent="yes" method="text" />
<xsl:template match="/t:tt"><xsl:apply-templates select="/t:tt/t:body" /></xsl:template>
<xsl:template match="t:div"><xsl:apply-templates select="t:p" /></xsl:template>
<xsl:template match="t:p"><xsl:text>
</xsl:text>
<xsl:value-of select="count(preceding-sibling::t:p)" /><xsl:text>
</xsl:text>
<xsl:value-of select="concat(substring-before(@begin, '.'), ',', substring-after(@begin, '.'))" />0 --> <xsl:value-of select="concat(substring-before(@begin, '.'), ',', substring-after(@begin, '.'))" />0
<xsl:text>
</xsl:text><xsl:apply-templates /></xsl:template>
<xsl:template match="t:br"><xsl:text>
</xsl:text></xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
'@) } PROCESS{ if ($_ -is [xml]){ invoke-transform -inxml $_ -inxsl $xslt } } END{ if ($xml -is [xml]){ invoke-transform -inxml $xml -inxsl $xslt } }} It can be used like this
PS> . .\T-TtafToSrt.ps1 # dot source this file
PS> T-TtafToSrt [xml(gc .\ttaf.xml) | sc -encoding ascii
or
PS> . .\T-TtafToSrt.ps1 # dot source this file
PS> [xml](gc .\ttaf.xml) | T-TtafToSrt | sc -encoding ascii
Note that if you aren't passing it on down the pipeline and are sending it to a file you have to set the encoding to ascii or applications will ignore it.
Here is the code.
T-TtafToSrt.zip (1.10 kb)
