aws*_*aws 4 scripting xml python perl text-processing
我有一个 xml 副标题,如下所示:
<?xml version="1.0" encoding="utf-8" ?><transcript>
<Item from="1.16" duration="4.68"><![CDATA[(Dong-hyuk is coming
to see you now.)
]]></Item>
<Item from="5.92" duration="1"><![CDATA[It's cold.
]]></Item>
<Item from="9.04" duration="2.88"><![CDATA[- Hello.
- Hello.
]]></Item>
<Item from="12.2" duration="1.76"><![CDATA[You're busy as always.
]]></Item>
<Item from="14.04" duration="3.48"><![CDATA[Look what I have here. Ta-da!
]]></Item>
<Item from="18.88" duration="1.5599999999999998"><![CDATA[Let me give it to you.
]]></Item>
<Item from="20.919999999999998" duration="2.8"><![CDATA[I'll give you
the most valuable present...
]]></Item>
</transcript>
Run Code Online (Sandbox Code Playgroud)
似乎"]]></Item>"总是蔓延到一个新的行。有没有办法将其转换为 srt 格式?
我会使用像xsh这样的 XML 处理工具:
open subtitles.xml ;
for /transcript/Item {
echo position() ;
echo @from '-->' (@from + @duration) ;
echo text() ;
}
Run Code Online (Sandbox Code Playgroud)
输出:
open subtitles.xml ;
for /transcript/Item {
echo position() ;
echo @from '-->' (@from + @duration) ;
echo text() ;
}
Run Code Online (Sandbox Code Playgroud)
转换时间数据留给读者作为练习。